While the S&P 500 has mostly recovered from its drop earlier this year, most analysts have adjusted their earnings expectations lower due to rising trade tensions and economic uncertainty. As a result, many stocks still look expensive in today's market.

Finding a bargain among them sometimes requires looking at stocks beaten down in recent months. Short-term challenges can often create great opportunities for long-term investors.

And even if you miss the exact rock-bottom price on a stock, you'll have plenty of opportunities to buy shares. The phrase "The markets take the stairs up and the elevator down" can work in your favor here, giving you time to assess a company's recovery from any setbacks.

One such stock worth examining more closely is The Trade Desk (TTD -2.47%). It fell over 67% from its all-time high reached at the end of last year. You could still buy shares for about half of that peak as of June 9. Here's why you don't want to miss this incredible opportunity.

A person holding a phone displaying a stock trading app.

Image source: Getty Images.

Why The Trade Desk's stock took the elevator down

About two years ago, The Trade Desk announced a new artificial intelligence (AI) platform, Kokai, for buying ads. It was designed to help marketers optimize bid prices for ads, improve targeting and measurement, and generally make the most of their advertising budgets.

Management is constantly adding new features to the platform as well. The more it can improve advertisers' results, the more business it is positioned to win.

The push to transition customers from its legacy platform to Kokai went slowly, ultimately leading to a major shake-up in the company's personnel and operations in the fourth quarter. Operational struggles combined with challenges related to Kokai led to the first earnings report where the company missed its own internal revenue forecast since going public in 2016.

The massive earnings miss led to a big sell-off in the stock. That was compounded as the Trump administration enacted new tariffs. The growing economic uncertainty caused by tariffs led many to expect businesses to pull back on advertising, which directly weighed on The Trade Desk.

Management outlined 15 factors that give it long-term confidence in the business, including internal factors like simplifying its platform, investing in AI, and completing the customer transition to Kokai.

That transition took a major step forward in the first quarter after the company simplified the user experience based on feedback. Management said it was ahead of schedule on its plans to transition 100% of customers to the platform, with two-thirds using it as of early May.

The strong first-quarter results and the good news on Kokai led to a sharp recovery in the stock price, but investors still have an opportunity to buy. The long-term potential of The Trade Desk is massive.

The Trade Desk is taking more of a growing market

Marketers will spend nearly $800 billion on digital advertising this year, according to a forecast from online shipping company Oberlo. That market will climb past $1 trillion by the end of the decade. Just a few names like Alphabet's (GOOG -1.11%) (GOOGL -1.03%) Google, Meta Platforms, and Amazon account for the bulk of digital ad spending.

The Trade Desk offers marketers an alternative to the so-called "walled gardens" by remaining platform agnostic and placing ads across media wherever they can perform best. As a result, it has managed to consistently gain market share over time, but it still accounts for a tiny percentage of that $800 billion in digital ad spending. Customers spent just $12 billion on its platform last year.

Since Google, Meta, and Amazon are, for the most part, selling their own inventory directly to marketers, they can offer better pricing. But The Trade Desk offers greater flexibility to advertisers. As such, it should be able to continue taking market share for the foreseeable future, but it probably won't ever grow to the size of the big three without cheap access to inventory.

To that end, it has introduced OpenPath, which cuts out middlemen, as publishers work directly with The Trade Desk to fill inventory. It also introduced a connected-TV operating system, Ventura streaming TV OS, which would provide more ad inventory for The Trade Desk to sell directly.

With Google facing regulatory challenges in court, it may have to divest certain properties or change policies. For example, Google's advertising exchange granted a first look to bids from Google Ad Manager, which can limit competition for ad inventory. If it has to change that, it could open the door for The Trade Desk to win more bids on the exchange, further increasing its market share.

Is The Trade Desk's valuation reasonable?

Despite the drop in price, the stock trades for a premium valuation. Its enterprise value is nearly 30 times its forward expectations for earnings before interest, taxes, depreciation, and amortization (EBITDA). But strong revenue growth combined with the potential margin gains from OpenPath and Ventura OS could lead to even better earnings growth over the next few years, making the price reasonable.

It also faces less downside risk from regulators compared to its bigger competition. As a result, the current price still looks like a great opportunity for investors to buy The Trade Desk while the stock remains well below its recent highs.