Stocks shook off a weak start to end higher Thursday, nearly erasing the S&P 500′s losses for the week.

Major indexes had wavered for much of the day as Wall Street’s tug of war continues between worries about the worsening pandemic and optimism that a vaccine will come soon.

On Thursday:

The S&P 500 gained 14.08 points, or 0.4%, to 3,581.87.

The Dow Jones Industrial Average added 44.81 points, or 0.2%, to 29,483.23.

The Nasdaq composite climbed 103.11 points, or 0.9%, to 11,904.71.

The Russell 2000 small-caps index picked up 14.82 points, or 0.8%, 1,784.13.

For the week:

The S&P 500 is down 3.28 points, or 0.1%.

The Dow is up 3.42 points, or less than 0.1%.

The Nasdaq is up 75.43 points, or 0.6%.

The Russell 2000 is up 40.09 points, or 2.3%.

For the year:

The S&P 500 is up 351.09 points, or 10.9%.

The Dow is up 944.79 points, or 3.3%.

The Nasdaq is up 2,932.11 points, or 32.7%.

The Russell 2000 is up 115.66 points, or 6.9%.