As the stock market sets new multiyear highs and many stocks are at or near all-time record levels, many investors are getting greedy. But prudent investors look at the recent optimism from a more balanced view, trying to figure out whether the strong advance in the market is sustainable. For them, the protection that portfolio diversification can provide may be what saves them from substantial losses whenever the next downturn strikes.

The basics of diversification
Many people think of having a diversified portfolio as meaning owning a lot of different stocks or funds. But much of the time, investors aren't nearly as diversified as they think they are. Especially among funds, you'll often find the same well-known big-company names prominently displayed on multiple top holdings lists, strongly suggesting that those funds will typically move in the same direction and therefore be useless in providing protection from downturns in those stocks.

Even if you don't own exactly the same stocks, that doesn't mean that you'll avoid the dangers of a concentrated set of investments. For instance, integrated oil company ExxonMobil (NYSE:XOM), refiner Phillips 66 (NYSE:PSX), and midstream pipeline MLP Kinder Morgan Energy Partners (NYSE: KMP) have very different focuses, with Exxon taking the broad view across the entire oil and gas field, while Phillips 66 earns its money primarily from refining crude oil into products like gasoline, diesel, and heating oil. Unlike Exxon or Phillips 66, Kinder Morgan's primary business isn't to produce various fuels but rather to deliver them to where they're needed. A portfolio with these three stocks might be slightly better diversified than just owning a single stock in this group, but all three are subject to many of the same factors and will therefore respond in similar fashion to some events that have broad implications for the entire energy sector.

The same is even true across industries in some cases. For instance, you might not think that fertilizer company Terra Nitrogen (NYSE: TNH) and electric utility Duke Energy (NYSE:DUK) would have anything in common. But both companies use natural gas, Duke increasingly to fuel its power plants and Terra as an input for its nitrogen-based fertilizers. As a result, a change in natural gas prices has an impact on both. They won't necessarily move in exactly the same way, but market-moving news on the natural gas front can push their stocks in the same direction.

How to get diversified
In order to have true diversification, you need to have investments whose movements aren't correlated. For instance, bonds have traditionally been a good counterbalance against stocks, as a booming stock market draws money out of bonds and sends their prices downward, whereas risk-averse investors fleeing stocks when markets fall tend to prefer the safe-harbor status that bonds have historically provided.

That's tougher to accomplish than you might think, because relationships among markets tend to change over time. For instance, international stocks used to give investors much different results than their U.S. counterparts, largely because economic conditions in individual countries differed greatly from nation to nation. With the economy having gotten increasingly global, however, correlations among those markets have gotten greater, and thus they've tended to move much more closely together in recent years -- especially in times of crisis.

Similarly, commodities were once seen as being independent of stocks. But some of the same factors that drive liquidity into the stock market also encourage commodity investing, and with the rise of exchange-traded funds that allow individual investors to take commodity positions easily, commodities have started moving more closely with stocks.

That's not to say that seeking portfolio diversification is a hopeless cause. What it does mean, though, is that you can't count on a particular strategy working forever. It takes constant diligence to make sure you have as much protection as you can find.

Stay smart
Whenever markets are doing well, it pays to take a look to make sure you won't give back all the hard-earned gains you've gotten. Making sure you're truly diversified is an important step toward protecting your portfolio.

This article represents the opinion of the writer, who may disagree with the “official” recommendation position of a Motley Fool premium advisory service. We’re motley! Questioning an investing thesis -- even one of our own -- helps us all think critically about investing and make decisions that help us become smarter, happier, and richer.