The S&P 500 (^GSPC 0.39%) advanced 31% over the past year as investors became more confident in a soft landing, a scenario in which the Federal Reserve successfully tames inflation without tipping the economy into a recession. The index currently sits within a percentage point of its record high, but upward momentum has stretched valuations across the stock market.

The S&P 500 currently trades at 20.9 times forward earnings, a slight premium to the five-year average of 19 times forward earnings, and a substantial premium to the 10-year average of 17.7 times forward earnings. Not surprisingly, some analysts on Wall Street think stocks are due for a correction. JPMorgan Chase and Morgan Stanley have set the S&P 500 with year-end targets of 4,200 and 4,500, respectively, implying a downside of 19% and 14% from its current level.

Those forecasts leave investors with a tough decision. Is it safe to buy stocks with the S&P 500 near its record high? Or is the stock market best avoided until valuations come down? Anyone looking for answers might want to take their cue from Warren Buffett.

What investors can learn from Berkshire Hathaway's 13F filings

CEO Warren Buffett reportedly manages about 90% of Berkshire Hathaway's (BRK.A 0.05%) (BRK.B -0.07%) equity securities portfolio, while deputies Todd Combs and Ted Weschler handle the remainder. Investors can track the stocks the trio buys and sells each quarter by reviewing the Form 13Fs the company files with the SEC.

The latest filing indicates that Berkshire sold several stocks during the fourth quarter. The company closed its positions in Markel, Globe Life, D.R. Horton, and StoneCo, substantially reduced its positions in Paramount Global and HP, and trimmed its stake in Apple (AAPL 3.27%). However, Berkshire also bought stocks during the fourth quarter. The company added to its positions in Sirius XM, Occidental Petroleum, and Chevron.

Collectively, Berkshire was a net seller of stocks last year. The company reported more than $40 billion in equity securities sales compared to just $16 billion in purchases. That marks a turnaround from the previous year when Berkshire reported $33 billion in equity securities sales and $68 billion in purchases.

In short, Buffett and his deputies continued to buy stocks throughout 2023 despite rising valuations, but they also moved more cautiously. Investors should follow that example.

The Warren Buffett blueprint for investing success

Over the years, Warren Buffett has dropped bits of investing advice like breadcrumbs during interviews, editorials, and shareholder letters. In synthesizing that information, the prevalent theme is that Buffett likes to buy understandable businesses that benefit from a durable economic moat, but only when shares trade at attractive prices relative to intrinsic value.

Economic moats come in different shapes and sizes, but they generally amount to pricing power or cost advantages. For instance, Apple derives pricing power from the brand authority it has built with consumers. Nvidia has pricing power in the superior nature of its artificial intelligence chips. And Visa benefits from cost advantages arising from the size of its payments network. However, an economic moat alone does not qualify a business as a good investment. Investors must also consider its valuation.

Buffett once explained the concept of intrinsic value by quoting economist John Burr Williams: "The value of any stock, bond, or business today is determined by the cash inflows and outflows -- discounted at an appropriate interest rate -- that can be expected to occur during the remaining life of the asset." That quote refers to discounted cash flow analysis, which discounts future earnings back to their present value to estimate what a company is worth.

How the discounted cash flow calculation works

The discounted cash flow (DCF) formula looks intimidating on paper. But online calculators can crunch the numbers, so investors only need to familiarize themselves with the inputs. Learning by example is the best strategy. Shown below is a DCF calculation for Apple using this calculator.

  • Current value: The trailing-12-month earnings per share (EPS) or free cash flow (FCF) per share. I used earnings per share of $6.42 over the last 12 months.
  • Discount rate: The return required to make the investment worthwhile. I used the historical return of the S&P 500, which is approximately 10% annually. Some investors prefer the weighted average cost of capital.
  • Growth rate: The anticipated earnings growth rate over a defined period of time. I used the consensus forecast among Wall Street analysts, which says Apple will grow earnings per share at 8.3% annually over the next five years.
  • Growth over: The length of time the growth rate will persist. As mentioned, Wall Street expects Apple to grow earnings per share at 8.3% annually over the next five years.
  • Terminal rate: The anticipated earnings growth rate after the explicit forecast period. This number should align with inflation, but should not exceed gross domestic product growth. Investors typically select a value between 2% and 4%, so I split the difference with 3%.
  • Terminal rate over: The length of time the terminal rate will persist. Investors often assume terminal growth will continue indefinitely, but I used 50 years.

Based on those inputs, Apple is currently worth $115 per share. That means the stock is about 32% overvalued at its current price of $169 per share. However, investors should remember DCF models involve guesswork, and even small changes to the inputs can have a drastic impact on the output.

It's safe to buy stocks, but the market environment warrants caution

To summarize, the S&P 500 moved much higher over the past year, and the index currently trades at a material premium to its historical valuation. Even so, Buffett continued to buy stocks throughout the year, including during the fourth quarter. But he also showed more caution compared to the previous year, indicating that worthwhile investments were harder to find.

In that context, investors can safely purchase stocks in the current market, provided they show similar caution. That means avoiding costly mistakes driven by fear of missing out, and instead limiting purchases to competitively advantaged businesses trading at reasonable valuations.