The S&P 500 (^GSPC -0.41%) closed higher on Friday, May 24, notching its fifth straight weekly gain. The index, a barometer for the U.S. stock market, has advanced 11% year to date, hitting more than two dozen record highs in the process. But history says that momentum will persist through the summer months of June, July, and August.

Here's what investors should know.

The S&P 500 has historically moved higher through June, July, and August

The S&P 500 advanced 234% over the past 10 years, compounding at 12.8% annually. During that time, the index generally produced a positive return during 11 months of the year, with September being the only exception, as shown in the chart.

A chart showing the S&P 500's average return in each month over the last decade.

The average price return (excluding dividends) of the S&P 500 in each month over the last decade.

As the chart shows, the S&P 500 produced an average return of 1% in June during the last decade, followed by an average return of 3.1% in July and 0.3% in August. In short, history says the U.S. stock market could build up stream through the summer months.

Of course, past performance isn't a guarantee of future results, so investors should never make assumptions about the S&P 500 in any given month. Instead, investors should focus on long-term returns because the stock market is more predictable when measured in decades.

Warren Buffett made a comment to that effect in his 1993 shareholder letter: "In the short run, the market is a voting machine -- reflecting a voter-registration test that requires only money, not intelligence or emotional stability -- but in the long run, the market is a weighing machine." In other words, stocks may be irrational over short periods, but fundamentally sound businesses are bound to do well over long periods.

Some Wall Street analysts warn the stock market is headed for a correction

Ultimately, whether the S&P 500 goes up or down depends on macroeconomic fundamentals that influence corporate financial results. The stock market is currently challenged by stubborn inflation and high interest rates, which could drag on economic growth and lead to worse-than-expected corporate earnings.

That possibility is particularly troublesome because the S&P 500 already commands a relatively high valuation. It currently trades at 20.5 times forward earnings, a premium to the 10-year average of 17.8 times earnings, according to FactSet Research. The index could fall sharply if earnings grow more slowly than anticipated in the coming quarters, and Wall Street has lofty expectations.

Analysts think S&P 500 companies will grow earnings 11.4% in 2024, an acceleration from 0.5% in 2023. They also anticipate an acceleration to 14.2% earnings growth in 2025. If actual results fall short, stocks could decline sharply, given that valuations are already elevated. Not surprisingly, certain Wall Street analysts see a stock market correction on the horizon.

The S&P 500 currently trades at 5,304, but Evercore and Morgan Stanley have set the index with year-end targets of 4,750 and 4,500, respectively. Those estimates imply downside of 10% and 15%, respectively. Most bearish of all is JPMorgan Chase, where analysts have set the S&P 500 with a year-end price target of 4,200. That implies downside of 21%, which would put the index in a bear market.

My advice to investors is twofold. First, hope for positive results through the summer months (and the rest of the year), but be prepared for a drawdown. It always makes sense to limit stock purchases to exceptional companies trading at reasonable valuations, but following that rule is especially important in the current market environment.

Second, look past any drawdowns and target long-term returns. No matter what happens in the coming months, remember that the S&P 500 returned 12.8% annually over the last decade, and similar results (perhaps a few percentage points lower) are likely over the next decade.