Pop quiz, hotshot: The S&P is up 78% from its closing low last March. If the market continues to go up, you want to ride along with it. But if it reverses course, you want to protect your nest egg. So what do you do?

The answer seems obvious, right? U.S. unemployment is still close to double digits, we've yet to touch the financial industry with any reforms, and Fannie Mae (NYSE: FNM) and Freddie Mac still have debt loads and losses that almost defy comprehension; they're just downright scary. It's time to sell!

But wait just a second there. Earnings reports have been pretty promising so far in the first quarter, particularly from key economic barometers like UPS (NYSE: UPS) and IBM (NYSE: IBM). Both companies easily beat Wall Street's expectations, but, more importantly, both also said that 2010 is going to be better than they previously thought. For IBM, its expansion beyond tech hardware played a big part in the quarter as its software revenue showed extremely strong growth. UPS benefitted from its operating leverage -- which is pretty typical of capital-intensive businesses as the economy exits a recession.

Meanwhile, the housing market has been showing signs of stabilization; and many economists seem confident that the recession is over and the U.S. is returning to growth. For Pete's sake, buy!

Don't mind the 78%
Stock market commentators tend to be a rather fearful bunch. When times get bad and the market is sinking, many of them seem to suffer from taphephobia -- a fear of getting buried alive -- and they want to run for the hills as quickly as possible. On the flip side, when the market is shooting up, acrophobia -- the fear of heights -- seems to come into play and, well, they're off running for the hills again.

But if you ask me – or, really, any fundamentals-oriented investor -- our concern shouldn't rest with how much the market has gone up or down, but rather whether its valuation is attractive or unattractive. If a hot market with sky-high valuations rises 78%, that acrophobia is probably warranted. On the other hand, if a sorely undervalued market tacks on that same 78%, there could still be good reason to buy. 

Do mind the valuation
There are many ways to track the market's valuation, but I'm a big fan of the work that Robert Shiller of Yale has done. He maintains a spreadsheet that tracks the S&P's price and earnings going all the way back to 1871 and tracks the market's valuation by comparing price with the average earnings over the past 10 years.

The long-term average P/E ratio is around 16.4. The current readout is a hair above 22, which is up from 13.3 in last March and down from 27 prior to the market's crash. While we could say that we're still below pre-recession valuation levels, it's hard to say that today's valuation is attractive when compared to the long-term average.

Fortunately, earnings are starting to recover. If first quarter earnings hit S&P's estimates, then total S&P 500 earnings over the past year will be $59.34. This is still below the trailing earnings from the same period in 2005, but it's a heck of a lot better than the single digit earnings that were posted in 2009. And S&P seems to think we're going to continue to move in the right direction and be up to $71.81 by 2011.

If we switch our view to a single-year P/E, S&P's improving earnings show that valuations are currently below their average of 22.7 over the past 21 years. Which, of course, sounds more bullish than the data we pulled from Shiller.

So what do you do?
Back in March of last year, when the market's valuation was undeniably low, it was difficult to go wrong with buying an index fund and calling it a day.

Sure, you could have trounced the market by buying certain individual stocks such as Fifth Third Bancorp (Nasdaq: FITB) (up 990%) or MGM Mirage (NYSE: MGM) (up 548%). But you'd have had to shrug off the downward spiral of the banking industry as a whole to take a chance on Fifth Third, while you had to trust that a massive debt load in a gripping recession wouldn't send MGM into bankruptcy.

And if you skipped out on those gut-churning wagers you still would have done quite well with a simple index.

If you're a long-term retirement investor and you want to keep it simple, you still may be OK grabbing those index funds today. For investors who like to put on a hard hat and go prospecting for the best stock opportunities, though, now is a good time to start eschewing the index funds in favor of individual stocks that are still undervalued. 

Now there's probably an argument to be made that both MGM and Fifth Third could be good picks today since they're still trading below their respective historical valuation levels. However, both reported losses in their December-ended quarters, and neither has really proven yet that they've truly turned the corner. Meanwhile, there are blue chips floating around at compelling valuations.

ExxonMobil (NYSE: XOM), for example, is still trading at 12 times its expected 2010 earnings, which is much more attractive than the broad S&P index. With Exxon, you get the 800-pound gorilla in the energy industry and take home a 2.4% dividend to boot.

Chip champ Intel (Nasdaq: INTC), meanwhile, is sitting at an attractive forward P/E of 13. Intel was one of the companies that helped set the tone early for first-quarter earnings season by showing earnings that nearly quadrupled from the year prior and giving an optimistic outlook for all of 2010.

And while I think the stocks of those blue-chip candidates could perform quite well, there may be even more opportunity for investors willing to consider small-cap stocks. The world of small caps is a largely uncharted sea of stocks that most institutional types avoid because they're too small to make an impact on huge mutual fund portfolios. For individual investors, though, they can be a great way to find hidden value -- particularly at the front end of an economic recovery.

If you're looking for stock ideas, the advisors at Motley Fool Hidden Gems are a great resource for new or veteran small-cap hunters. You can see their six Buy First stocks and read the research on all of their recommendations free for 30 days. Click here to get started.

This article was first published Aug. 4, 2009. It has been updated. 

Fool contributor Matt Koppenheffer owns shares of Intel, but does not own shares of any of the other companies mentioned in this article. Intel is a Motley Fool Inside Value recommendation. United Parcel Service is a Motley Fool Income Investor recommendation. The Fool has created a covered strangle position on Intel. Motley Fool Options has recommended a buy calls position on Intel. The Fool owns shares of Best Buy. The Fool's disclosure policy enjoyed Speed in spite of Keanu Reeves.