Equity markets have performed well in the past 12 months, much to the joy of investors. Maybe that will continue next year or perhaps it won't. But no matter what happens in 2022, it's essential to look beyond the stock market's performance during a single calendar year. The magic formula to grow capital is always the same. 

First, buy shares of great companies. Second, keep these shares for a while, even amid market booms and busts. Let's look into two companies that could be excellent forever holdings: DexCom (DXCM 0.33%) and Amazon (AMZN -1.14%). Here's why both are worth buying. 

DXCM Chart

1. DexCom

Medical devices specialist DexCom has handily outperformed the market this year. The company can thank the increasing adoption of its G6 Continuous Glucose Monitoring (CGM) system for that. CGM devices help diabetes patients keep track of their blood glucose levels continuously, hence the name. The G6 makes 288 glucose level measurements per day -- or one every five minutes.

And since CGMs are associated with better health outcomes for diabetes patients, it isn't surprising that it keeps gaining new customers. DexCom's revenue jumped by 30% year over year to $650.2 million in the third quarter. In the press release announcing this quarterly update, DexCom said that "Volume growth in conjunction with strong new customer additions continues to be the primary driver of revenue growth as awareness of real-time CGM increases."

That's not a one-off: The company has generally recorded strong top-line growth thanks to the fact that CGM continues to win over diabetes patients. And there remains a long runway for growth. Many diabetes patients still rely on blood glucose meters (BGMs), despite their inferiority compared to CGM devices. The market in the U.S. remains severely underpenetrated. The market outside the U.S. shows an even more attractive opportunity since the U.S. is one of the world's leaders in CGM adoption.

Diabetes patient monitoring glucose levels while checking a mobile device.

Image source: Getty Images.

The number of people with diabetes will continue to increase, too, which will provide a long-term tailwind to DexCom's business. Naturally, there are risks to consider before investing in DexCom. The first is competition. Companies such as Abbott Laboratories and others are also looking to tap into this market. Another caveat worth mentioning is DexCom's valuation.

With a forward price-to-earnings ratio (P/E) of 201 as of this writing, DexCom looks expensive by any metric. However, neither of these risks warrants avoiding DexCom. There is more than enough space in the CGM market for multiple winners, and DexCom is already one of the leaders in the sector. Further, while DexCom's shares might be volatile in the short term due to its rich valuation metrics, the long-term opportunities it boasts are too juicy to pass up.

Stocks with significant growth potential often sport sky-high valuations. In the long run, I believe DexCom will justify these metrics by delivering market-beating returns, which makes the healthcare stock worth buying. 

2. Amazon

Amazon's shares have lagged the broader market this year. Here are two potential explanations for this somewhat surprising fact. First, the company's stock soared in 2020 as customers turned to e-commerce amid the worst of the pandemic and government-imposed lockdowns. Many so-called "pandemic stocks" have been significantly less successful on the market this year. Second, Amazon's iconic founder, Jeff Bezos, stepped down from his role as the company's CEO. Andy Jassy, the former CEO of Amazon Web Services, is the company's new CEO.

This transition happened in the third quarter. Bezos' decision to step down may have made some investors uneasy. After all, the company had not known any other CEO in its over 20-year history. But all these issues are mere background noise, in my view. There is too much going Amazon's way, and it will continue to deliver solid returns from here on out. Here is why.

The company boasts multiple competitive advantages. Its brand name, undoubtedly one of the most recognizable in the world, is a powerful intangible asset. Amazon's core e-commerce business benefits from the network effects: The more merchants join the platform, the more it attracts customers and vice versa. Amazon also offers lower prices on average than most of its e-commerce peers.

In addition to its leadership in the e-commerce industry, it also stands atop the cloud computing market. Both the e-commerce and cloud computing industries are still ripe for growth, and Amazon has plenty of cash on hand to invest in various ventures within these two sectors and others. The company ended Q3 with $29.9 billion in cash and cash equivalents.

That's not including Amazon's other segments that contribute to its financial results and add some diversity to its operations, such as its streaming service Prime Videos and its grocery business via Whole Foods. That's why, even with a forward P/E of 83.6, Amazon is well worth consideration. In my view, Amazon's business will continue to thrive for many years to come, despite a poor performance on the market in the 12 months.