Four months after the S&P 500 hit its lowest level since the recession, the benchmark index staged a comeback Tuesday, closing at a record high of 2,933. The Nasdaq Composite Index also hit a record, closing at 8,120, surpassing its Aug. 29 high of 8,109.

The markets roared back after a strong week of corporate earnings. The S&P contains just over 500 of the country’s largest publicly traded corporations, and three-quarters of the companies that reported earnings this week beat analyst expectations.

The market turnaround comes after the S&P hit recession-era levels in December, capping off its worst year since 2008. To date, the index has gained 17 percent for 2019, with the Nasdaq up 22 percent.

Leading the charge on Tuesday was tech heavyweight Twitter, which reported earnings and user growth that outpaced investor predictions. Shares spiked by more than 15 percent after the social platform released its quarterly results.

Analysts credited a more cautious monetary policy from the Federal Reserve and improved relations between the U.S. and China for the volte-face. Having raised the interest rate four times last year, Fed Chairman Jerome Powell has this year followed a more accommodative strategy.

“Fed Chair Jerome Powell removed the barricade and opened the expressway," said Greg McBride, Bankrate's chief financial analyst. "The economy is in solid shape, the labor market is the tightest in 50 years and getting tighter, and interest rates are low."

At the Fed's last meeting, in March, the central bank not only decided not to raise interest rates, but also indicated that no more hikes would be coming this year. While such a move gives the economy room to grow, it also indicates the Fed will have the wherewithal to pull back in case of another pronounced economic downturn.

Tech headliners Facebook and Microsoft release their quarterly earnings on Wednesday, along with Tesla and Dow heavyweight Boeing.