It's not just companies with exposure to the hypergrowth artificial intelligence space that have registered huge returns. Even a boring retailer, such as Costco (COST 1.01%), is up big. Its shares have more than tripled just in the last five years. For comparison's sake, the S&P 500 is up 86% during the same time.

This has undoubtedly been a magnificent stock. It's already up double digits in 2024 (as of March 21) as the momentum continues. And it was a longtime favorite of the late great Charlie Munger.

However, you shouldn't buy Costco shares right now. There's a very obvious reason for that.

Don't ignore a key factor in investing

The era of ultra-low interest rates and cheap debt during the 2010s led to surging stock prices that were disconnected from business fundamentals. In this environment, it seemed like investors cared less about valuation, instead prioritizing growth and business quality above all else. That's not necessarily a bad thing, but it ignores the fact that valuation is still a critical component of successful investing.

Here's where Costco's monster stock return in recent years has become a reason not to buy shares. As of this writing, the stock trades at a nosebleed price-to-earnings (P/E) ratio of just under 49. Except for earlier this month, shares haven't been this expensive this century. This tells me that the optimism surrounding Costco is at high levels right now.

And that's precisely why it's not smart to buy the stock. Yes, Costco has reported strong fundamentals. However, its P/E ratio has also soared by 60% in the past five years. The market continues to bid up the stock, even as the business's growth opportunities become limited over time. No one argues with the fact that Costco has far less expansion potential today than it did even a decade ago. But back then, the P/E multiple was at 25.

When expectations are this elevated, it leaves no margin of safety for prospective shareholders. Consequently, there is a lot more downside risk than upside.

Investors should wait until there's a major pullback before buying. But what valuation is appropriate? Everyone's opinion is different, but I wouldn't invest unless the P/E multiple got back to the mid-20s range.

A high-quality enterprise

Part of the reason Costco's stock has performed so well is its strong financial performance. Net sales climbed 60% between fiscal 2019 and fiscal 2023, a disruptive period of time that included the onset of the coronavirus pandemic, inflationary pressures, and rapidly rising interest rates. There are still fears about a recession these days, but Costco was still able to grow same-store sales by 5.6% in the latest quarter (Q2 2024 ended Feb. 18). This is a steady and consistent business and that has clearly deserved a premium from investors.

During the previously mentioned four-year stretch, Costco's diluted earnings per share increased at a faster clip. The operating margin might look low, but the fact that the bottom line has expanded more than revenue shows that Costco can scale up.

Costco's massive scale is exactly what creates its most important competitive advantage. As the world's third-largest retailer, it has unrivaled purchasing power and negotiating leverage with its suppliers. And these lower per-unit costs are passed on to shoppers in the form of low prices.

However, not just anyone can shop at a Costco warehouse. The business operates a successful membership model that has an outstanding renewal rate of 92.9% in the U.S. and Canada. This also drives loyalty.

Succeeding over the long term in the retail sector is the exception to the rule. Costco has established itself as a dominant presence in the industry. However, the market more than fully appreciates this, so you shouldn't buy the stock right now.