The market has been moving in and out of bear territory over the past few months as investors assess conflicting signs about how the economy is doing. Inflation is still high, and many consumer goods companies have been raising prices to offset costs. It's not surprising that the market is declining under these conditions.

As a result, many excellent stocks have been tripped up by the shifting economic trends. But over time, they will come back. Amazon (AMZN -1.64%), Costco Wholesale (COST -0.22%), and Target (TGT -1.43%) are great companies that have beaten the market over time. So if you have $5,000 after paying off debts and setting aside an emergency fund, you should consider adding these stocks to your portfolio.

There's almost no end to what Amazon can do

Amazon continues to dominate e-commerce domestically and expand its reach abroad. But although e-commerce remains its best-known business, its other businesses are growing at a fast clip. In a few years, the company may look very different from today.

Amazon Web Services (AWS), which offers cloud services, is churning out high growth despite the general economic slowdown. It has been Amazon's growth engine while retail decelerates amid inflation and supply chain problems. 

Amazon has been acquiring businesses almost as long as it's been in operation, but it has accelerated buyouts recently, and in somewhat of a departure from the norm, these acquisitions are for the most part not related to its core retail business.

Its biggest-ever acquisition was Whole Foods in 2017, but its next-biggest acquisitions were MGM Studios in May for $8.5 billion and 1Life Healthcare, known as One Medical, for $3.9 billion in July. These both went through at a time when retail was tapering off after soaring growth through the beginning of the pandemic, and they represent a push into new areas of business -- specifically, streaming and healthcare.

Amazon has offered streaming for many years under the Prime banner, including original content. The MGM acquisition keeps it in the big leagues at a time when competition is intensifying. The One Medical purchase is much further afield. Amazon is overhauling its healthcare services, and this is a springboard for greater innovation. 

Amazon has beat the market over many years, and although it's underperforming in 2022, it has tons of potential to beat the market again -- for many years to come.

Dirt cheap prices breed customer loyalty

Costco is the only stock on this list that's beating the market this year, although it's also down.

^SPX Chart

^SPX data by YCharts

It continues to post elevated sales growth as customers turn to its warehouses for the best prices available when inflation makes every penny count.

Sales increased 15% year over year in the fiscal 2022 fourth quarter (ended Aug. 28). The mid to high-teens sales growth has started to moderate as inflation's grip on retail has become stronger, and the 2023 first quarter may look different. But growth remains robust.

Costco's fee-based model allows it to charge dirt-cheap prices while still generating lots of cash. Beyond its price points, which drive volume and comps growth, Costco still has enormous growth potential with opening new warehouses. It operates 839 global warehouses, with 578 in the U.S. It typically opens around 25 stores annually, which is a slow pace as compared with other retailers. That keeps the growth runway nice and long. 

Costco stock has generated high gains for investors over many years. Not only is it beating the market this year, but it's the highest gainer on this list over the past five years. Investors should expect that continue.

^SPX Chart

^SPX data by YCharts

The hybrid omnichannel champion

At some level, Target is the hybrid Amazon and Costco model, and carving out that niche has brought it tremendous success. It operates a discount model, and with more than 1,900 stores, it's a fairly ubiquitous presence across the country. These stores are carefully designed to fit the needs of specific communities, so instead of a one-size-fits-all model, it works with several models that enable it to service many different areas.

Shortly before the pandemic, the retailer revamped its business to include a robust array of omnichannel services and so it was well-positioned to deliver -- both literally and figuratively. Its same-day services were a lifeline for many customers, and Target posted some of the highest sales growth of any large retailer, driven by these services.

It's worth noting that more than 95% of digital orders are delivered from stores. That means orders are shipped faster and cheaper than they would if they came from distribution centers. It also means that even with elevated inventory levels, Target is not stuck with expanded warehouses, as are many other retailers who invested to meet high demand.

So although it's going through a bit of a rough patch, having been left with too much inventory as inflation soared and people stopped spending on expensive items, it retains its strong infrastructure and should see good times again. Target stock has beaten the market over time, and it's a great stock to buy before a market recovery.