(CNBC) – Stocks rose on Thursday after comments from a top Federal Reserve led to increasing bets that the central bank will take a more aggressive stance later this month to ease monetary policy.

The S&P 500 closed 0.4 percent higher, led by a 0.8 percent gain in consumer staples. The Nasdaq Composite advanced 0.3 percent. The Dow Jones Industrial Average ended the day up just 2 points, after dropping as much as 151.06 points. The gains were the first for the indexes in three sessions.

The indexes turned around in the afternoon came after New York Federal Reserve President John Williams said the central bank needed to “act quickly” when the economy was slowing and rates were low. “It’s better to take preventative measures than to wait for disaster to unfold, ” he said in a speech.

After Williams’ comments, traders increased their bets that the Fed could go deeper than a quarter-point cut at its meeting in late July.

Note: Read our discussion guidelines before commenting.