New York CNN Business  — 

It has been a rough quarter for the US economy, with the country plunging into a pandemic-fueled recession. Yet the stock market is alive and kicking — in fact, it’s having its best quarter in more than 20 years.

The Dow (INDU) recorded its best quarter since the first three months of 1987 with a 17.8% jump, while the S&P 500 (SPX) logged its best quarterly gain since the final three months of 1998, climbing 19.9%.

The tech-heavy Nasdaq Composite (COMP) lagged only slightly behind, with its best performance since the fourth quarter of 1999, soaring 30.6%.

All three indexes also finished in the green on Tuesday, the final trading day of June and the second quarter.

It’s been an extremely turbulent quarter for the stock market.

The buoyant rally came on the coattails of a dramatic selloff in the market in March, when the pandemic lockdown began. The Dow recorded its worst start to a year in history, falling 23.2% in the first three months.

But investors were optimistic about the summer thanks to the gradual reopening of the economy – which began as early as April in some states – as well as unprecedented monetary and fiscal stimulus left investors optimistic about the summer.

More than 20 million American jobs vanished in April, but soon after, the jobs picture and other economic data began to improve as well.

That said, the country’s crisis is clearly not over. Thursday’s jobs report from the Bureau of Labor Statistics is still expected to show an unemployment rate of more than 12%.

Nevertheless, investors are deciding to focus on the positives.

Over the past few weeks, infection rates in parts of the country have surged and have left some states to pause their reopening plans. Economists worry about what a second lockdown could do to the recovery. These worries weighed on the market on some days but were often outweighed by hopes for more stimulus money from Washington.