Stocks closed with solid gains on Wall Street Wednesday after a choppy day of trading that pulled indexes temporarily into the red.

The bumpy day came as investors sized up a mix of company earnings and another flare-up in tensions between Washington and Beijing.

Gains in technology and health care stocks outweighed losses in energy companies, banks and elsewhere in the market. Treasury yields fell slightly, a sign of caution in the market.

On Wednesday:

The S&P 500 gained 18.72 points, or 0.6%, to 3,276.02.

The Dow Jones Industrial Average rose 165.44 points, or 0.6%, to 27,005.84.

The Nasdaq composite added 25.76 points, or 0.2%, to 10,706.13.

The Russell 2000 index of small company stocks picked up 2.63 points, or 0.2%, to 1,490.14.

For the week:

The S&P 500 is up 51.29 points, or 1.6%.

The Dow is up 333.89 points, or 1.3%.

The Nasdaq is up 202.94 points, or 1.9%

The Russell 2000 is up 16.82 points, or 1.1%.

For the year:

The S&P 500 is up 45.24 points, 1.4%.

The Dow is down 1,532.60 points, or 5.4%.

The Nasdaq is up 1,733.52 points, or 19.3%.

The Russell 2000 is down 178.33 points, or 10.7%.