The stock market has notched the year’s best stretch of gains, as investors take comfort from early signals that inflation is slowing and the economy is holding up.

The S&P 500 rose 1.7 percent on Friday, taking its rise for the week to 3.3 percent and marking its fourth consecutive positive week, a feat it had not achieved since October. The index is now more than 16 percent higher than its low point in June, though it remains 10 percent lower for the year.

The rally stands in stark contrast with the first half of the year, when Wall Street suffered its worst start in half a century, as the war in Ukraine, soaring energy costs, rising interest rates and rapid inflation galvanized investors’ fears about the health of the economy.

In the past month, investors have welcomed data that showed cooling inflation, a robust labor market and resilient company earnings. Having braced for the worst, improvements in the