We won't know exactly how Wal-Mart (WMT 0.46%) fared during the holidays until February, but the retailer will likely put up solid numbers if the first nine months of 2017 are any indication. Wal-Mart had an outstanding 2017 on pretty much every front. The stock soared 42%, handily beating the broader market. The company's thousands of stores produced consistent sales growth, and the online business exploded.

A bet that paid off

Shares of Wal-Mart crashed in 2015, losing 28% of their value. Part of the reason was the company's plan to raise wages and invest in its employees. CEO Doug McMillon announced the plan in February 2015. It featured a higher starting wage, improved training programs, better benefits, and more flexible scheduling.

The front of a Walmart store.

Image source: Wal-Mart.

Concerns that these changes would knock down earnings took a toll on the stock price. Those fears weren't misplaced -- Wal-Mart reported earnings declines in both 2015 and 2016. But the long-term benefits outweigh the short-term downside. Wal-Mart has reported comparable sales growth in the U.S. for 13 consecutive quarters, despite a retail environment that's testing many of its peers. Wal-Mart had no trouble driving traffic to its stores in 2017.

Period

U.S. Comparable Sales Growth

U.S. Comparable Traffic Growth

Q3 

2.7%

1.5%

Q2 

1.8%

1.3%

Q1 

1.4%

1.5%

Data source: Wal-Mart.

Profits are still being pressured by the company's investment in its stores, as well as its e-commerce initiatives. But it's clear that Wal-Mart's strategy is working.

An e-commerce monster

Wal-Mart paid $3 billion for e-commerce start-up Jet.com in late 2016. Jet.com CEO Marc Lore was put in charge of Wal-Mart's entire e-commerce operation. It was an expensive acquisition, but it jump-started the company's e-commerce efforts at a time when it absolutely needed to catch up to Amazon.

The results of this acquisition and Wal-Mart's other e-commerce initiatives speak for themselves.

Period

U.S. E-Commerce Year-Over-Year Sales Growth

Q3

50%

Q2

60%

Q1

63%

Data source: Wal-Mart.

Organic growth through Walmart.com drove much of these sales gains. The company has vastly expanded its assortment of products, launched free two-day shipping on orders over $35, and introduced pick-up discounts on certain items. It also plans to bring Jet.com's "Smart Cart" feature to Walmart.com sometime this year, providing another way for customers to save money.

Beyond standard e-commerce, Wal-Mart's online grocery service is another driver of this growth. The free service is available at more than 1,000 locations as of September, and the company is testing out online grocery delivery in a handful of markets. Other supermarket chains, including Kroger, offer similar services. But Wal-Mart has been aggressive as it defends its grocery market share and attempts to win even more.

Not a cheap stock

That 42% gain in 2017 has made Wal-Mart stock a lot less attractive, despite the fact that nearly everything seems to be going right for the company. Wal-Mart expects to produce adjusted earnings of as much as $4.46 per share in fiscal 2018, which ends this month. That puts the price-to-earnings ratio at a lofty 22.

To be fair, earnings are still depressed from the investments that Wal-Mart is making. But the intensity of those investments, especially in e-commerce, probably isn't going to let up anytime soon. Wal-Mart is aiming to be a meaningful alternative to Amazon, a company that operates with razor-thin or nonexistent margins. Going after the market leader won't be cheap.

That's not to say that Wal-Mart won't be a solid investment. I just don't think we'll see a repeat of 2017 this year. Earnings need to catch up with the stock price, and it's hard to say what kind of growth rate Wal-Mart can achieve as it goes head-to-head with Amazon.