Stocks closed modestly higher Wednesday, recovering some of the market’s hefty losses from the day before.

Energy companies led the gainers, climbing as the price of crude oil rose. Gains by several big retailers and health care companies also helped lift the market.

On Wednesday:

The Standard & Poor’s 500 index rose 7.69 points, or 0.3 percent, to 2,465.54.

The Dow Jones industrial average added 54.33 points, or 0.3 percent, to 21,807.64.

The Nasdaq composite gained 17.74 points, or 0.3 percent, to 6,393.31.

The Russell 2000 index of smaller-company stocks picked up 2.54 points, or 0.2 percent, to 1,402.20.

For the week:

The S&P 500 fell 11.01 points, or 0.4 percent.

The Dow slid 179.92 points, or 0.8 percent.

The Nasdaq declined 42.02 points, or 0.7 percent.

The Russell 2000 lost 11.37 points, or 0.8 percent.

For the year:

The S&P 500 is up 226.71 points, or 10.1 percent.

The Dow is up 2,045.04 points, or 10.4 percent.

The Nasdaq is up 1,010.20 points, or 18.8 percent.

The Russell 2000 is up 45.07 points, or 3.3 percent.