The S&P 500 (^GSPC 1.02%) is having a spectacular year. It's up 22.8% including dividends so far, marking a sharp reversal from 2022 when it plunged into bear market territory.

In fact, the S&P 500 has only posted an annual loss 15 times since its establishment in 1957. On nine of those occasions, the index immediately bounced back the following year with a gain, much like it has in 2023.

I dug through the data to figure out what normally happens next in situations like this, and you'll likely be very pleased with what I found.

History isn't the only reason 2024 could be a great year for the S&P 500

The height of the pandemic feels like a lifetime ago, but the flood of stimulus dollars from the U.S. government, combined with record-low interest rates, drove the surge in inflation that crashed the stock market in 2022.

By June of last year, the Consumer Price Index (CPI) hit a 40-year high of 9.1% annualized, which triggered the U.S. Federal Reserve to raise interest rates at the fastest pace in its history. In just 18 months, the federal funds rate soared from 0.25% to 5.50%, which pulled investors out of stocks and into risk-free assets like cash and government Treasury bonds.

Investors rightly expected the pace of interest rate hikes to slow in 2023, hence the rebound in the S&P 500. Attention has even turned to interest rate cuts recently, and experts predict the Fed could lower the benchmark rate five times in 2024. That alone could fuel a strong rally in the stock market next year.

But let's circle back to the historical data I mentioned at the top. Rebound years like 2023 have always been followed by another positive year, which bodes extremely well for 2024.

Plus, the average gain based on nine instances dating back to 1957 is 15.1%. That suggests 2024 won't be quite as strong as 2023, but historical data doesn't account for the potential rate cuts, which could drive a larger return.

Two investors looking at four computer monitors with price charts on them.

Image source: Getty Images.

Which stocks should investors buy to prepare for 2024?

First, it's important to keep in mind that past performance doesn't guarantee future results. Historical data alone isn't enough to cement the stock market's next move, otherwise we'd all be very rich.

That said, specific stocks will clearly benefit from a decline in interest rates next year. Real estate brokerage giant Redfin is one of them, especially if the housing market gathers steam.

Plus, artificial intelligence (AI) stocks are coming off a spectacular year and will likely carry a ton of momentum into 2024. AI can significantly boost productivity for businesses, and it has the potential to transform the economy over the long term.

Nvidia will probably continue to do well as it can barely keep up with demand for its AI data center chips. Similarly, Microsoft bet $10 billion on ChatGPT developer OpenAI earlier this year, one of the AI industry's leading start-ups.

Palo Alto Networks is also experiencing a surge in demand for its cybersecurity software, which is increasingly powered by AI.

For risk-averse investors, buying shares in Warren Buffett's holding company, Berkshire Hathaway, is typically a safe bet given it has doubled the return of the S&P 500 every year (on average) since 1965.