Apple (AAPL 1.35%) made headlines this week by surpassing a market capitalization of $3 trillion, a level it hadn't seen since August. The company's shares are up 50% year to date, despite repeated declines in its product segments that sent revenue dipping 3% year over year in its fiscal 2023.

Macroeconomic headwinds caught up with Apple over the past 12 months, curbing consumer spending and creating weakness in foreign currencies relative to the U.S. dollar. Yet, its stock and business have remained resilient as loyal investors have continued to believe in its long-term prospects, and its heaps of cash have kept the company expanding.

The stock might be slightly overpriced today, trading at 31 times its earnings, but here's why Apple is still a buy.

A powerful position in tech that is unlikely to dissipate soon

Apple has built brand loyalty that is almost unmatched in tech. Its interconnected ecosystem of products simultaneously deters people from using competing devices and encourages users to gradually branch out into Apple's other offerings.

The popularity of Apple's products has seen it attain leading market shares in multiple industries, holding a 55% share of the U.S. smartphone market.

The company's significant user base came in handy in 2023 as spikes in inflation made people less likely to upgrade their devices. Product revenue faltered, but Apple continued to profit from the sales of past devices through its services.

The tech giant's services business includes income from the App Store and subscription-based platforms like Apple TV+, Music, and iCloud. The digital division has become the fastest-growing part of Apple's business, with revenue rising 9% year over year in fiscal 2023 and outpacing the iPhone for two consecutive years.

Consistent growth from services is positive for Apple's long-term prospects, with profit margins regularly hitting about 70%. By comparison, its products' profit margins hover around 36%.

Apple's potent brand has seen it achieve dominating roles in nearly every new market it has entered. In 2024, the company will launch its first virtual/augmented reality (VR/AR) headset and will likely continue expanding into artificial intelligence (AI). With billions of users worldwide and a free cash flow that hit nearly $100 billion this year, I wouldn't count it out as becoming a top performer in either of those high-growth sectors.

Has Apple earned its premium price tag?

Apple's substantial stock rise this year has made it slightly overpriced. Its forward price-to-earnings ratio (P/E) of 30 and price-to-free cash flow multiple of 31 are high, considering that anything below 10 to 20 for both metrics is generally regarded as a good value.

However, this is Apple, the world's most valuable company that has delivered stock growth of 345% over the last five years. Even if its shares rose half that over the next five years, it would still outperform Alphabet's and Amazon's stock gains since 2018. So, the question remains: Is Apple worth its high valuation?

AMZN PE Ratio (Forward) Chart

Data by YCharts

The charts above compare the forward P/E and price-to-free cash flows of some of the biggest names in tech. The figures indicate that shares in Apple are trading at a better value than Amazon, Nvidia, and Microsoft, with only Alphabet potentially a better bargain.

Apple's reputation for reliable gains, loyal user base, and substantial cash reserves make the company a no-brainer for investing in tech. It's one of the cheapest options in the industry and has delivered more five-year growth than most of these companies. Even if it can't replicate the same growth over the next half-decade, the company's share price is still likely to rise significantly with its lucrative services business and expansions into other areas of tech.

The company has earned its high valuation and remains a buy right now.