By Kate Gibson

Recent strength in commodity prices and weakness in the U.S. dollar were among the factors that had stock-market investors fleeing on Monday to the materials sector, which also benefited from brighter forecasts for global economic growth.

Improving expectations for global growth is "a strong positive for a sector that relies heavily on export growth," Oppenheimer equity analysts Brian Belski and Nicholas Roccanova wrote in a note.

Material shares fronted Monday's gains, with chemical giant Dow Chemical Co. (DOW) rising 6.9%, while packaging maker Sealed Air Corp. (SEE) and lumber giant Weyerhaeuser Co. (WY) were among the session's top performers, both up roughly 6%.

Reversing course in afternoon trades, the major indexes erased earlier declines and crossed into positive territory. The Dow Jones Industrial Average (DJI) gained 21.39 points, or 0.2%, to end at 9,626.8. The S&P 500 Index (SPX) climbed 6.61 points, or 0.6%, to 1,049.34, while the Nasdaq Composite Index (RIXF) gained 10.88 points, or 0.5%, to 2,091.78.

For the year to date, materials are up 34.1%, outperforming the broader market, which had the S&P 500 ahead 15.4% as of Friday's close.

"Once again, the market is beginning to rotate investment groups, from the financials to the materials. Materials and the technology sectors have been among the top groups since late [in the] second quarter and continue to do so today, again as investors expect real and lasting economic recovery," said Paul Nolte, director of investments, Hinsdale Associates.

Crude futures in recent months have traded between $65 and $75 a barrel as the market looked to increased demand on expectations of a global recovery. On Monday, oil futures lapsed below $69 a barrel, while shares of natural gas jumped more than 11%. .

"We believe the correction in the local Chinese equity market is an early sign of pending correction in commodities along with materials," wrote Bank of America Merrill Lynch research analysts Mary Ann Bartels and Stephen Suttmeier.

Gold miner Goldcorp. (GG) made Bank of America's latest "most attractive buy" list, which identifies common stocks viewed as attractive on technical analysis. .