U.S. stocks have had a such a miserable quarter that investors might just have to buy a whole load of them this week.

Investors who keep portfolios on target by rebalancing every quarter are looking at a dramatic outperformance by bonds since July. Bonds soared, and stocks slumped -- and those who desire a specific make-up in their portfolio are going to be selling lots of bonds and buying stocks to get back to their desired allocations.

The rebalancing means stocks could outdo bonds this week by about seven percent if historical trends hold, analysts at JPMorgan said. That forecast got off to a good start Monday as the stock market rallied and bond prices fell.

If you're doing passive rebalancing for quarter-end, that would require investors to sell bonds and buy stocks especially given the dramatic difference in performance this quarter in particular, said Jack Ablin, chief investment officer at Harris Private Bank in Chicago, which oversees $50 billion in assets.

Stocks have been a disaster this quarter, with the S&P 500 <.SPX> down 12 percent through Monday. Bonds, meanwhile, have been stars. Benchmark yields rallied to lows not seen in decades, boosting the iShares Barclays 20+ Year Treasury Bond Fund , which follows an index of long-dated bonds. The ETF is up more than 26 percent since the beginning of July.

When this happens, it tends to reverse in the waning days of a quarter or a month, and that could drive flows for a good part of the week, according to the analysis from Marko Kolanovic, global head of equity derivatives strategy at JPMorgan.

JPMorgan analysts on Monday said that when the S&P 500 underperforms 20-year Treasury prices going into the last week of the month, stocks tend to reverse the trend and recoup roughly a quarter of the relative underperformance.

The underperformance in this quarter has been dramatic, with equities trailing bonds by about 42 percentage points --on par with what was seen during the financial crisis in 2008.

Government bonds outperformed stocks in the past three months as investors fretted first over the softening economic data and later over a return to recession.

The downgrade of the U.S. credit rating in early August cast further doubts over growth, with the reverse effect of enhancing the safe haven appeal of Treasuries.

Hopes for a resolution in Europe were viewed as a catalyst for the market rally, but it may not be the only reason as portfolio shifts are part of it.

To be sure, the main reasons for the massive decline on the S&P 500 in the past quarter -- the European credit crisis and the weakening economic data in many world regions -- are still unresolved.

The market is bouncing around with the vagaries of the headlines, said Ablin. We need either some kind of resolution to the uncertainty in Europe or some momentum signals, or some combination of both that would prompt us to go into this market, he said.

(Reporting by Rodrigo Campos; Editing by Andrew Hay)