A stock's valuation not only reflects its growth outlook, but also risks. After all, many consumer staples and utilities stocks don't feature much growth, but still trade at price-to-earnings (P/E) ratios in the 20s or even 30s, due to their low-risk and recession-resistant businesses.

One may be able to trace Apple's (AAPL -1.04%) terrific stock performance over the past few years to this dynamic of greater perceived safety, rather than mere growth -- although growth has been solid, too. The stock's gains have outpaced both revenue and earnings-per-share (EPS) growth, as Apple's P/E ratio has expanded significantly.

AAPL Chart

AAPL data by YCharts. TTM = training 12 months.

While part of the rise is no doubt due to an improved growth outlook, because of the coming 5G cycle as well as the growth of new services such as Apple TV+, at least some of the rise is also due to the change in the perception of Apple's safety.

Moody's lifts Apple's rating to a level enjoyed by only two other companies

On Dec. 21, Moody's (MCO -0.19%) upgraded Apple to its highest rating, AAA. After the upgrade, it is one of only three companies to enjoy that ultra-elite status, along with Microsoft (MSFT 0.92%) and Johnson & Johnson (JNJ 0.66%).

The honor is quite a change from just five years ago, when Apple was regarded by many as nothing more than a cyclical device maker, rather than a sticky brand ecosystem with highly loyal customers and an emerging recurring-services division.

Of course, Warren Buffett (who also owns Moody's stock, coincidentally) was smart enough to see Apple differently, and began buying the stock back in 2016, with a current split-adjusted average cost basis of $34.25, compared with a price around $178 today.

In the upgrade, Moody's analyst Raj Joshi said, "Apple's very strong business profile reflects its substantial operating scale, a large installed base of products and users of its services, strong customer loyalty, and premium brand positioning."

The note also praised Apple's balance sheet and other resilient attributes, with Joshi elaborating that Apple has "an exceptionally strong liquidity profile over the next three to five years." That liquidity should come from 5G-fueled earnings, bolstering Apple's balance sheet, which already boasts $190.5 billion in cash and equivalents, against just $124.7 billion in debt.

Middle aged woman smiles at her phone at kitchen table with coffee.

Apple's debt and equity were both recently upgraded. Image source: Getty Images.

Apple was recently upgraded by stock analysts, too

While the Moody's upgrade reflects a better view of Apple's safety profile, the company also received a positive note from equity analysts at Bank of America (BAC -1.25%) (another Warren Buffett holding!) on Dec. 14. Analyst Wamsi Mohan thinks Apple is in for a strong iPhone upgrade cycle in fiscal 2023, and he predicts it will also introduce a virtual reality headset that year as well.

That thesis seems to indicate Mohan believes 5G connectivity will really become a game changer for consumers about a year from now. 5G killer apps won't catch on until the network is built out, which is currently in process. Telecom companies are currently racing to build out mid-band 5G across the country, which takes a lot of capital and time. Yet by next year, a lot of that infrastructure will have been rolled out and accessible to smartphone customers. 

In any case, between the Moody's upgrade to Apple's safety profile and BofA's upgrade to the company's improving medium-term growth outlook, it's no wonder Apple is currently rising back near all-time highs, and closing in on a $3 trillion market cap as the most highly valued company in the world.