Bet against the masses. Don't be the lemming. Be fearful when others are greedy.

Follow these simple rules, and you'll probably be a successful investor.

With those rules of thumb in mind, you'd be forgiven for thinking now is a terrible time to buy stocks. The S&P 500 is up more than 50% since March, which is typically consistent with a market flooded with uncontrollable euphoria. Sure enough, many are preaching of an overvalued market that's gotten way ahead of itself.

Oh really? 
And maybe they're right. Sooner or later, they probably will be. But perspective is in order: When stocks bottomed out earlier this year, a better part of the investment community thought the world was about to explode. Companies like Citigroup (NYSE:C) and Bank of America (NYSE:BAC) traded for trivial valuations because they really, truly, were on the verge of death.

Today, it looks like we've skirted most of those calamitous end-of-the-world threats. It's still terrible, mind you, just not as terrible as many thought. Naturally, stocks have sprung back to levels that reflect a deep recession, rather than a total Mad Max scenario.

This is an incredibly important distinction to make: Markets haven't risen to levels that reflect exuberance, but to levels consistent with a world that isn't about to fall into mass insolvency.

This is evident by looking at the biggest winners over the past few months. By and large, the stocks that have risen the most are ones you wouldn't recommend to your worst enemy. Have a look:

Company

Return Since March

Dollar Thrifty Automotive

2,353%

Avis Budget Group

2,092%

Pier 1 Imports

2,227%

Are these companies destined for greatness? Did they announce a new blockbuster product? Are they the next Google (NASDAQ:GOOG) or Apple (NASDAQ:AAPL), waiting to change the way we live? Goodness, no. Not even close. Their huge gains are simply a reflection that they'll live to see another day.

In general, this is a rally built on canceling out past pessimism. The biggest gains have been concentrated in very low-quality companies that are simply being given a second shot at life. 

Not all gains are created equal 
The idea that a stock is overvalued after a massive run-up is contingent on the idea that it was properly priced to being with. But this was hardly the case when the market bottomed in March. More importantly, some of the highest-quality companies in the world have largely been left out of the rally and still trade at attractive prices.

Here are three in particular:

Company

Return Since March

Forward P/E Ratio

H&R Block (NYSE:HRB)

(1.3)%

12.0

Lockheed Martin (NYSE:LMT)

17.3%

9.85

AT&T (NYSE:T)

14.4%

11.8

What's to like about these three? Glad you asked:  

Life's two guarantees, death and taxes, are good news for three organizations: Congress, funeral homes, and H&R Block. Go all the way back to 1992, and H&R Block has, on average, traded at more than 27 times earnings. Its reputation, niche, and returns on equity have typically justified such a premium. Today, you can pick up shares for no more than 12 times forward earnings. Enough said.

Congressman Barney Frank once made a brilliant quip about Washington's obsession with what he called "weaponized Keynesianism," or the undeniable urge for politicians to spend ungodly amounts of taxpayer money to protect the homeland. Think about that, then look at a company like Lockheed Martin -- where 84% of revenue comes from the federal government -- trading at under 10 times earnings, and smile.

AT&T will impress precisely no one when it comes to innovation or stellar growth potential. But it's huge, giving it one of the largest scaling moats out there, and comes with a 6.3% dividend yield. When most fixed-income products yield a pinch above nothing, and high-quality, tried-and-tested companies yield more than 6%, you probably won't be disappointed by sticking with the latter. 

Onward 
Perspective can be a powerful thing: Last year, Dow 10,000 would have been associated with the end of the world. Today, some want to treat it like it symbolizes irrational exuberance simply because we've bounced so far off the March lows. This is inherently flawed thinking. Focusing on a stock's percentage change over a short period of time is utterly meaningless. Drilling down on a company's intrinsic value and buying bargains like we haven't seen in decades is what's important.

And that's why our Motley Fool Inside Value team of analysts is having a field day digging through the rubble and finding cheap stocks like never before. For more information, click here to see all of our picks, free for 30 days. There's no obligation to subscribe.

Already a member of Inside Value? Log in at the top of this page.

This article was published on June 25. It has been updated.

Fool contributor Morgan Housel doesn't own shares in any of the companies mentioned in this article. Google is a Motley Fool Rule Breakers recommendation. Apple is a Stock Advisor selection. The Fool has a disclosure policy.