Investors aren't flocking into home improvement stocks today. With prices cooling, interest rates soaring, and a recession potentially on the way, Wall Street has abandoned the niche.

That said, the best returns come to investors who hold stocks through many economic cycles, meaning it could be the perfect time to establish a position in a world-class retailer like Home Depot (HD 0.22%). Let's take a closer look at whether the stock is a buy today or is too risky to own.

The latest trends

The good news is that Home Depot has already experienced some of the pain that investors are fearing is on the way. Interest rates have been climbing and home sales slowing for a while now. We can see the impact on the chain's results, and it isn't devastating.

In fact, Home Depot in mid-August revealed that Q2 comparable-store sales were up a healthy 6% on top of the prior year's 5% increase. The chain trounced rival Lowe's (LOW 0.43%) in this department, in part because of its stronger position in the professional contractor niche. Do-it-yourself shoppers pulled back spending in Q2 as inflation hurt their wallets. But Home Depot is still on track to grow sales yet again in 2022.

Profits and cash

Buying the stock today doesn't mean you're forced to give up earnings growth in exchange for that increasing revenue metric. Home Depot is finding ways to increase profitability despite soaring expenses. The rising operating margin seen in the chart is a good sign of pricing power, and it hints at other major competitive advantages.

HD Operating Margin (TTM) Chart

HD Operating Margin (TTM) data by YCharts

The business boasts other key financial selling points, including industry-leading return on invested capital and robust free cash flow. Management has directed much of its excess cash toward stock buybacks, but Home Depot also delivers a more generous dividend payment amounting to 55% of earnings compared to Lowe's 35% goal.

The path ahead

The company had to pause that dividend payout during the worst of the financial crisis housing slump from 2009 through 2011. That painful period also included several years of slumping sales and annual earnings.

Yet Home Depot's revenue sailed out of that recession, moving from a low of $65 billion in 2010 to $151 billion last year. Although few investors are predicting a similarly sharp pullback today, it is notable that shareholders earned excellent returns simply by holding Home Depot stock through the volatility around that major recession.

Price is another good reason to avoid waiting. Home Depot is valued today at about 1.8 times annual sales, or close to its lowest valuation since 2016.

On the other hand, investors don't have a clear idea of how Home Depot's business will perform in an era of high -- and rising -- interest rates. That's the main reason to wait on purchasing the stock. And it's a big one. Earnings and sales trends might be pressured for several years if home sales volumes fall too quickly.

This means you might prefer to wait on Home Depot stock if your time horizon is shorter than a few years. Longer horizons make it more likely that you'll profit from holding world-class businesses despite periods of economic disruptions. Home Depot clearly fits that description, so investors who can see beyond the current volatility should have no problem keeping the stock in their portfolios.