It's been a brutal few weeks for investors. The longest bull market in history has come to a screeching halt -- and many investors' portfolios have been rocked. As of this writing, the market has officially slipped into bear-market territory, meaning it has declined 20% from recent highs.

What should investors do? It may be time to go on a shopping spree. While fear may be the prevailing sentiment in the market today, times like these present lucrative opportunities for investors willing to be "greedy while others are fearful," as famed investor Warren Buffett has said.

Sure, there's a chance we haven't yet reached the bottom of this market downturn. Trying to time the market, however, is a fool's errand. It is nearly impossible to know when fear will subside and be replaced with greed. There are simply too many dynamics at play, including unpredictable factors like human emotion and herd-like behavior.

With this backdrop in mind, here are three high-quality stocks that appear oversold amid this market turmoil. All three of these businesses have balance sheets to weather economic challenges and look poised to thrive over the long haul. Yet their shares have plummeted in recent weeks, giving investors compelling buying opportunities.

A chart showing a stock price crashing

Image source: Getty Images.

1. Berkshire Hathaway

One company that can not only survive but even benefit from a stock market sell-off is Warren Buffett's Berkshire Hathaway (BRK.B -1.94%) (BRK.A -2.16%). Sure, Berkshire's stock itself isn't exempt from getting slammed along with the broader market during a market crash. Even more, its insurance operations, subsidiaries, and equity holdings can similarly be negatively impacted by macroeconomic headwinds. But here's where it gets particularly exciting: As of Berkshire Hathaway's most recent financial update, the company boasted cash, cash equivalents, and U.S. Treasury Bills totaling $125 billion. This is some serious money in the hands of one of the greatest capital allocators in the world. You can bet Buffett, Munger, and his investment lieutenants are scouring the market closely for attractive investment opportunities during this downturn.

The Oracle of Omaha could use Berkshire's cash hoard to make large, lucrative bets like his $44 billion acquisition of Burlington Northern Santa Fe Railroad in 2009, when railroads were out of favor with the Street. Or he could turn to the stock market and buy a massive stake in an undervalued company, just as he did with Apple (AAPL -0.74%) -- a position Berkshire largely accumulated throughout 2017 and into the beginning of 2018, when shares were trading between about $120 and $170 (compared to about $280 today). It also wouldn't be surprising to see Berkshire ramp up repurchases of its own stock, boosting per-share intrinsic value for shareholders; it's the company's policy to be more aggressive with share repurchases when Buffett and his partner Charlie Munger believe shares are trading at a discount to their intrinsic value.

Of course, there's no guarantee that any investment Berkshire makes during this market downturn will turn out well. But Berkshire does have quite a good track record of building shareholder value by allocating capital opportunistically. That's why shares have compounded at an average rate of 20% annually since 1965 -- a period the S&P 500 has appreciated just 10% annually. 

Amid this coronavirus panic, Berkshire stock has slid 14%, giving investors a great opportunity to potentially take part in Buffett's next big elephant-gun bet and to buy into a collection of high-quality assets under Berkshire's ownership.

2. Apple

Apple is another company with a war chest large enough to handle just about anything thrown at it. Net of its low-interest debt, the tech giant wrapped up its most recent quarter with net cash of $99 billion. While Apple will almost certainly see a sales slump due to production challenges and store closures related to the coronavirus, the tech stock's 14% decline since February 19 has already priced in these headwinds.

Further, the iPhone maker has actually built a formidable business that isn't highly dependent on product sales: services. This segment will help offset any hit Apple's hardware business takes as a result of the coronavirus outbreak. Including revenue from the App Store, Apple Music, Apple Pay, iCloud, AppleCare, Apple TV+, and other services, Apple's services segment now accounts for about 18% of total revenue and 30% of gross profit. 

In addition, this segment is growing rapidly. In Apple's most recent quarter, services revenue increased 17% year over year, driven by double-digit growth in all five of its geographic segments and record performance in cloud services, music, payments, the App Store, and Apple Care. One catalyst for the segment worth calling out is its growth in subscriptions across its own native apps and third-party apps. Apple's paid subscriptions totaled 480 million at the end of its first quarter of fiscal 2020, up 33% year over year.

Importantly, this services business is supported by an installed base of 1.5 billion active devices (up 100 million from the year-ago quarter) -- and these users will continue to spend money on services amid the coronavirus outbreak.

3. The Trade Desk

Finally, there's The Trade Desk (TTD 0.92%). Though the fast-growing digital ad-buying specialist is much smaller than Berkshire Hathaway and Apple, investors shouldn't underestimate its financial health, resilient business model, and promising growth prospects.

As of the end of 2019, The Trade Desk had $255 million of cash and short-term investments and no debt. This is a large amount for a company with $661 million in total revenue in 2019. Further, it gives The Trade Desk great optionality and flexibility considering that there's no reason for the tech company to rely on this cash for regular operations; the company is free cash flow positive and its net income is rising rapidly, growing from $88 million in 2018 to $108 million in 2019. Adjusted earnings before interest, taxes, depreciation, and amortization (EBITDA) in 2019 was $214 million, up from $159 million in 2018. 

Better yet, in its Feb. 27 fourth-quarter earnings call, management was confident about its growth prospects even in the face of growing coronavirus fears. The Trade Desk guided for ad spend on its platform to grow nearly 36% year over year in 2020 -- an acceleration from 33% growth in 2019. Further, management said it expected revenue to increase 40% year over year in Q1 -- an acceleration from 35% growth in Q4.

The Trade Desk CEO Jeff Green even said in a Feb. 27 interview with CNBC Mad Money's Jim Cramer that marketers continued to advertise "as aggressively as they ever have" amid the coronavirus scare. He added that a trend of more people staying at home could increase media consumption, ultimately benefiting The Trade Desk. Even more notable, however, was Green's stance on how advertiser spend could actually shift toward data-driven programmatic advertising -- The Trade Desk's specialty -- if there is weakness in consumer sentiment since advertisers will be "way more deliberate about where they spend..." Green went as far as to say that "in all scenarios, data-driven advertising -- I think -- is in a very good position." 

Shares of The Trade Desk have been hit particularly hard during this market sell-off. Since Feb. 19, shares are down 37%. Of course, the stock still isn't cheap. Shares trade at 88 times earnings. But with ad spend growth likely to accelerate in 2020, this is a great opportunity to get in on the leading programmatic advertising platform while it's still in its early innings.

Of course, all three of these stocks could continue to fall further before recovering. But investors should think twice before they try to time the market. The S&P 500 has only fallen 20% or more from recent highs an average of approximately once every six years since 1926. Opportunities like this aren't common. This is a great opportunity to buy three high-quality stocks that will likely perform very well over the next five years and beyond.

Editor's note: This article has been corrected to state that Apple's paid subscriptions totaled 480 million at the end of its first quarter of fiscal 2020, up 33% year over year.