The US stock market just had its best year — so far — since 1997

The stock market just had its best performance through July in 26 years.

The benchmark S&P 500 index closed last month with a boost of about 21% for the year. That’s its largest gain through July in 26 years, according to data from S&P Dow Jones Indices.

Along with the Nasdaq Composite, the S&P 500 notched its fifth winning month in a row in July, marking the broad-based index’s longest monthly winning streak since 2021.

The rally stalled out in the first trading day of August, with stocks wavering as investors parsed the week’s mixed bag of second-quarter earnings. The month also tends to be volatile for Wall Street, since the summer travel season leads to lower trading volumes.

Gains in the US market this year have largely been driven by the so-called Magnificent Seven, a group of stocks favored for their simultaneously defensive and growth qualities as well as their roles in developing artificial intelligence products. Tech behemoths Nvidia, Apple, Amazon, Alphabet, Meta Platforms, Microsoft and Tesla comprise the group.

The better-than-feared earnings season has also helped lift stocks. About 81% of the 292 companies in the S&P 500 that have reported their second-quarter results so far have reported earnings above analyst expectations, according to data from Refinitiv Lipper.

Nvidia soared by 220% for the year through July, Meta Platforms jumped 165%, Carnival gained 134%, Royal Caribbean added 121% and Tesla increased 117%.

The market’s rally has also broadened in recent months, as Wall Street has become more optimistic that inflation is cooling, the economy could avoid a recession and the Federal Reserve is nearing the end of its rate-hiking cycle. The S&P 600 index, which tracks the performance of stocks of small companies, outperformed the broader index last month.

Still, the market’s gains are far from being equal across the board. An equal-weighted version of the S&P 500 underperformed year to date through July.