A bear market -- defined as at least a 20% drop in the stock market -- is one of the most opportune times to invest for the long term. There was technically a bear market in 2020 because the S&P 500 declined about 34%. However, that particular bear market was abnormally short-lived. For perhaps a more normal bear market, let's rewind the clock to 2007.

In late 2007, the S&P 500 peaked. From there, prices started falling. And over the next 17 months, the market dropped by about 57%. Moreover, even though it recovered from the absolute low, the S&P 500 didn't hit new highs until the first half of 2013, more than five years later. In other words, bear markets can be pronounced and prolonged. But they can also be great times to put fear aside and invest.

If you invested $10,000 in an S&P 500 index fund in January 2009 -- not rock bottom but when the market was well below its highs -- you would have nearly $46,000 today. This clearly demonstrates the merits of bear-market investing.

^SPX Chart

^SPX data by YCharts.

However, if you invested $10,000 in individual stocks in January 2009, you potentially did far better than this. Many top stocks were on sale back then and have provided shareholders with sensational returns since.

As of this writing, the S&P 500 is only down 14% from its all-time high. But it's been over 15 months from its last high, showing that we are currently in a prolonged market downtrend. That's why I believe now could be a good time to invest, taking advantage of lower prices. And it's also why I want to share three stocks that I believe are trading at bargain prices for long-term investors.

1. PubMatic

Programmatic advertising-technology (adtech) company PubMatic (PUBM 0.32%) is forecasting a year-over-year revenue decline of 5% to 8% in the first quarter of 2023. The advertising market is particularly weak for digital-video content at the moment, which is PubMatic's core competency. This partly explains why the stock is down 70% from its all-time high.

The good news is that PubMatic isn't losing customers -- it was working with around 1,600 publishers in the third quarter of 2022 as well as the fourth quarter. Rather, the slowdown is due to macroeconomic weakness. And it's reasonable to assume this problem is temporary. Indeed, management expects the ad market to start rebounding in the second half of 2023.

In the meantime, PubMatic is cutting capital expenditures by about 50% year over year in 2023. And management expects ongoing profitability, which should increase its already strong cash position. It ended 2022 with $174 million in cash, cash equivalents, and marketable securities, with zero debt. 

For investors, PubMatic stock is quite cheap at just 28 times trailing earnings. That's a cheap enough valuation to reward shareholders once the ad market recovers. And it's possible management will take advantage of the relatively cheap stock with share repurchases in the coming year. It's authorized to repurchase $75 million, which is about 10% of its current market capitalization.

2. DigitalOcean

Cloud-computing company DigitalOcean (DOCN -0.04%) is one of my three favorite stocks right now because I believe it offers good value relative to its growth projections and its strengthening profitability.

DigitalOcean is going up against much bigger players in the cloud computing space. And yet management doesn't seem too concerned about competition. To the contrary, it expects to go from $576 million in revenue in 2022 to $1 billion in 2025.

Some investors might think that's overly ambitious. After all, DigitalOcean already has 677,000 customers. How many more potential customers can the company attract to grow revenue by that much?

While its customer base is already large, there's an important nuance here. As of December, just 2% of the company's customers accounted for 55% of its revenue. And just 21% of customers accounted for 85% of revenue. In other words, it wouldn't take many customers for DigitalOcean to hit it's big revenue goal -- it's very attainable.

Through disciplined management, DigitalOcean's free-cash-flow margin is climbing higher. Its 13% margin in 2022 is expected to surpass 30% in the next few years. If it hits its goal, it would generate $300 million in free cash flow in 2025.

If the stock traded at a reasonable 20 times its potential free cash flow in 2025, DigitalOcean would have a market cap of $6 billion -- 71% higher than its valuation now. In my opinion, that would easily be enough to outperform the S&P 500.

Two people in white lab coats working at a computer.

Image source: Getty Images

3. Lam Research

Lam Research (LRCX -0.77%) and Applied Materials are direct competitors in the semiconductor space, building equipment used in manufacturing. I'm not a semiconductor expert and I consequently don't have an opinion on which is the better company.

In reality, both companies have provided investors with market-crushing returns over the last decade. And given the importance of the semiconductor industry, I believe it's possible for both to outperform over the coming decade as well.

However, I'd pick Lam Research over Applied Materials today because it's the better value. It trades at a lower price-to-earnings (P/E) valuation, it has reduced its share count more over the past five years, and its dividend yields 1.3%, whereas Applied Material's is below 1%.

AMAT PE Ratio Chart

AMAT PE ratio data by YCharts

At just 13 times trailing earnings, Lam Research stock trades at a substantial discount to its nine-year average of 18 times earnings. And it's trading at a discount because the spending for wafer fabrication equipment is expected to drop more than 20% year over year in 2023. Therefore, its revenue growth could also be challenged.

Investors worried about 2023 are being shortsighted, in my opinion. Cyclicality is normal in this industry, and this has happened to Lam Research in the past.

Moreover, spending is expected to rebound sharply in 2024 and grow in the coming decade, meaning Lam is still a great company to invest in for the long haul. And near-term concerns allow investors to pick up shares today at bargain prices.

Investing in PubMatic, DigitalOcean, and Lam Research is a personal decision, as is the decision regarding how much to invest in each. But I believe all three will outperform the S&P 500 over the next five years, making them great bear-market bargains.

Whatever you decide, don't forget that it's important to build a diversified portfolio of at least 25 stocks -- don't bet the farm on just three, even if their prospects look great.