Walmart (NYSE:WMT) shareholders had a good year in 2020. Their stock outpaced the S&P 500 for almost the entire period and shares even avoided a sharp drop during the market downturn in late March and April.

Yet the retailing giant's performance trailed peers like Costco and Target, suggesting investors have comparatively low expectations for the year ahead. With that in mind, let's take a closer look what really drove Walmart's performance in 2020.

^SPX Chart

^SPX data by YCharts.

The strategy works

Changing consumer demand priorities during the pandemic rewarded companies that could deliver a seamless digital and physical shopping experience, which has been a strategic goal of Walmart's for years. The company showed off its progress on this score by posting 10% higher comparable-store sales in fiscal Q1, a 9.3% boost in Q2, and a 6.4% increase in Q3.

A masked woman shops for groceries.

Image source: Getty Images.

Surging e-commerce volume offset declining store traffic in each of these periods, and the company mostly succeeded in stocking popular products like consumer staples and home furnishing supplies. That was no small feat considering the massive supply chain challenges it dealt with and the unprecedented demand levels that held across constantly shifting categories throughout the year.

Walmart could have done better, though. Rivals like Costco and Target posted stronger comps growth in 2020, and even Kroger managed to claw back some of the market share it had recently lost in the grocery niche. That relative growth performance is one key factor behind the stock's muted rise in 2020. It's also an open question as to where growth will settle over the next few quarters given the fact that comps have slowed in each of the last two reporting periods.

Profits and cash

On the other hand, Walmart shareholders can celebrate the fact that profitability is rising, with gains likely to persist now that the retailer has an efficient omnichannel platform up and running. Adjusted operating income jumped 19% last quarter, with help from rising gross profit margin as Walmart sold more discretionary products like consumer electronics and home furniture.

Cash returns should support the stock in 2021, too. Walmart executives scaled back on repurchase spending in 2020 due to the increased volatility brought on by the pandemic. As a result, they're heading into the new fiscal year with an unusually high cash balance that they'll likely direct toward buybacks and dividends as soon as the economic outlook settles down.

WMT Stock Buybacks (TTM) Chart

WMT Stock Buybacks (TTM) data by YCharts.

Walmart's income potential is modest. The stock promises an annual yield of about 1.5%, similar to Target's and above Costco's.

Looking ahead

Investors will have a clearer picture of Walmart's 2021 prospects when CEO Doug McMillon and his team issue their Q4 report in mid-February. Assuming no big surprises in that announcement, the most likely scenario is that the retailer continues to modestly outperform the market thanks to competitive assets like its leadership position and improving earnings outlook.

Yes, Walmart's massive sales base means that these strengths can't drive big revenue gains. But they protect shareholders during market downturns and support a cash-rich business. Wall Street acknowledged that success in 2020 and should continue seeing value in this stock for the year ahead.

This article represents the opinion of the writer, who may disagree with the “official” recommendation position of a Motley Fool premium advisory service. We’re motley! Questioning an investing thesis -- even one of our own -- helps us all think critically about investing and make decisions that help us become smarter, happier, and richer.