Right now, a lot of investors are understandably frustrated with the stock market. Many high-quality stocks have lagged behind the market's overall gains over the past six months. Meanwhile, "junky" companies have seen their share prices skyrocket over the same period.

At first glance, that may seem colossally unfair. Yet if you step back and take a look at it from a broader perspective, you'll realize that everything is working out the way it should.

An unfair rally
To get a sense of just how pervasive this phenomenon was, I took advantage of our Motley Fool CAPS screener to help do some simple analysis. Going back six months to March 9, the low point of the bear market, I examined some of the lowest-rated stocks to see how they performed. To make sure that the stocks I tracked had enough of a following on CAPS for the rating to make sense, I only selected stocks with 250 or more active picks.

When I did this search yesterday, I came up with 136 stocks, many of which have gained 50% or more since March. Here's a small sample:

Stock

# of Active Picks

6-Month Return

Vonage Holdings

1,513

284%

Capital One Financial (NYSE:COF)

1,224

307%

Hovnanian Enterprises

1,034

571%

Fifth Third Bancorp (NASDAQ:FITB)

932

663%

Krispy Kreme Doughnuts

728

208%

Source: Motley Fool CAPS.

As a comparison, I also looked at top-rated stocks on CAPS since March 9. Out of the 152 stocks I found that had at least 1,000 active picks, you can find quite a few that have lagged well behind the market's 50% return. Here are some of the laggards:

Stock

# of Active Picks

6-Month Return

Johnson & Johnson (NYSE:JNJ)

12,289

32%

Altria (NYSE:MO)

8,176

21%

Procter & Gamble (NYSE:PG)

6,415

25%

Activision Blizzard (NASDAQ:ATVI)

4,540

17%

Abbott Labs (NYSE:ABT)

1,499

0%

Most people would agree that the second set of stocks includes stronger companies than the first group. Yet the first group saw its shares jump much further.

What gives?
The key to understanding the paradox is to set aside your focus on the recent rally. Sure, it's interesting that so many weaker stocks have seen such huge gains. But when you add in some additional context, it quickly becomes clear that these "junk stocks" haven't really seen much of a recovery at all from their longer-term losses.

For instance, rather than just looking at the most recent move up, let's expand the time horizon to include more of the overall market cycle. Going back three years, you would capture the last year of the bull market, the entirety of the financial crisis, and the recovery from the March lows.

Looking at how these stocks have done over that period of time gives you a brand new view of what really happened. From the first set of stocks, Capital One turns out to be the  best of the worst, with a loss of "only" 48% over the past three years. Hovnanian clocks in with the worst performance at a loss of nearly 84%.

Meanwhile, among the higher-quality stocks, the returns are more in line with what you'd expect. Four of the five stocks actually gained ground since 2006. P&G was the sole loser, with a drop of just less than 5%.

Give it time
These figures show just how irrational the market can be over the short run. Wild swings can push stocks up and down in volatile moves that aren't necessarily justified by fundamental business conditions.

As you expand your time horizon, though, those fundamentals reassert themselves. Strong businesses see their stocks do well, while weaker ones typically suffer.

Whenever you think the market is unfairly punishing otherwise promising stocks, it's best to step back and see whether you're focusing on too short a timeframe. If you're confident in your stock selections, patience often pays the best rewards.

Think high-flying stocks are due to crash? Shannon Zimmerman tells you which stock doubles you should sell right now.

Fool contributor Dan Caplinger isn't letting the rally get him down. He owns shares of Altria. Activision Blizzard is a Motley Fool Stock Advisor selection. Johnson & Johnson and Procter & Gamble are Income Investor selections. The Fool owns shares of Procter & Gamble. The Fool's disclosure policy keeps its chin up no matter what happens.