History has shown that, given enough time, the stock market always broadly trends toward new highs. That's an important lesson to remember in a year like this where all the major U.S. indexes, from the S&P 500 to the Nasdaq-100, dipped into bear market territory. 

Soaring inflation and rising interest rates were the key drivers of this latest decline, as traders worried about whether consumers would have less spending power and impact many businesses' financial performance. The market downturn is unlikely to end until those worries ease. There are some early signs that inflation has peaked, which might be the first step in unleashing the next bull market.

Two of the highest-quality stocks investors can own are Microsoft (MSFT 1.65%) and Apple (AAPL 0.64%). Given both stocks are trading down by more than 20% this year, a buying opportunity before an inevitable market recovery now presents itself. 

1. Microsoft's diversity makes it the ideal all-weather stock

One of the best attributes a company can have during tough economic times is a diverse revenue base because some industries simply hold up better than others. Revenue streams reliant on consumer spending, for example, are suffering the most right now and Microsoft is right there with them. But many businesses continue to invest in new technologies like cloud computing, where Microsoft is a major player. 

This year, Microsoft saw a decline in revenue and engagement in its Xbox gaming ecosystem, as well as falling sales for its Surface line of notebook computers and devices. Plus, the U.S. Federal Trade Commission is seeking to block Microsoft's blockbuster $69 billion acquisition of game development studio Activision Blizzard. The deal would open the door to new opportunities for the Xbox platform, but the government is concerned it will harm the competitive landscape in the gaming industry by making Microsoft too dominant. 

This is precisely why operational diversity is so valuable. Despite these challenges, Microsoft's intelligent cloud segment, which is home to the Azure cloud services platform, continues to grow rapidly. Azure ranks behind only Amazon Web Services in the cloud industry and provides hundreds of products and solutions to help businesses migrate their operations online. Whether they require simple data storage or complex artificial intelligence-powered tools, Azure has them covered.

The platform's revenue jumped by 35% year over year in the recent first quarter of fiscal 2023 (ended Sept. 30), which was three times the rate of Microsoft's companywide revenue growth of 11%. That outperformance has been a consistent trend over the last few years, and it's why Microsoft CEO Satya Nadella wants to prioritize areas of the business that will benefit most from the move toward digital technology. 

After all, according to an estimate by Grand View Research, the cloud stands to become a $1.5 trillion annual opportunity by 2030. With Microsoft stock down 27.4% in 2022, this could be a rare opportunity to buy in at a steep discount. 

2. Apple is a great way to bet on a consumer comeback

While consumers are suffering the most from soaring inflation, it means they also stand to be the greatest beneficiaries when prices cool off. Apple is a quintessential consumer products company, and, therefore, it stands to reason that the company could be one of the first to bounce back under those circumstances. 

Still, even in light of the broader economic weakness, Apple has continued to generate growth. Its revenue expanded by 7.8% year over year during fiscal 2022 (ended Sept. 24), which was buoyed by a strong fourth quarter following the release of a series of new products in early September.

The company unveiled its new flagship iPhone 14, its next-generation AirPods headphones, and its Apple Watch Ultra. But the Mac brand delivered the most positive result in Q4, with sales jumping a whopping 25% year over year.

These products should give Apple's financials a boost in the important holiday season.

But in the longer run, investors continue to watch the company's services segment closely. It's home to all of Apple's subscription-based products like Apple Music, Apple News, Apple TV, and Apple Pay, which is going after a global payments industry that could be worth almost $20 trillion by 2026. The services business grew by 14.1% during fiscal 2022, more than double the pace of the products business, which expanded by 6.3%.

Services make up just one-fifth of Apple's total revenue, though, so why are investors so focused on them? It's because they carry a gross profit margin of 71%, which is substantially higher than the 36% of Apple's hardware business. They also provide predictable, recurring revenue streams, which consumers are less likely to put off compared to, say, upgrading their expensive iPhone. 

Apple stock is down 24.6% year to date, and while that's a notable decline, it's faring better than other consumer-focused companies like Amazon, which has lost 48% of its value in the same time frame.

Apple remains the largest listed company in the U.S., with a market valuation of $2.1 trillion, and discounts of this magnitude are relatively rare. That spells opportunity for investors ahead of the next inevitable bull market.