A Federal Reserve forecasting tool currently puts the odds of a recession at 51.84% in the next 12 months. That may sound insignificant, but the forecasting tool in question has only given a reading above 50% a few times since 1960 -- the last time was four decades ago -- and each event either preceded or occurred during a recession.

The chart below shows the recession probability implied by the Fed's forecasting tool dating back to 1960. Areas shaded gray have been classified as recessions by the National Bureau of Economic Research. Notice that spikes in the recession probability curve have correlated closely with actual recessions.

US Recession Probability Chart

US Recession Probability data by YCharts

No forecasting tool is perfect, but it would be historically unprecedented if the U.S. economy was not in a recession one year from today, according to the Federal Reserve Bank of St. Louis.

The stock market usually declines sharply during recessions

Nine recessions have rolled through the U.S. economy since 1960, and each one involved a sharp decline in the stock market. For context, the benchmark S&P 500 (^GSPC 1.02%) fell by an average of 32% during those events, with peak losses ranging from 14% to 57%.

In short, history says the stock market will nosedive during the next recession, so investors may be tempted to avoid stocks in 2024. But Peter Lynch and Warren Buffett would probably disagree with that decision.

Market timing strategies lead to losses and missed opportunities

Peter Lynch managed the Fidelity Magellan Fund between 1977 and 1990. That period was characterized by two recessions and two bear markets, but Lynch still achieved an annual return of 29.2%, doubling the performance of the S&P 500.

One reason for that success was his ability to ignore transient headwinds and focus instead on long-term capital appreciation. Lynch once said, "Far more money has been lost by investors preparing for corrections, or trying to anticipate corrections, than has been lost in corrections themselves."

Building on that, investors may think it prudent to exit the market and buy in again when the risk of recession has passed. But trying to time the market often leads to missed opportunities because many of the market's best days occur in close proximity to its worst days. In fact, 42% of the S&P 500's best days in the last two decades occurred during a bear market, and another 36% occurred during the first two months of a bull market (before it was clear the bear market had ended).

Missing even a few of those days can have catastrophic consequences. For example, $10,000 invested in the S&P 500 in January 2003 would have grown 548% to $64,844 by December 2022. But if the 10 best days were excluded, that $10,000 investment would have grown just 197% to $29,708, according to JPMorgan Chase.

Buying opportunities exist in all market environments

Warren Buffett is one of the most accomplished investors in American history. Under his guidance, Berkshire Hathaway has become a $790 billion company, and its share price has increased by a factor of 43,000 since he took control in 1965. Much of that value comes from its $371 billion portfolio, and Buffett manages the vast majority of those assets.

The most important thing investors should know is that Berkshire has consistently put money into the stock market. The company has purchased stocks in every quarter for the last 25 years, buying through bear markets and bull markets, economic booms, and recessions. Buffett has yet to find a market environment in which there are no buying opportunities.

That said, Berkshire has invested more aggressively in some quarters, presumably because valuations were more attractive. Investors should be aware that the S&P 500 currently trades at 19.5 times forward earnings, a premium to its 30-year average of 16.6 times forward earnings. That merits some caution, meaning investors should be particularly cognizant of valuations when they buy stocks.

Buy stocks with economic moats, especially when they trade at discounted valuations

Warren Buffett likes companies with a durable economic moat, and he likes to invest in those companies when their stocks trade at a discount to their intrinsic values. Investors should understand both concepts.

Economic moats come in different shapes and sizes, but they generally amount to pricing power and cost advantages. For instance, Alphabet and Amazon have pricing power arising from immense scale. Nvidia has pricing power arising from the patented technology behind its artificial intelligence chips. And Visa benefits from cost advantages arising from its status as the largest card payments network.

In 1992, Buffett defined 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 the discounted cash flow (DCF) model, a somewhat complex mathematical formula that estimates what a company is worth by discounting its future earnings back to their present value. Fortunately, there are plenty of DCF calculators online. Investors should make a habit of using one of those calculators to estimate the fair value of a stock before purchasing shares.

Here's the bottom line: The Federal Reserve's forecasting tool currently signals a high probability of a recession in the next year. Despite that risk, I believe Lynch and Buffett would still recommend buying stocks in 2024, provided investors take the time to identify good stocks trading at reasonable prices.

Furthermore, if the economy does slip into a recession, investors should treat any subsequent drawdown in the stock market as a buying opportunity. To quote Buffett, "The best chance to deploy capital is when things are going down."