Stocks racked up more gains Friday as Wall Street closed out its best month since November 2020, a welcome breather for investors after a punishing year for the market.

The S&P 500 index, a benchmark for many stock funds, rose 1.4% and finished 9.1% higher for July. A rebound in technology stocks, big retailers and other companies that rely on direct consumer spending helped power the index’s broad gains this month. The index is still down 13.3% for the year.

The tech-heavy Nasdaq rose 1.9%, ending the month 12.4% higher, while the Dow Jones Industrial Average rose 1% and notched a 6.7% gain for the month.

The latest rally came as investors weighed a mix of company earnings reports and new data showing inflation jumped by the most in four decades last month.

The S&P 500 rose 57.86 points to 4,130.29. The Dow gained 315.50 points to close at 32,845.13. The Nasdaq rose 228.09 points to 12,390.69.

Smaller company stocks also gained ground. The Russell 2000 rose 12.20 points, or 0.7%, to 1,885.23. It ended July with a 10.4% gain.

Weak economic data, including a report Thursday showing that the U.S. economy contracted last quarter and could be in a recession, have also spurred stocks higher by giving some investors confidence that the Federal Reserve will be able to dial back its aggressive pace of rate hikes sooner than expected.

The central bank raised its key short-term interest rate by 0.75 percentage points on Wednesday, lifting it to the highest level since 2018. The Fed is raising rates in a bid to slow the U.S. economy and quell inflation.

An inflation gauge that is closely tracked by the Federal Reserve jumped 6.8% in June from a year ago, the biggest increase in four decades, leaving Americans with no relief from surging prices. On a month-to-month basis, inflation accelerated to 1% in June from May’s 0.6% monthly increase, the Commerce Department said Friday.

The figures underscored the persistence of the inflation that is eroding Americans’ purchasing power, dimming their confidence in the economy and threatening Democrats in Congress in the run-up to the November midterm elections.

Some market watchers advised against placing too much emphasis on the June data, however.

Inflation hit one company in its earnings on Friday: consumer staples giant Proctor & Gamble. Shares in the maker of Tide laundry detergent fell 5.3% after the company said consumers were cutting back, but the company’s recent price increases were keeping profits up.

It was a mixed day in the bond market. The two-year Treasury yield, which tends to move with expectations for the Fed, rose to 2.89% from 2.87% late Thursday. The 10-year yield, which influences mortgage rates, fell to 2.65% from 2.67%.