With the S&P 500 and Nasdaq Composite both well off their all-time highs, now could prove to be one of the best times to put some money to work in the stock market. If history tells us anything, it's that buying equities when uncertainty is high and pessimism is bountiful can lead to outsized returns for the patient investor. 

If you've found yourself sitting on some extra cash right now, take a closer look at Costco Wholesale (COST -0.24%) and Home Depot (HD 0.74%). These top retail stocks could be great buys for your portfolio. 

Costco 

Warehouse club retailer Costco just announced its fiscal 2023 second-quarter financials, and they were a bit of a mixed bag. Total revenue of $55.3 billion fell short of Wall Street expectations of $55.6 billion. Earnings per share (EPS) of $3.30, however, exceeded estimates of $3.21. What's more, same-store sales, or comps, were up 5.2%. This period's performance continues a trend of decelerating year-over-year growth over the past several quarters. 

During the earnings call, CFO Richard Galanti highlighted weakness in big-ticket discretionary items like home furnishings, small electrics, jewelry, and hardware. He mentioned the softening economic backdrop, as well as difficult comparisons for these items during the pandemic and even last year, as reasons for the declines. On the positive side, the leadership team does believe that inflation is improving. 

Despite the near-term macroeconomic factors -- which are affecting really every retailer out there -- shareholders have a lot to like about this business. Costco's relentless focus on providing the lowest prices around provides some downside protection in uncertain times, particularly when consumers need to stretch their dollars further. Operating a successful membership-based model that has a worldwide renewal rate of 90.5% certainly helps drive customer loyalty and stickiness. 

While Costco currently trades at a price-to-earnings (P/E) multiple of 36, which is by no means cheap, investors might still want to consider the stock. What's impressive about this business is its durability as it finds ways to succeed in any economic environment thanks to its second-to-none customer value proposition.

If a company's staying power is something that is important to you, then it might be worth paying up for this quality enterprise. 

Home Depot 

Home Depot appears to be in a similar boat as Costco, seeing a business slowdown. Revenue and comps in the most recent fiscal period (fourth quarter of 2022, ended Jan. 31) were up just 0.3% and down 0.3%, respectively, compared to the prior-year period. Although operating income declined 1.5%, diluted EPS increased 2.8% thanks to a smaller outstanding share count.

For a business that caters to homeowners, it's not a huge surprise that macroeconomic concerns are starting to have an impact on Home Depot. Inflation directs consumers' extra income to more essential needs, which can result in renovation projects being delayed. Management specifically called out a shift in consumer spending from goods to services. This is a headwind shareholders need to pay attention to. 

But it's hard to overstate Home Depot's competitive strengths, namely when it comes to distribution. With its 2,007 stores in the U.S., the company's physical footprint is within 10 miles of 90% of the country's population. This makes it easy for DIY and professional customers to get whatever tools and supplies they need. Moreover, this bolsters Home Depot's omnichannel presence. Last quarter, 45% of online orders were actually picked up at a store. 

As of this writing, Home Depot shares are selling at a P/E ratio of 18, lower than the 10-year historical average. In fact, Home Depot's stock is trading at a discount to its smaller rival, Lowe's. And it's about the same P/E multiple as the broader S&P 500 index, despite unquestionably being a better-than-average company. 

I don't have any doubts that Home Depot will be able to navigate the current softer macroeconomic climate without much trouble. It's a critical component of the U.S. economy and still has a sizable growth opportunity ahead of it. This makes it a worthy investment candidate if you're sitting on some extra cash right now.