Ten years ago, Amazon (AMZN 0.35%) was valued at $55 billion. Walmart (WMT -0.27%) -- the undisputed king of retail at the time -- was almost four times that size. But the past decade has been characterized by the conversion to e-commerce, and Amazon has risen to become one of the most valuable companies in the world today.

But as investors, we're a forward-looking bunch. Which of these two stocks is the top stock to buy at today's prices? While we can never answer that question with certainty, we can compare the two companies on three key characteristics to see which we are more comfortable buying.

Financial fortitude

First, we'll investigate financial fortitude. This asks a simple question: If a financial crisis kicked off tomorrow, how would these companies be affected? We all know that both Walmart and Amazon can survive a crisis -- that's just what they did ten years ago. 

But could either of them benefit from it? Let's take a look, remembering that today Amazon is valued at more than twice Walmart:

Company Cash Debt Free Cash Flow
Walmart $8.6 billion $44.9 billion $13.9 billion
Amazon $43.4 billion $22.5 billion $20.0 billion

Data source: Yahoo! Finance. Cash includes long and short-term investments. Free cash flow presented on trailing twelve month basis.

The winner here is clear: Amazon. The fact that it has a much higher cash position, less debt, and stronger free cash flows means that it has more flexibility. If a crisis were to occur, it could buy back more of its own stock, acquire rivals, or simply drive more competition out of the market by outspending them.

That's not to say that Walmart's balance sheet is unhealthy. With cash flows like it has, Walmart should have little trouble paying off debt. It simply has less flexibility.

Winner = Amazon

Valuation

Second, we'll tackle valuation. This is basically to see if one company's stock is "cheaper" than the other's. Because this is part science, part art, I like to consult a number of different variables to see which stock has a more appealing price tag.

Company P/E P/FCF P/S Dividend Yield
Walmart 24 24 0.6 1.8%
Amazon 77 44 3.3 0%

Data source: Yahoo! Finance, YCharts, E*Trade. P/E presented using non-GAAP earnings when applicable.

Here again we have a clear winner...but this time it's Walmart. Not only is Walmart trading at a significant discount to Amazon based on earnings (P/E), free cash flow (P/FCF), and sales (P/S), but it also offers investors a dividend. And over the past twelve months, Walmart has only had to use about 43% of its free cash flow to pay that dividend. That means it is both sustainable and has lots of room for growth.

Winner = Walmart

Sustainable competitive advantages

Finally, we have what I consider to be the most important thing to investigate: a company's "moat." You can break down types of moats into four general forms:

  1. Network effects: Where each additional customer makes the product or service more valuable.
  2. High switching-costs: Customers would be loathe to switch, either because of the cost or time and energy required to do so.
  3. Low-cost production: When one company can provide something at a lower cost than the competition.
  4. Intangible assets: This includes patents, government-backed protection, and brand value.

Viewed from 30,000 feet, Walmart benefits from many moats. Forbes rated the company's brand as the 26th most valuable in the world. Additionally, the company's vast network of stores allows it to negotiate lower prices for goods from producers. It can then pass those savings on to customers. More recently, those same physical locations have also become a boon for Walmart's booming e-commerce business, as they provide easier pick-up locations for customers.

If Walmart were up against just about any other company, this host of moats would be more than enough to win this contest. But Amazon isn't just any other company. Consider:

  • Network effects: Because Amazon.com is the de-facto choice for online shopping, it attracts lots of eyeballs. That leads many third-party providers to list on Amazon and use Fulfillment by Amazon, which only draws more customers.
  • High switching costs: Companies that have set up their businesses on Amazon Web Services (AWS), the company's cloud offering, would think twice about switching to another provider given the complexity of the task and the amount of time it could take.
  • Low-cost production: This is the key moat. With hundreds of fulfillment centers worldwide, Amazon can guarantee quick delivery for a lower internal cost than any other company in the world.
  • Intangibles: Forbes rated Amazon's brand as the 4th most valuable in the world.

Given these advantages, Amazon gets the nod.

Winner = Amazon

And my winner is...

So there you have it: While Walmart might have a more appealing stock price, Amazon has a wider moat with a larger war chest on hand. I've backed up my conviction with my own portfolio: Amazon accounts for 17% of my family's real-life holdings.

At the same time, I have also been very impressed with Walmart's ability to evolve in the age of e-commerce. While I haven't bought shares myself, I have given it an outperform rating on my CAPS profile, and I think it is a wise choice for investors who don't like volatility and enjoy getting quarterly dividends to consider.