Wall Street capped a day of choppy trading with modest gains for stocks Thursday, as the market’s tug of war continues between worries about the worsening pandemic in the present and optimism that a vaccine will rescue the economy in the future.

The S&P 500 rose 0.4% after spending much of the day flipping between small losses and gains. The benchmark index was coming off a 1.2% slide from the day before that pulled it away from its record of 3,626.91 set on Monday. The late-afternoon burst of buying erased nearly all of the S&P 500′s losses for the week.

Technology companies accounted for much of the rebound. Companies that rely on consumer spending and communications stocks also helped lift the market, outweighing losses in the utilities and health care sectors. Treasury yields fell, a sign of caution in the market.

The S&P 500 gained 14.08 points to 3,581.87. The Dow Jones Industrial Average added 44.81 points, or 0.2%, to 29,483.23. The index had been down 210 points. The tech-heavy Nasdaq composite climbed 103.11 points, or 0.9%, to 11,904.71.

Small-company stocks had a good showing. The Russell 2000 index picked up 14.82 points, or 0.8%, 1,784.13.

Wall Street’s huge November rally has slowed this week as fears about the economy buckling in the near term collide with hopes that stronger growth will arrive next year once effective coronavirus vaccines become available. A discouraging report on Thursday underscored the fears, showing that more U.S. workers filed for unemployment benefits last week than the week before. It was a worse number than economists expected and the first increase in five weeks.

With infections and hospitalizations on the rise across much of the country, governors and mayors are grudgingly issuing mask mandates, limiting the size of gatherings, banning indoor restaurant dining, closing gyms and restricting the hours and capacity of other businesses.

“Good vaccine news is battling worsening coronavirus trends,” said Ross Mayfield, investment strategist at Baird. “We’re at this point where you have the endgame in sight, but the path to get there looks really murky.”

Investors worry the moves and the worsening pandemic that caused them will hurt corporate profits and shake confidence among consumers, keeping them hunkered at home. New York City’s announcement that it’s halting in-person learning at public schools helped send stocks on their late-day slide Wednesday.

Democrats and Republicans in Washington, meanwhile, are still stymied in their attempts to deliver another dose of financial support to workers and businesses. That has the specter of a bleak winter looming for both the health care system and economy.

Counterbalancing all those fears is hope that coming vaccines can control the pandemic and get the global economy back toward normal next year.

“The market is grappling with the push and pull of the progress with the vaccine track, which allows a window to when our economy can reopen, with the current reality of rising cases,” said Bill Northey, senior investment director at U.S. Bank Wealth Management.

University of Oxford scientists expect to report results from the late-stage trials of the COVID-19 vaccine they’re developing with AstraZeneca by Christmas, a key researcher said Thursday.

Already this month, pharmaceutical companies have offered data suggesting other vaccines under development could be highly effective. Pfizer and BioNTech said Wednesday they plan to ask U.S. regulators within days to allow emergency use of their vaccine.

That had led to a resurgence of interest for stocks that stand to gain the most from a healthy, reopening economy. These were also among the stocks most beaten down by the stay-at-home economy created by the pandemic, such as travel-related businesses, banks and smaller companies.

Investors will likely need more clarity on the timing and impact of a vaccine in order to gain more confidence in the economic recovery, Northey said.

“We saw a sharp recovery to date, but now its beginning to plateau,” he said. “We’re doing that as we head into a very important holiday shopping season.”

L Brands, the company behind Bath & Body Works and Victoria’s Secret, notched the biggest gain in the S&P 500 Thursday. It vaulted 17.7% after it reported a profit for the latest quarter that blew past Wall Street’s expectations.

The yield on the 10-year Treasury dipped to 0.84% from 0.86% late Wednesday.

European stock markets fell, and Asian markets ended mixed.