Stocks eked out modest gains Wednesday, keeping the major stock indexes on Wall Street at or near record highs.

The S&P 500 inched up 0.1%, recovering some of its losses from a day earlier. It’s hovering within 0.1% of the record high it set Monday. The Dow Jones Industrial Average closed just above its own all-time high from Monday.

Energy and materials companies led the gains. Industrial and financial stocks also had a strong showing. Communication services stocks fell the most. Roughly 73% of stocks in the S&P 500 rose. Treasury yields mostly fell.

Small-company stocks again outpaced their larger rivals, a sign that investors are feeling more optimistic about the economy.

Stocks have been mostly grinding higher in recent weeks, with indexes setting new highs, amid optimism that coronavirus vaccinations will pave the way in coming months for the economy to escape from the pandemic’s grip.

“This is overall a market that’s setting the stage for 2021 and looking at an economy that is going to normalize, albeit at a probably slower pace than initially projected,” said Quincy Krosby, chief market strategist at Prudential Financial.

The S&P 500 index rose 5 points to 3,732.04. The Dow gained 73.89 points, or 0.2%, to 30,409.56. The Nasdaq composite picked up 19.78 points, or 0.2%, to 12,870. The Russell 2000 index of smaller companies climbed 20.63 points, or 1.1%, to 1,979.99.

Ahead of the final day of trading in 2020, the S&P 500 is up 15.5% this year, while the Nasdaq is up 43.4%.

The modest gains came as the effort to develop and distribute vaccines to fight the virus pandemic intensifies. Britain has authorized the use of a COVID-19 vaccine developed by AstraZeneca and Oxford University. The vaccine is considered easier to store and handle than others hitting the market. Earlier in December, the U.K. and the U.S. approved a vaccine made by Pfizer.

Meanwhile, vaccine development continues around the globe, with China’s Sinopharm becoming the latest to release encouraging study results.

Investors are optimistic about more vaccines gaining approval and reaching the market in coming weeks, though the potential for problems with their distribution remains a concern, said Ryan Detrick, chief market strategist for LPL Financial.

“The hiccups are the actual rollout,” he said. “Approving them is one thing, but getting them out and into people’s arms is another thing.”

Treasury yields were mostly lower. The yield on the 10-year Treasury slipped to 0.92% from 0.93% late Tuesday.