Stocks ended sharply higher on Monday after a late rally driven by hopes for a Greek debt deal and as energy shares bounced with oil prices.

Greece’s new government has proposed ending a standoff with its international creditors by swapping its outstanding debt for new growth-linked bonds, Finance Minister Yanis Varoufakis was quoted as saying on Monday.

Adding to the day’s advance were energy shares, with the S&P 500 energy sector .SPNY ending up 3 percent. U.S. crude CLc1 settled up 2.8 percent at $ 49.57 a barrel, despite a strike at U.S. refineries that could boost crude supply.

The sharp move higher came late in a session where the S&P 500 repeatedly moved between positive and negative territory.

“Markets are finding some comfort in the fact there is a dialogue that has the potential to lead to something other than a Grexit. That is a constructive narrative for equity markets, not just in the U.S. but globally,” said Peter Kenny, chief market strategist at Clearpool Group in New York. “Grexit” refers to the possibility of Greece exiting the euro zone.

The Dow Jones industrial average .DJI rose 196.09 points, or 1.14 percent, to 17,361.04, the S&P 500 .SPX gained 25.86 points, or 1.3 percent, to 2,020.85 and the Nasdaq Composite .IXIC added 41.45 points, or 0.89 percent, to 4,676.69.

The gains also follow the worst monthly performance for the indexes in a year.

Shares of Exxon Mobil were up 2.5 percent at $ 89.58 after it reported a smaller-than-expected profit drop. The results follow several disappointing earnings results from many multinational companies.

Disappointing readings on consumer spending and the manufacturing sector weighed on the market early in the session.

The pace of growth in the U.S. manufacturing sector slowed more than expected in January. U.S. consumer spending recorded its biggest decline since late 2009 in December, with cheaper gas not translating to higher activity.

Solar power companies were among the strongest of the day after China said it aims to install 15 gigawatts of solar power capacity this year, 43 percent more than it added in 2014. First Solar climbed 7.5 percent to $ 45.48.

About 7.7 billion shares changed hands on U.S. exchanges, above the 7.4 billion average for the last five sessions, according to BATS Global Markets.

NYSE advancing issues outnumbered decliners 2,271 to 821, for a 2.77-to-1 ratio; on the Nasdaq, 1,746 issues rose and 987 fell, for a 1.77-to-1 ratio favoring advancers.

The benchmark S&P 500 posted 4 new 52-week highs and 6 lows; the Nasdaq Composite recorded 25 new highs and 82 lows.