The stock market has been a lousy place for most investors over the past few months. But it's not a stock market but rather a market of stocks, and as you'd expect, some companies saw their shares hold up quite well even during one of the worst periods for financial markets in history. Below, I'll talk about some of the winners among the wreckage of the quarter, but first, let's take a look back to see why markets have responded as badly as they have since July.

A quarter to forget
The third quarter's terrible performance for stocks reminded investors of just how bad things were three years ago. With the S&P 500 falling 14% in the third quarter, the market's decline was worse than any since the worst part of the 2008 bear market.

It's not hard to understand why. After a lengthy bull run predicated on slow but steady economic growth in the U.S. and abroad, doubts began to emerge over whether the future will actually turn out to be as rosy as everyone hopes. Weak economic data from China suggest that the long, red-hot expansion there is at best cooling and at worst heading for a hard landing that could threaten to destabilize the nation's housing market, which some see as being in a bubble. Given the importance of Chinese growth for materials companies like Cliffs Natural Resources (NYSE: CLF) and Peabody Energy, the ripple effects from an emerging-market slowdown will undoubtedly extend around the world.

At the same time, things in the developed world are equally uncertain. Europe continues to tiptoe around the core issues surrounding its sovereign debt problem, coming up with bailout plans while leaving largely untouched the need to match up government spending and revenue across the eurozone. Meanwhile, in the U.S., the failure of the political system to find real solutions to economic and budgetary problems has made investors increasingly pessimistic that it's even possible for government to fix things.

What worked well
Amid the gloom, you might think that no stock could emerge unscathed. But many did. Here are several of the biggest U.S. companies to see their stocks rise over the past three months:

Stock

Price Change, July 8 to Oct. 6

Current Dividend Yield

McDonald's (NYSE: MCD) 1.8% 3.2%
Altria (NYSE: MO) 0.2% 6.1%
Bristol-Myers Squibb (NYSE: BMY) 11.4% 4.1%
Duke Energy (NYSE: DUK) 2.7% 5.1%
Kimberly-Clark (NYSE: KMB) 6.5% 3.9%
General Mills (NYSE: GIS) 3.7% 3.2%

Source: Motley Fool CAPS. Price change does not adjust for dividends paid during the period.

Why did these stocks do well when the rest of the market was down sharply? It's not because they don't face challenges. Kimberly-Clark still sees commodity inflation hurting its earnings, and General Mills has the same headwind facing it. Altria will have to post even bigger warning labels on its cigarettes starting next year. And none of these companies wants to see economic growth stall out.

But in general, what holds these stocks up even during tough times is the fact that their customers keep buying what these companies sell. Unlike more cyclical stocks whose revenue patterns are much more closely tied to the condition of the overall economy, these companies can expect to retain a strong foundation of loyal customers who will give some stability to their financial results -- and by extension, their stocks.

Gimme shelter
Obviously, it's impossible to predict what will happen next in the financial markets. But if you're concerned about preserving your capital, taking a look at defensive bellwether stocks that have already proven they can weather stock market storms in the past could be exactly what you need to feel more confident about your investments.

If you like dividend stocks, you'll love The Motley Fool's free special report, "13 High-Yielding Stocks to Buy Today." You'll find a baker's dozen ideas to boost your income.