History said that the market would be volatile leading into the presidential election. History was right. The Dow Jones Industrial Average closed out its second-best Election Day ever on Tuesday, with a gain of over 500 points, but that came after some big losses posted the previous week.What does the history of stocks and elections suggest about the S&P 500 for the rest of 2020, once Election Day is in the rearview mirror? With so much still unknown about how this election will end, here are potential outcomes for the stock market based on the history of elections.A contested election can be a factor in creating even more volatility, but there’s only the 2000 Bush-Gore battle in recent history, so not too much data to draw on. While that resulted in trouble for the S&P 500, the longer history of the markets in election years, covering eight decades back to 1944, suggests that stocks could hold up well in the final two months of 2020, regardless of the winner.It is the day after Election Day, and the outcome in the race between President Donald Trump and Democratic nominee Joe Biden is far from decided. Trump won big states such as Florida, Texas and Ohio, according to NBC News projections, but Arizona, Wisconsin, Nevada, Michigan, Pennsylvania, Georgia and North Carolina are all either too early or too close to call. Earlier Wednesday morning Trump threatened legal action to stop vote counting days after the election.Stock futures were higher in trading, though futures had bounced around between gains and losses overnight. Looking ahead, if you had to pick a month to take more risk in equities, history says it is better to bet on December in an election year. In election year Novembers since 1944, the S&P 500 has risen, on average, of 0.8%, according to CFRA and S&P Dow Jones Indices data. That’s not great — it is actually considerably lower (by 600 basis points) than the average for all Novembers since 1944. And the stock market rose less than half the time (42%) in election-year Novembers — or in other words, the frequency of gains was lower — compared to gaining 66% of the time for all Novembers over the past eight decades.A trader on the morning after the 2016 presidential election. U.S. stocks started Nov. 4, 2016 in the red, but finished that day’s trading higher. The history of election years suggests that more gains could be coming before 2020 is over.Xinhua | Wang Ying via Getty Images | Xinhua News AgencyDecember is when the election year numbers for stocks look better. It’s historically been a good month for stocks, regardless of the election cycle, with the S&P 500 posting an average increase of 1.5% back to 1944. In election years specifically, that monthly gain remains strong, if slightly lower, at 1.4%. But the S&P 500 has been more likely to gain in the final month of election years, even if the size of the gain is a little lower. The U.S. stock market has posted a gain 84% of the time in election-year Decembers since 1944, versus 74% for all Decembers. CFRA suggests that an end to election uncertainty has been a factor, as well as seasonal optimism from investors. The winning party is another factor in the short-term market moves after elections. Wins by the Democratic Party in a presidential election have been followed by weaker Novembers. But the S&P 500 went on to post above-average price gains, and more frequent gains, in Decembers after a Democratic presidential candidate wins.It’s tended to be the opposite when the Republican Party prevails. The S&P 500 posted better gains in Novembers of those election years, as well as more frequent gains. But in December, the gains were more likely to trail the historical average after a Republican prevailed in the election.The realignment of the political power structure in Washington, D.C., has influenced stocks, too, in the ways one might expect, and beyond just the final two months of an election year. With more pandemic stimulus from the federal government important to the economy and the market, the way Washington, D.C., looks once the election is decided also will be a factor.History suggests that the level of control by the two major political parties over the branches of the federal government has influenced the size of gains in the year after a presidential election.CFRA/S&P Dow Jones IndicesThe best gains in the year after an election occurred when the president and Congress were under control of the same party, with the S&P 500 rising an average 10.6% across those 30 years, versus the average of 8.8% for all 76 years, according to CFRA. Its conclusion: when a president has a Congress which “rubber stamps” their agenda, stocks stand to benefit.It also follows that a split in power between Congress and the executive branch has been second-best for stocks (8.6%), and a Congress unified in control against the president’s party has posted the worst results (7.4%), on average.The years after an election when the same party won control of both the executive and legislative branches of government were the only when the average return posted by the S&P 500 (10.6%) was higher than the average stock gains across all 76 years (8.8%).