Mankiw thinks that the good returns in the stock market during democrat presidencies are simply a sequence of random event.
A theory of regulation cycles in this paper by can provide some explanation to this phenomenon. Basically, when the economy booms, people trust the market more and would accept deregulation, which encourage financial fraud and followed by a burst of the bubbles drags the economy into a recession. During the earlier part of this cycle, market is working then republican/conservative arguments win. After that, problems in the market accumulate and eventually, market returns fall as the bubble bursts. People then wake up in the aftermath of the bubble and demand more regulation of the financial market, which lead democrats to the White house and congress, who may overburden the economy with regulation however, the economy recovers and grows with new boom and the next round of deregulation and bubble are brewing.