The broader stock market has enjoyed a rosy first half of 2023, a far cry from the turmoil investors experienced last year. While the market's upward run might mean a correction is coming at some point, there are always opportunities on Wall Street if you look in the right spots.

For example, two household technology names recently enjoyed remarkable stock moves. Amazon (AMZN -0.09%) is up 60% since January, while social media conglomerate Meta Platforms (META 0.11%) has climbed a whopping 156% over the same time.

It might seem like you're chasing momentum when looking at these stocks, but the data shows that long-term investors have plenty of room to buy, hold, and still enjoy solid investment returns over the coming years.

Here is what you need to know.

Value is in the eye of the beholder

Typically, investors will value a company by looking at what it trades for versus the earnings the business generates. But Amazon has continually invested its profits back into the business instead of retaining them as bottom-line earnings (net income). Founder Jeff Bezos has referred to Amazon as being "famously unprofitable."

So to value the stock, consider looking at Amazon's profits before it starts reinvesting all that money: its operating cash flow. You can see in the chart below that operating cash profits have soared over the past decade. A multibillion-dollar investment in electric-vehicle manufacturer Rivian ultimately tanked profits in 2022, but you can see that operating cash flow is back on a long-term upward trend.

AMZN Price to CFO Per Share (TTM) Chart

AMZN price to CFO per share (TTM) data by YCharts. TTM = trailing 12 months.

Today, Amazon trades at 25 times its operating profits, which is still below its average over the past 10 years, despite the stock's big run. In other words, the stock was extremely cheap before its run, and now it's closer to its historical norms. There's nothing wrong with buying a quality company like Amazon at a fair price.

Besides, the company should continue growing. It recently announced record-level sales for its summer Prime Day event. Analysts are also optimistic, projecting earnings-per-share (EPS) growth averaging 33% annually over the next three to five years. Investors might have missed the recent gains, but more could be coming over the next several years.

The potential comeback story of 2023

It wasn't even a year ago that Wall Street declared Meta Platforms dead as an investment. The company was losing billions on its Reality Labs segment (and still is), and a soft advertising market painted a picture that Meta's growth days were behind it.

Below, you can see how pessimistic industry analysts became, forecasting almost zero earnings growth. But that abruptly changed in 2023: Long-term estimates exploded to nearly 20% annual earnings growth.

So what happened? CEO Mark Zuckerberg made several rounds of aggressive layoffs and budget cuts to help make the company lean again. It has had multiple product announcements, including a new Meta headset coming this fall, the Quest Pro 3.

And Meta launched Threads, a Twitter-like text-based app that has replaced ChatGPT as the world's fastest-growing app, with more than 100 million users added in a matter of days.

META EPS LT Growth Estimates Chart

META EPS LT growth estimates data by YCharts. LT = long term.

The newfound efficiency and hot growth prospects reversed investors' sentiment, sending shares soaring. Fortunately, the stock remains attractively priced despite a triple-digit gain in 2023. The company trades at a forward P/E of 26, and analysts believe the business can grow earnings by 20% annually.

That's a price/earnings-to-growth (PEG) ratio of just 1.3, which could be a great deal considering how powerful Meta's competitive advantage is in social media and its strong profit margins (a quarter of its revenue ends up as free cash flow).

Again, both companies have run up considerably from lows, so there could easily be a correction of some kind. But the goal isn't to guess what a stock might do on any given day. Instead, long-term investing is about finding companies that could be worth much more in five years than they are today. It seems that both Amazon and Meta Platforms fit the description.