Amazon (AMZN -0.41%) and Apple (AAPL 1.61%) are two of the most closely followed stocks, and among the world's five most valuable companies by market cap. These tech giants rule their respective industries, with one dominating e-commerce and the other leading consumer tech. As a result, their stocks still have much to offer new investors over the long term and could be some of the smartest buys right now.

Macroeconomic headwinds over the last two years have challenged countless companies. Reductions in consumer discretionary spending led to steep declines in Amazon's retail profits in 2022. Meanwhile, Apple has experienced repeated dips in product revenue. However, economic hurdles won't last forever, and these companies are well positioned to profit substantially from a market recovery.

So, let's examine whether Amazon or Apple is the better buy this month.

The case for Amazon

In fiscal 2022, Amazon posted operating losses of $10.6 billion between its two e-commerce segments. The company remained profitable thanks to its lucrative cloud business, Amazon Web Services (AWS). However, the e-commerce declines led management to rethink its business model and introduce various cost-cutting measures, closing dozens of warehouses, sunsetting unprofitable projects, and laying off thousands of people.

The restructuring paid off as Amazon's retail business returned to profitability this year. Its North American segment hit over $4 billion in operating income in the third quarter, compared to the $412 million in losses it reported the year before.

In addition to e-commerce growth, Amazon is steadily expanding in artificial intelligence (AI), a market that has blown up in 2023. The company has added several new AI tools to AWS as it works to meet soaring demand for such services. AWS has solid prospects in this high-growth space with its leading market share and a long list of prominent clients that includes Netflix, Sony, and Meta.

Amazon shares have soared 70% year to date as Wall Street has recognized the improvements in its retail business and its growing prospects in AI. The company is on a promising growth trajectory that could be worth an investment.

The case for Apple

Apple hasn't had it as easy as Amazon this year. Its revenues have tumbled 3% year over year in fiscal 2023 as each of its four product segments reported declining sales. The company has continued to experience pullbacks from consumers due to inflation and higher interest rates. Yet despite those recent challenges, Apple shares have risen 42% year to date.

AAPL Chart

Data by YCharts.

Apple has a long history of providing investors with consistent gains. The chart above shows its shares have outperformed some of its biggest competitors over the last five years, among them Microsoft, Alphabet, and Amazon. While past growth isn't always indicative of what is to come, Apple is making moves to keep its business expanding over the long term.

The company is home to a highly profitable services business, which includes the App Store and subscription platforms like Apple TV+, Apple Music, and more. The digital business boasts profit margins of 70%, significantly higher than its margin for products, which hovers around 36%. Indeed, services may be on track to eventually surpass the iPhone as Apple's highest-earning segment, as revenue growth has hit 9% in 2023 compared to the iPhone's decline of 2%.

Apple is gradually shifting its business to more digital markets that are less vulnerable to economic fluctuations. It's also expanding into AI and has reportedly developed its own version of OpenAI's ChatGPT. The company has excellent prospects over the long term, and its stock looks like an attractive buy for patient investors.

Is Amazon or Apple stock the better buy?

Amazon and Apple are two compelling investments with excellent prospects over the next decade. However, Amazon's meteoric stock rise this year has made it significantly more expensive than Apple. The chart below compares the companies' price-to-earnings and price-to-free-cash-flow ratios. Apple comes out on top for both metrics. The figures indicate that Apple's stock offers far more value right now.

AMZN PE Ratio Chart

Data by YCharts.

Moreover, despite recent declines, the iPhone company brought in more than $99 billion in free cash flow in its latest quarter compared to Amazon's free cash flow of $17 billion. Apple's business is on better footing financially, making it a more reliable investment.

Furthermore, Apple shares have dipped 5% since the end of July, which has only made its stock more attractive. Now would be an excellent time to make a long-term investment in the MacBook company. However, it would still be smart to keep Amazon on your radar in case its stock dips to a more attractive valuation.