Feeling down about the market? Looking for something to perk you up? Here's an eye-opening exercise. Click over to a stock screener, like the one in Motley Fool CAPS, and ask it to give you all the stocks in the S&P 500 that have gained in value so far in 2008. With the market having fallen some 40%, you might expect no stocks to have risen. But you'd be wrong. When I ran that screen this morning, I got 21 trend-bucking companies -- a whopping 4% of the S&P 500!. Here they are, in descending order:

Company

Return, Year-to-Date

Family Dollar (NYSE:FDO)

39%

Rohm and Haas

33%

UST

31%

Amgen

25%

Barr Pharmaceuticals (NYSE:BRL)

25%

H&R Block

21%

Wal-Mart (NYSE:WMT)

19%

Celgene                                         

17%

Hasbro (NYSE:HAS)

15%

AutoZone

13%

Cephalon

9%

Pulte Homes

9%

Apollo Group (NASDAQ:APOL)

8%

General Mills (NYSE:GIS)

8%

McDonald's (NYSE:MCD)

7%

Gilead Sciences

6%

Hudson City Bancorp

6%

Wells Fargo

2%

Lowe's

2%

Public Storage

2%

People's United Financial

1%

Data: Yahoo! Finance as of Dec. 18, 2008.

Let's try to figure out why some of these companies ended up on the list.  

  • McDonald's and Wal-Mart. Well, we should start with the economy, right? If you're out of a job or are worried about losing your job, you will likely change some habits. Instead of dining at your favorite restaurants, or even buying those great $5 sandwiches you can get at various delis, you are likely to look at food purveyors such as McDonald's, which offer sandwiches for as little as a dollar. Meanwhile, Wal-Mart will draw your attention more often, as you'll be able to save money by shopping there.
  • Family Dollar. You're not going to find many stores with lower prices than Family Dollar. It seems that many investors also expect consumers to gravitate more toward stores like Family Dollar as the recession continues.
  • Apollo Group. This long-distance learning specialist can be seen as another play related to our sluggish economy. Many people are already out of work and others are scared of losing their jobs. Given that, many will be considering new careers or simply boosting their education. A perfect solution for many? Apollo's University of Phoenix. Other online schools are also doing well.
  • General Mills. The maker of Wheaties cereal and other tasty treats is another recession play, of course. As consumers tighten their belts, they'll likely be eating at home more. But the company has other things going for it, too, such as significant cost-cutting in recent years, via simplifying its product lines and shrinking packaging. A lesson here is that within a recession, companies that are able to boost their bottom lines via cost-cutting can catch the attention and respect of investors, especially if they're defensive in nature.
  • Barr Pharmaceuticals. This is another defensive play, as people need medicine no matter what the economy is doing. In addition, as baby boomers age, prescription use will likely grow. For the most part, though, Barr's gain can be attributed to its buyout by Teva Pharmaceutical, whose shares are down just slightly for the year.
  • Hasbro. This is an example of the power of brands being resilient in a rough economy. Hasbro offers wares labeled with names such as Trivial Pursuit, G.I. Joe, Transformers, Mr. Potato Head, Monopoly, Cranium, Candyland, Scrabble, and Twister. In addition, the company has been buying back many of its shares of stock, which (a) signals that it views the shares as good values at recent prices and (b) boosts the value of the remaining shares for shareholders.

Overall, these companies and others offer us some critical reassurance that, in any given down market, there will be some companies that will buck the trend and outperform. And better still, remember that a fallen market is rife with bargains. As my Motley Fool colleagues have suggested, this might be the best investing opportunity of the past decade or even the past 35 years!