Earlier this month in an interview with CNBC, financial analyst Gary Shilling warned that there could be a "delayed" recession. He noted that he is seeing some traditional and reliable forerunners to a recession, including the current inverted yield curve and small businesses cutting back on spending and employment. He added that on average, a recession starts within two years after the Federal Reserve starts to raise rates. The Fed started raising rates in March 2022, so it has been just over two years.

Shilling was one of the analysts back in 2007-08 warning investors about the housing bubble that was developing. It led to the Great Recession of 2008-09 which had a long-term adverse effect on the economy. In other words, he has some street cred when it comes to macroeconomic predictions.

A recession is typically bad for the stock market, and investors are always looking for ways to cope when such downturns hit. Walmart (WMT 0.13%) has proven to be a strong performer during these periods. Here's why it's a stock to consider in light of Shilling's comments.

Walmart is a low-cost leader

Walmart tends to perform well in a recession for several reasons. One is that it sells a lot of everyday necessities that people will buy regardless of the broader economy. The company has become the largest grocer in the U.S. by far, twice as big as Kroger, its largest grocery competitor (as measured by revenue). This gives the company tremendous scale and buying power, which allows it to get the best prices. It then turns around and passes these low prices on to its customers.

The company is a low-cost leader, and in times of economic stress, it isn't afraid to push prices even lower. This allows it to gain share from both traditional grocers and general merchandise retailers like Target.

Walmart also benefits from the trade-down effect. During more difficult economic times, even higher-income people will often look for lower-priced alternatives. Walmart tends to attract more high-income customers during tougher economic times, given its everyday lower prices.

The company has already been making inroads into the higher-income demographic in the past few years, as more consumers try to cope with the elevated inflationary environment. Walmart is seeing share increases among households earning more than $100,000. This started largely in grocery but has moved into general merchandise as well.

The company has been leaning into both value and convenience to retain and increase its share of higher-income customers. It's been updating stores to include wider aisles and better lighting fixtures, and pickup and delivery services have also resonated with this demographic group. Its Walmart+ paid subscription service, which offers perks such as discounts on gas, unlimited free delivery, and free streaming through Paramount+, has also been a hit among higher earners. The subscription, which is the company's attempt to compete with Amazon Prime, costs $98 a year, or $12.95 if paid on a monthly basis.

Given the strides Walmart has been making attracting higher-income customers, a recession could very well help it accelerate this push. Services such as pickup and delivery and Walmart+ could later help with customer retention as well. At the same time, once new customers enter the Walmart ecosystem, the company has a lot of opportunities to sell them not only groceries and necessities but various other services -- from pharmacy to auto to financial services. This is important, as it creates a long runway for future growth.

Person putting items in basket in store aisle.

Image source: Getty Images.

A recession out-performer

Walmart stock outperformed the S&P 500 during the past two big recessions (2020 and 2008-09). In 2020, during the start of the COVID-19 pandemic, it outperformed the S&P 500 by five percentage points. But early on, when the S&P 500 was down 25% from its highs in March 2020, Walmart's stock was trading up 2%. During the housing crisis of 2008-09, meanwhile, it easily outpaced the S&P 500 by over 56 percentage points.

The company was able to grow its sales during both the past two recessions. In 2020, its sales rose by nearly 2%, while its sales rose by nearly 9% in 2008. Given the uniqueness of the pandemic, 2008 is probably more reflective of how Walmart would perform in a more typical recession. The company is also now more skewed toward groceries, so it could perform even better in the next recession than it did in 2008.

The great thing about Walmart, though, is that it can perform well in any environment. The stock is up over 20% over the past year in an inflationary environment. Meanwhile, the company grew its sales a solid 6%, and operating income grew even faster at 32%.

This makes Walmart a top buy not only if there is a recession, but over the long term as well.