With a few months to go in the presidential campaign, pundits are poring over every scrap of new economic data-notably, unemployment-for a clue as to whether President Barack Obama will be reelected.

But the best predictor, many say, is the stock market. If the S&P 500 rises in the three months before the election, most likely the President will win a second term, according to market historians. So far this year, it's up 10.6%.

It's not an issue of Obama's polices, or even Democrats versus Republicans. It's simply that a good market bodes well for the guy in office, and a bad market does not. "Investors will not have suddenly decided to embrace the current administration and their seemingly anti-Wall Street policies," wrote Sam Stovall, the Chief Equity Strategist at S&P Capital IQ, in a research note, "but will have become sufficiently encouraged by the improving economic conditions to stay the course."

In the 28 presidential elections since 1900, the incumbent was reelected 80% of the time when the S&P 500 increased the three full months before the election, according to Stovall.

If the market fell? The incumbent lost 88% of the time. On average, the S&P harbinger works 82% of the time, which doesn't mean it's foolproof, but "in many ways it has earned its stripes," Stovall says. "As goes the outlook for the economy, so goes the reelection chances of the incumbent." There are many indicators from the Superbowl Effect to the Hemline Theory. But what sets the S&P performance apart, is its record for accuracy and intuitiveness. "That's why investors look to stock price movements; to see whether they point to a strengthening or a weakening in the economic data," Stovall says.

Of course, many investors assume there is a more complex connection based on ideology; namely, Republicans are good for their portfolios. "It troubles me that everyone still believes that just because Republicans are said to be good for the market that they are," Jeff Hirsch, editor of the Stock Trader's Almanac and Chief Market Strategist at Magnet Æ Fund, says. "It's not about the party; it's about the incumbency issue."

Stovall's data, which compares stock prices and poll numbers, shows that whenever the market has gone up, so have President Obama's poll numbers. When the markets went down, it coincided with positive poll numbers for Republican challenger Mitt Romney, who named Rep. Paul Ryan of Wisconsin as his running mate.

Stovall admits it's hard to tell if good poll numbers for the president are driving rallies in the stock market, or if rallies in the market are resulting in a better feeling among voters toward the president. "This is a chicken or egg thing," he says, adding: "All I know is Obama's number went up, as did the market's numbers. I'm not willing to say which drove which, but I am willing to say they move pretty much in lockstep."

What about the four times since 1900 the S&P rallied in the run-up to the election and the incumbent lost anyway? Stovall has a theory for three out of the four times. In those years-1912, 1968 and 1980-there was a third party candidate to steal votes from the incumbent. (In 1912, it was Theodore Roosevelt, in 1968 George Wallace, and in 1980 it was John Anderson.) In 1932, when Franklin Delano Roosevelt beat President Herbert Hoover, the predictor was "just plain wrong," Stovall says.

And exactly how did the markets do in each of the election years since 1900? On average, the years when the S&P 500 rallied in the three months before the election, it gained 6.1% in that time. In the down years, the index sank 5.1%.

The good news is that under either scenario, investors historically have been so relieved to be past Election Day that they have sent the S&P 500 up an average of 0.6% in November, and 1.7% in December. After an August-October gain, the S&P typically rose an average of 1.4% in November and 1.8% in December. Conversely, in the years when markets were down ahead of the election, the index gave back an average of 1.3% in November, only to break even in December. That bounce following November losses after an incumbent is ousted represents an act of investor optimism, analysts suggest. Says Hirsch: "You get a celebration of change that somebody new is coming to fix things."