The stock market is an excellent vehicle for generating wealth over many years. It isn't the only way to build up a large retirement nest egg, of course, but owning a diversified portfolio of stocks puts you in a great position to benefit from the long-term growth of the global economy.

Besides having a long holding period, the other main ingredient necessary to produce great returns is owning the right stocks. You'll do well simply matching the wider market's roughly 15% annual appreciation. But extending that figure by even a percentage point or two can make a huge difference over several decades.

With that goal in mind, let's look at a few stocks that seem destined to be a positive force in your retirement portfolio.

1. Apple

Apple's (AAPL -0.35%) business has been going through a rough patch lately, with sales declining to $383 billion from $394 billion in the most recent fiscal year. Consumers were less excited to purchase iPhone and Mac products in 2023 as demand for tech devices slowed overall following big gains in the prior two years.

Apple is still an incredibly strong business. The company's $383 billion of revenue last year compares well to the $366 billion posted two years earlier. Success in its rapidly expanding services segment offset most of the weakness in the iPhone and Mac franchises in 2023, and that should help to stabilize growth going forward. Growth has returned at the start of fiscal 2025, although it will take some time before it speeds back up toward the double digits.

Meanwhile, you'll struggle to find a more financially impressive company. Apple regularly generates more than $100 billion in annual operating cash flow. Those resources allow management to spend aggressively on repurchasing the stock, which in turn amplifies per-share earnings growth. Investors should benefit from that virtuous cycle, even through those inevitable periods of sluggish sales trends.

2. Walmart

Walmart (WMT -0.08%) has created many millionaires over the decades that it worked to build its dominant retailing business. That process might not be over just yet.

Sure, the chain already has a massive global sales base, and a high valuation to go along with it. Walmart won't quickly double or triple its current $500 billion market capitalization.

But that doesn't mean you can't get great returns from holding this retailer over the next several decades. Sales growth was robust in 2023 and was anchored by rising customer traffic. That success reflects Walmart's ability to deliver value to its core shoppers, who are increasingly looking for deals. Few of its peers can match Walmart's low prices, which flow from its massive economies of scale.

Shareholders today have a good chance at capitalizing on Walmart's push to become more than just a brick-and-mortar retailer. E-commerce sales last year crossed $100 billion and jumped more than 20% compared to the prior year. Walmart is getting a lift from its growing digital advertising business as well.

These wins are lifting the company's profit margin above the 3% to 4% rate that investors have seen for many years. Even a small uptick here would have a huge impact on Walmart's annual earnings potential -- if the retailer can make it a sustainable one.

While they wait for progress on this score, shareholders can collect Walmart's dividend and allow those quarterly payments to automatically reinvest into more shares. That way, you'll amplify your long-term returns and speed up the process of building wealth with your portfolio.