Things are looking up for investors as the year winds down. Although the S&P 500 retreated quite a bit in September and October, the index is bouncing back nicely. Barring a major tumble over the next few weeks, we should see a solid double-digit gain for 2023.

I suspect that many, if not most, investors are already looking ahead into next year. How will the stock market perform in 2024? History may provide a big clue -- and it's one investors will like.

The most important thing to keep in mind about next year

2024 will be a leap year. It will be the "year of the wood dragon" on the Chinese calendar (although, technically, the Chinese year will begin on Feb. 10, 2024, and end on Jan. 28, 2025). But those are relatively trivial things to know about next year.

The most important thing to keep in mind about 2024 is that it's a U.S. presidential election year. President Joe Biden is seeking his party's nomination for another term. Former President Donald Trump holds a lead over several rivals vying for the GOP presidential nomination.

People at voting booths.

Image source: Getty Images.

Presidential election years are enormously important for investors. The person who wins the White House will have an opportunity to establish policies that impact the economy, regulations, and international relations. All of these, in turn, can cause some stocks to rise and others to fall.

How the S&P 500 has performed in previous presidential election years

Between 1928 and 2016, the average return during U.S. presidential election years was nearly 11.3% based on data from Morningstar and Ibbotson Associates. The S&P 500 delivered positive gains in 19 of the 23 presidential election years during that period. The story would perhaps be even better were it not for the stock market plunging in 2008 due to the financial crisis and sinking in 1940 with the uncertainty during the early part of World War II.

Historically, stocks performed better during the years when a Republican was elected president with an average S&P 500 total return of 15.3%. The average total return when a Democrat was elected president, though, was still pretty good at 7.6%.

These numbers don't include 2020. However, despite the market meltdown early in the year due to the COVID-19 pandemic, the S&P 500 still managed to recover and end the year up 16% and a total return of over 18%.

^SPX Chart

^SPX data by YCharts

How has the market performed historically when a Democrat was in the White House and the party kept control of the presidency? The S&P 500 delivered an average total return of 15%. And when a Democratic president was replaced by a Republican, the index's average total return was 12.9%.

The key caveat

No matter how you look at it, history shows that the stock market tends to perform well during U.S. presidential election years. This could be because the incumbent party typically tries to do everything it can to boost the economy in an effort to hold onto power. Sometimes, investors can be optimistic about the possibility of a change in policies with a new administration.

However, there's a key caveat that mutual funds always mention: Past performance is no guarantee of future results. This caveat holds true with the S&P 500 and presidential election years, too.

If history is a guide, 2024 will be a good year for the stock market. Unfortunately, though, history isn't always such a great guide.