Many stocks are up sharply this year as signs of economic resilience reinvigorated investors. The broad-based S&P 500 is up 15% year to date, and the tech-heavy Nasdaq Composite is up 29%.

But Wall Street legends Warren Buffett and Michael Burry apparently see a reckoning for overvalued equities on the horizon, as both investors recently took steps to protect their portfolios from a stock market correction.

Here are the details.

Berkshire Hathaway is selling stocks

Warren Buffett is widely regarded as one of the greatest business minds in history, so many investors track the stocks Berkshire Hathaway (BRK.A -0.76%) (BRK.B -0.69%) buys and sells each quarter, hoping to mimic his strategy and achieve a modicum of his success. But the latest quarterly Form 13F filed with the SEC included a subtle warning.

Berkshire invested $7.4 billion in stocks during the first half of 2023, far less than the $57.3 billion it had invested by the halfway point in 2022. Berkshire also sold $25.8 billion in stocks during the first half of this year, much more than the $12 billion it sold in the first half of last year.

So what? Berkshire was a net seller of stocks through the first half of 2023 (to the tune of $18 billion), but it was a net buyer of stocks through the first half of 2022 (to the tune of $45 billion). The implication here is simple: Buffett and fellow investment managers Todd Combs and Ted Weschler think stocks are overvalued. At the very least, they couldn't find many opportunities compelling enough to tap into the $147 billion in cash and short-term investments Berkshire has at its disposal.

Scion is betting on a stock market downturn

Michael Burry of Scion Asset Management made a fortune when he predicted the subprime mortgage crisis. In the early 2000s, soaring home prices and lax lending standards left many subprime borrowers with too much debt and credit rating agencies failed to sound the alarm when that bad debt was repackaged as mortgage-backed securities and sold to financial institutions like Lehman Brothers.

What happened next seems obvious in retrospect, but few saw it at the time. Those mortgage-backed securities became worthless when borrowers started to default, and the financial institutions that owned them lost trillions.

Those events ultimately led to the Great Recession, but Burry came out ahead. He pocketed $100 million in profit and earned $700 million for clients by betting against the subprime mortgage bonds, a decision that inspired the 2015 film The Big Short.

So what? Burry started betting against the stock market in the second quarter of this year, and his bets were aggressive. Scion invested $1.6 billion (94% of its assets) in put options on index funds that track the S&P 500 and the Nasdaq-100, according to the most recent Form 13F. A put option confers the right to sell a security at a predetermined strike price, so purchasing a put option only makes sense when the security is expected to lose value.

In this case, Burry is betting the S&P 500 and the Nasdaq 100 will decline, which is tantamount to betting against the U.S. stock market, especially the technology sector.

Is it safe to invest in the stock market?

Buffett and Burry have impressive track records, and their actions always warrant consideration. However, while some caution would undoubtedly be prudent in the current market environment, investors need not avoid stocks entirely.

Berkshire added to a few positions in the first half of the year, including Apple (AAPL -0.35%) and Bank of America (BAC -0.21%), despite being a net seller. And Scion bought several stocks in the second quarter, including Expedia Group (EXPE -0.40%) and Charter Communications (CHTR -1.73%), despite hedging against the broader market.

Additionally, the latest Form 13Fs are a snapshot of the quarter that ended on June 30, so the information is already outdated to some degree. Buffett and Burry may have revised their strategies.

More importantly, history makes it crystal clear that time in the market (not timing the market) is what matters. The S&P 500 has been a profitable investment over every rolling 20-year year period since its creation in 1957, and its precursor was a profitable investment over every rolling 20-year period since its creation in 1926.

In other words, patient investors who buy an S&P 500 index fund today will almost certainly be better 20 years down the road.