Rising mortgage rates and a softening housing market can unsurprisingly have a negative impact on Home Depot's (HD 0.02%) business. In this kind of macroeconomic environment, consumers are less inclined to take on costly renovation projects, something they can delay until better days are on the horizon. And a situation like this will also result in investors souring on the company's stock. 

With shares down substantially this year, is it time to buy Home Depot stock? Let's take a closer look. 

Strong momentum 

Despite mortgage rates climbing to a level they haven't been in 15 years, coupled with home prices in the U.S. cooling over the past few months, Home Depot's business continues showing its resilience. In the fiscal 2022 second quarter (ended July 31), the company's revenue of $43.8 billion (up 6.5% year over year) and diluted earnings per share of $5.05 (up 11.5%) both exceeded Wall Street estimates.  

Throughout the pandemic, with people spending more time at home, undertaking renovation projects was a new focus. And Home Depot's sales surged, jumping 19.9% in fiscal 2020 and 14.4% in fiscal 2021. Following this double-digit growth, the expectation was that with the economy pumping the brakes, Home Depot's business would as well. 

However, management mentioned no meaningful slowdown in demand, with both DIY and Pro customers continuing to post growth and order backlogs remaining healthy. In fact, sales gains from professionals outpaced the DIY segment, demonstrating consumers' willingness to tackle even bigger and more complex projects. Same-store sales increased 5.8% year over year, and sales per retail square foot rose 5.7%. Both were positively affected by the strength in the Pro customer. 

"Despite near term uncertainties, we believe that the long-term underpinnings of demand for home improvement remain strong and that we are well-positioned to leverage our distinct competitive advantages to capitalize on compelling growth opportunities in our space," CEO Ted Decker said in the Q2 earnings call. 

It is no doubt a difficult operating environment, with inflation squeezing margins at many companies while pinching consumer budgets. Given this economic backdrop, it's even more impressive that Home Depot was able to post an operating margin of 16.5% in the latest quarter, up from 16.1% in the prior-year period. Rival Lowe's fares worse when it comes to this profitability metric, with an operating margin of 15.4% in its most recent quarter. 

Current valuation 

With Home Depot shares down 34% in 2022, it's clear that pessimism surrounding the stock is elevated thanks to weakness in both the stock market and the housing market in the U.S. As a result, shares are currently trading hands at a price-to-earnings (P/E) ratio of just 17, cheaper than the S&P 500's P/E of 18. Furthermore, that figure is well below Home Depot's trailing-10-year P/E multiple of 23, making for an incredibly attractive entry point for investors to scoop up the stock. 

Nonetheless, the Federal Reserve's aggressive hiking of interest rates has some experts predicting a recession in the near term. This means that if your investment time horizon is a couple years, then you might want to think long and hard before adding Home Depot to your portfolio. That's because an economic downturn could have a major negative impact on the housing market, and in turn, this will hurt the company's business prospects because people will hold off on renovation projects. 

On the other hand, for those who truly adopt a long-term mindset when it comes to investing and can look out over the next five to 10 years, buying Home Depot stock looks like a no-brainer decision right now. This is an outstanding business that has delivered sales and earnings growth, as well as fantastic stock returns, over its history. Whatever headwinds it is currently facing, I have no doubt that management will be able to successfully navigate them.