Investing in the stock market requires patience. Even the best-performing stocks have down years.

Take e-commerce giant Amazon as the perfect example. Since the end of 2001, shares of Amazon are higher by nearly 32,000%. However, Amazon has ended five of the past 20 years lower, if we include its year-to-date return for 2021 as the 20th year. There's simply no such thing as a stock that goes up every year.

However, there are a handful of publicly traded companies that come awfully close. The following trio of stocks have delivered a positive annual total return -- including dividends paid -- in at least 18 of the past 20 years (i.e., since Dec. 31, 2001).

A dollar sign rising up from a financial newspaper that's displaying stock quotes and charts.

Image source: Getty Images.

Costco Wholesale: A positive total return in 18 of the past 20 years

The first stock that's been nearly automatic for investors over the past two decades is warehouse club Costco Wholesale (COST 1.00%). Costco's total return has been positive in 18 of the past 20 years, with the exceptions being 2002 and 2008. This means it's working on a 13-year winning streak in 2021, and it's delivered an aggregate total return of close to 1,400% over 20 years.

One of the biggest factors in Costco's success is the company's buying strategy. Costco is a large company with deep pockets. It purposely buys its goods in bulk to drive down the cost it pays for each unit. These cost-savings are then passed along to its members and used as an important dangling carrot to attract new customers.

Although groceries play a big role in bringing foot traffic to its warehouses, food isn't what'll drive margins higher. Costco also fills its stores with aisles of discretionary goods, ranging from clothes and electronics to jewelry and household items. By providing a wide array of goods for its members that are generally cheaper than they'd find in other brick-and-mortar retailers, Costco is counting on its shoppers to add higher-margin discretionary items to their carts.

It's also worth noting that Costco is a consumer staples stock. In other words, it sells basic need products that consumers purchase no matter how well or poorly the U.S. economy is performing. No matter how steep of a recession we go through, people still buy toothpaste, toilet paper, detergent, food, and a number of other goods that Costco carries. This means steady and predictable cash flow for Costco in virtually any economic environment.

The final catalyst for Costco is its membership-based model. Charging its customers an annual fee for access to its discounted items boosts brand loyalty. More importantly, the membership fees Costco collects help lift its razor-thin margins and ensures its warehouse club price advantage remains intact.

A physician using a stethoscope to listen to a child's lungs.

Image source: Getty Images.

UnitedHealth Group: A positive total return in 18 of the past 20 years

Another near-annual winner for investors is UnitedHealth Group (UNH 1.22%), the second-largest healthcare stock by market cap. Like Costco, UnitedHealth has generated a positive total return in 18 of the past 20 years for its shareholders, with 2006 and 2008 being the lone exceptions. In aggregate, UnitedHealth has delivered about a 2,750% total return since Dec. 31, 2001.

Most people are familiar with UnitedHealth because of its insurance offerings. Although this tends to be a relatively slow-growing segment, the beauty of health insurance is the strength of premium pricing power. Rarely has this company struggled to pass along higher premiums to businesses or individual members. This allows the insurance segment to stay ahead of the inflationary curve and generate predictable cash flow.

Something else to consider is the introduction of the Affordable Care Act (ACA) under former President Obama. Even though the ACA required insurers to provide coverage to all applicants, even those with preexisting conditions, it brought millions of new people, including generally healthy people, into the fold.

However, it's not the insurance segment that's propelling UnitedHealth to what looks like its 13th consecutive positive total annual return. The segment shining brightest for this company is healthcare services provider Optum.

Optum has three components, all of which are helping it grow significantly faster than UnitedHealth's insurance operations. This includes OptumRx, which provides pharmacy prescription refilling services, OptumInsight, which offers data analytics to healthcare organizations, and OptumHealth, which provides care through various medical groups. On top of growing at a considerably faster rate, Optum's operating margins should outpace UnitedHealth's insurance margins more quarters than not.

At the pace UnitedHealth Group has been growing, it wouldn't be a surprise if it surpassed Johnson & Johnson to become the largest healthcare stock in the United States.

An electrical tower next to three wind turbines at sunrise.

Image source: Getty Images.

NextEra Energy: A positive total return in 19 of the past 20 years

Last, but certainly not least, we have electric utility stock NextEra Energy (NEE 1.42%). NextEra, the largest utility stock by market cap, has generated a positive total return in 19 of the past 20 years, with the one exception being 2008. All told, NextEra's aggregate total return since Dec. 31, 2001, is approximately 2,080%.

The obvious reason NextEra has been such a steady performer is that it provides a basic need service: electricity. Demand for electricity and natural gas doesn't change much from one year to the next, which insulates the company from recessions.

But there's another reason NextEra Energy has been such a superstar: its focus on renewable energy. No utility in the country is generating more capacity from solar or wind power than NextEra. Although investments in clean energy can be expensive, they're also worthwhile. In addition to staying ahead of whatever green legislation could come out of Washington, NextEra's electric generation costs have been declining. This has helped push its growth rate to the high single digits for more than a decade. By comparison, most electric utilities have growth rates in the low single digits.

And the company isn't anywhere near done. Management anticipates spending an aggregate of $50 billion to $55 billion on new infrastructure projects between 2020 and 2022. With lending rates near historic lows, it makes sense now more than ever for the company to get aggressive with its green transformation.

To boot, the company also benefits from its regulated utility operations -- i.e., those not powered by renewable energy sources. You might think that having to seek approval from state public utility commissions to pass along rate hikes is a nuisance, but it ensures that NextEra isn't exposed to potentially volatile wholesale pricing.

Between its leading wind and solar capacity and its highly predictable cash flow, NextEra has been about as steady a performer as any stock could be for the past two decades.