Shares of Apple (AAPL -0.35%) rose 48.2% in 2023, according to data from S&P Global Market Intelligence. The stock climbed last year thanks to a combination of strong operational performance and swelling investor optimism.

Investors aggressively bought shares in reliable, high-quality businesses last year, especially if they provided some upside potential relative to mature value stocks. Apple's ability to navigate a challenging macroeconomic environment created surging investor confidence, and the stock benefited as a result.

A couple sitting on a couch while one person wears a virtual realty headset and holds a game controller.

Image source: Getty Images

Strong earnings and favorable market conditions

Apple was one of many tech companies that delivered strong cash flow despite experiencing slowing sales over the past two years. Its revenue fell nearly 3% for the fiscal year that ended in September, though it saw acceleration in the most recent quarter to 13% growth. Consumers are struggling with high inflation, a difficult job market, and high interest rates on debt, all of which are bad news for businesses selling big-ticket consumer products.

Apple impressed investors with its work on the expense front. The company delivered cuts to the cost of goods sold and selling, general, and administrative expenses. Importantly, its declining product sales were partially offset by higher-margin service revenue, which is associated with App Store fees and content streaming fees.

These factors, along with ongoing share repurchases, meant that Apple's earnings per share (EPS) increased, despite the top-line weakness. The company reported better-than-expected earnings in three of last year's quarterly reports.

Apple has firmly established itself as a reliable cash flow producer that can survive lean times and thrive during cyclical expansions.

AAPL Revenue (TTM) Chart

AAPL Revenue (TTM) data by YCharts

Market forces played a major role in Apple's success last year. Its price chart was remarkably similar to that of the Invesco QQQ Trust (QQQ 1.54%), an exchange-traded fund that tracks the Nasdaq index and is heavily exposed to large-cap tech stocks. The high level of correlation suggests that Apple shared key drivers with its sector peers.

AAPL Total Return Level Chart

AAPL Total Return Level data by YCharts

Apple's valuations ratios also support that conclusion. The stock's forward price-to-earnings (P/E) ratio climbed more than 35% during the year to 29. Investors were willing to pay a larger premium relative to short-term results. That indicates more optimism about Apple's prospects and higher investor risk tolerance overall.

AAPL PE Ratio (Forward) Chart

AAPL PE Ratio (Forward) data by YCharts

Apple clearly owes much of its recent returns to market sentiment rather than to anything company-specific.

What's next for Apple

Apple's forward P/E ratio is approaching 30 right now, which might look a bit rich for investors. At this valuation, smaller growth stocks are likely to outpace Apple if there's a bull market around the corner. It's also expensive enough to suffer drawdowns if macroeconomic conditions deteriorate.

The long-term narrative for Apple rests on its stellar performance as a cash flow generator along with its significant investment in disruptive technologies. The company is aiming to become a leader in virtual reality and artificial intelligence products. If it successfully establishes itself in these emerging industries, then strong financial results are likely to propel more shareholder gains in the future.