One of my all-time favorite quotes by Warren Buffett is the following line of contrarian advice: "Be greedy when others are fearful, but be very fearful when others are greedy." As I read the headlines these days, that quote increasingly -- and ominously -- comes to mind.

I believe the current stock market rally is now well into the stage of greed. You can smell it in the record levels of investor optimism. You can see it in the rocketing prices of the most speculative stocks. You can feel it in the celebration of "stimulative" monetary and fiscal policy, which above all else has stimulated a massive increase in consumer and federal debt. (These reasons are but a morsel of Whitney Tilson's impressive case for why it's a scary time for stocks.)

So, the writing is on the wall -- but what exactly is the most intelligent way to heed Buffett's admonition to "be very fearful"? That's the question I want to address today, because I emphatically do not believe the answer is abandoning the stock market altogether, much less going to cash or haphazardly shorting the Nasdaq 100 (AMEX:QQQ).

Bargains can still be found
Even though the signs of avarice and over-optimism are widespread, not all stocks are equally "infected." People talk about the stock market as if it were one unified mega-corporation, when in reality it's a vast array of disparate businesses. Some are undervalued relative to their future cash flows and therefore a low-risk investment -- while a great many more are priced dearly and therefore vulnerable to even the slightest bump in the road.

Typically, in my research, I'm uncovering about one new undervalued stock per week, so there are still bargains to be found. (For me, "undervalued" means a conservative projection of 15% or better annual returns over the next five years.)

The "flight to crap"
At the same time, however, I marvel at the rampant speculation -- what's aptly been called a "flight to crap." Which sectors belong in this category? I'll defer to Fred Hickey, who in his latest High-Tech Strategist newsletter referred to all of the following as "mini-bubbles": Chinese stocks, satellite radio stocks XM (NASDAQ:XMSR) and Sirius (NASDAQ:SIRI), Linux stocks, Voice-over-IP (VOIP) stocks, Internet stocks, and nanotech stocks. Each of those categories inevitably has one or two exceptions that represent good value, but beware the majority of these.

Looking beyond the areas of obvious froth, I'd also urge the highest caution regarding the following sectors: momentum-driven technology shares that dominate the Nasdaq 100 (e.g., semiconductors); interest rate sensitive companies (e.g., financials and homebuilders); and high-P/E retailers. Additionally, I'd also be wary of any company whose business or valuation could suffer much harm if interest rates were to rise 2%-3%.

Demand value of every investment
In sum, the best way to mitigate risk is to demand value of every investment. If you're a casual investor and not prepared to ascertain that each and every stock you own is undervalued, then you may be better off considering a value-oriented mutual fund, such as Aegis Value or Royce Total Return, both of which emphasize overlooked and beaten-down small caps. Aegis favors stocks with a low price-to-book ratio, while the Royce fund prefers shares offering a good dividend yield. You also might consider Motley Fool investment newsletters -- where the Fool's analysts do the work for you. Tom Gardner uncovers undervalued small-caps in Hidden Gems and Mathew Emmert digs up high-dividend payers in Income Investor.

For those of you who are more advanced investors, I continue to believe a concentrated portfolio of six to eight undervalued stocks is likely to perform well in all weather. I suggest targeting companies with the following features:

  • Small market capitalization -- Companies below $200 million tend to be most overlooked and consequently most undervalued.

  • Unheralded sectors -- Just because a business is boring doesn't mean it can't make you good money!

  • Low price multiples -- High percentage bets include any of the following: those trading for less than 10 times free cash flow or earnings; a market cap less than tangible book value; or, a 3%-plus dividend yield.

  • Share buybacks -- Companies committed to buying back substantial amounts of stock tend to be great investments, especially when the shares are being bought back at a low price multiple (here's an example).

  • Improving financials -- The market is quick to reward companies with rising profit margins, rising returns on invested capital, and improving balance sheets.

  • Sturdy balance sheet -- Companies with little or no debt will survive the inevitable rainy day, while those with high debt can fall victim to even a minor profit hiccup.

In addition to the above list, I recommend paying no more than about 75% of your conservative fair value estimate (as estimated by discounted cash flow analysis or by projecting conservative multiples). The 75% level isn't magic, but in doing this you'll limit your portfolio to only those companies that offer excellent risk/reward probabilities.

In conclusion, consider the benefits of a value-centric approach: With a portfolio of undervalued stocks, you're playing a conservative form of offense that's inherently defensive in bad times. And if there ever comes a point when you can't find enough undervalued stocks to fill up your portfolio, then you'll naturally take on an even more defensive posture as cash piles up.

So be "very fearful," yes, of the overvalued, speculative crap -- but don't hesitate to be "greedy" for any undervalued stocks you're able to dig up.

Guest columnist Matt Richey has been a longtime contributor to The Motley Fool and is a portfolio manager at Centaur Capital Partners LP, a money management firm based in Dallas, Texas. He welcomes your feedback at The Fool is investors writing for investors .