The S&P 500 has historically risen after midterm elections regardless of which party wins, according to a CNBC analysis of returns from 1980 through 2024.

After midterms, the index gained an average of 13.7% within one year. Returns were positive in 91% of cases. The S&P 500 rose after all 11 midterms from 1982 through 2022.

Short-term moves are less predictable. The index averaged 0.2% gains after one day and one week following both presidential and midterm elections, though it showed slightly negative returns after one day and one week following presidential elections specifically.

The market has historically performed better under divided government, where one party controls the White House and another holds at least one house of Congress. After 10 midterms and five presidential elections with no single party in control, the S&P 500 rose an average of 15% over one year. One-year returns were positive in 14 of 15 cases. By contrast, elections producing single-party control saw average one-year gains of 11.5%.

"If you have a huge red wave or a big blue wave, markets actually kind of don't like that as much because you have too much spending one way and too much power," Ryan Detrick, chief market strategist at Carson Group, told CNBC.

When Democrats controlled both houses and a Republican held the presidency in 1986, 1990, and 2006, the S&P 500 declined 0.5% on the reaction day but rose 3.4% after one month and 10.9% after one year.

Election results matter less than other factors. The S&P 500 fell 22.1% in the year after the 2000 elections due to the dotcom bust. It gained 38.3% after the 2020 elections as markets recovered from the COVID-induced selloff.

Federal Reserve policy and corporate earnings ultimately matter more than elections, according to Société Générale. After the 2018 midterms, the Fed raised rates four times that year and the S&P 500 ended down 6.2%, though it was up 11.7% one year after the election.