The government said on Wednesday that the U.S. economy had suffered its worst contraction since the last recession. The head of the Federal Reserve later said he didn’t know how bad this downturn would be, or how long it would last.

Yet by the end of the day, the S&P 500 stock index had risen 2.7 percent.

That’s been the pattern lately. The drumbeat of grim news — one million known coronavirus cases in the United States, businesses are collapsing, the unemployment rate could reach 16 percent — has done little to deter stocks’ upward march.

Since March 23, when the Federal Reserve announced plans to make unlimited purchases of financial assets to prop up Wall Street, the S&P 500 has soared by more than 31 percent. The unlikely rally created more than $5 trillion of stock market wealth, allowing investors to reclaim more than half of their losses from a steep sell-off earlier this year, in the early days of the pandemic.

Why are stocks climbing when news about the economy isn’t getting much better, and the severity of the public health crisis has barely abated? There are two main reasons: First, trillions of dollars of stimulus money from the Fed and Congress come with an implicit guarantee that the government will limit investors’ risk no matter how bad it gets. Second, the periodic glimmer of positive news fuels investors’ optimism that things can only get better.