A lot has been written recently about how U.S. stocks usually perform well after the midterm elections. But a deeper dive into the data shows the post-midterms rally hinges on the majority party maintaining control of the House.

Data compiled by Fundstrat Global Advisors showed the median stock market return since 1896 was only 1.9 percent a year after the House majority flipped from one party to the other. Meanwhile, the median return totaled 16.8 percent when the House majority stayed the same after the midterms.

Fundstrat used Dow Jones Industrial Average data to calculate returns before 1945 and data for returns post 1945.

Democrats are expected to take control of the House away from Republicans after Tuesday's elections. In the Senate, the GOP is expected to maintain a slight majority over the Democrats.

Many investors are looking at the average gains following all midterm elections and not parsing the data like Fundstrat did. For example, data from Kensho shows the S&P 500 has averaged a gain of 0.95 percent one week after the midterms since 1980. They also show the broad index climbs on average more than 2 percent a month after the election and 5.4 percent in three months.

They say this is because investors gain clarity on which policy initiatives Congress will pass through and which will be blocked. And that certainty is worth something to the market, even if some of the policies will work against business.

But Nobel Prize-winning economist Robert Shiller says this election will be different as it is more of a referendum on President Donald Trump, adding he would not use this election to predict which way the market will go.

"This is a very different midterm election," he said Monday on CNBC's "Trading Nation." "There's a lot of anxiety at this point; a lot of anger. I don't think this is easily grouped into past midterm elections. So, I think that the history of the market responses to that doesn't tell us very much."

Also, while stocks have historically thrived under a divided government, this time it could be different as the risk of impeachment for Trump increases in this scenario. The GOP's economic policies, which have boosted stocks since Trump took office, could also be limited or reversed in a divided Congress.

WATCH: Jeremy Siegel says House-Senate split isn't the worst thing