Amazon or Walmart: Which stock is the better buy?

How the heck does Amazon make money?
How the heck does Amazon make money?

If Amazon really wanted to give its customers a special treat on Prime Day, it would offer a massive sale on its stock.

Shares of Amazon (AMZN) are up more than 50% this year and are trading near an all-time high. The company is now worth $215 billion.

At this rate, it's possible that Amazon will soon become more valuable than struggling Walmart (WMT).

Walmart's stock has rolled back 15% this year and the company's market value is about $235 billion.

Over the past five years, Amazon's stock has torched Walmart's.

Amazon is the clear leader in online retail. Walmart is desperately trying to catch up. Hence, the company's decision to quickly counter Amazon's Prime Day event with its own "atomic" online deals.

Walmart seemed to be getting some good attention for its Wednesday event. Unlike Amazon, which had waitlists for some of its "Lightning" deals, Walmart's sales were immediately available to shoppers.

Related: Angry Amazon customers vent about #PrimeDay sale fail

Plus, you don't need to spend $99 on an annual membership to take advantage of Walmart's sales.

But playing catch up comes at a cost. Heavy investments in online retail is one reason why Walmart's profits have been disappointing this year. It's also facing tough competition from Target (TGT) and Costco (COST).

Still, there's no denying that Walmart is a better bargain of a stock than Amazon right now.

Walmart's answer to Amazon: Pick up at our store
Walmart's answer to Amazon: Pick up at our store

Walmart trades for less than 15 times earnings estimates for its next fiscal year while Amazon has an astronomical valuation of nearly 170 times profit forecasts for 2016.

Warren Buffett's Berkshire Hathaway (BRKB) is a big investor in Walmart. Many other value investors like the stock too.

Walmart consistently generates a profit every quarter. That's not always the case with Amazon.

Heavy investments in new products often hurt its earnings. Amazon also spends a lot on shipping costs as part of its Prime program.

Related: Amazon and Walmart's big sales day: 10 things you need to know

Of course, Amazon has a lot more momentum than Walmart. Its revenues are expected to increase by more than 15% this year and next. Walmart's revenues are likely to grow in the single digits.

And even though Amazon usually loses money in the first nine months of the year, it more than makes up for that during the holidays -- just like many other retailers. Amazon is expected to be profitable this year thanks to big earnings in the fourth quarter.

Amazon is also much more than just a retailer. The company's cloud computing business -- Amazon Web Services -- is rapidly growing.

So if you are the type of shopper that is willing to pay a premium price for quality, Amazon may still be a good bet despite its sticker-shock inducing price.

Related: Facebook now worth more than Walmart

Walmart, on the other hand, is a classic buyer beware stock. It's cheap. But there's a good reason for that.

Yes, Amazon is risky. But investors who have been bearish about Amazon's long-term prospects have been pretty much wrong for two decades now.

Remember, the reason that Amazon is having Prime Day in the first place is to celebrate its 20th anniversary.

CEO Jeff Bezos clearly is more concerned with long-term growth than meeting Wall Street's short-term goals. And that strategy has worked.

CNNMoney Sponsors