Stocks closed broadly higher Wednesday amid renewed hopes on Wall Street that a U.S. trade deal with China may be nearing, despite tough recent talk from President Donald Trump.

The gains snapped a three-day losing streak for the S&P 500, though the benchmark index remains on track for a weekly decline.

The market has swung sharply for months on every hint of progress about talks between the world’s largest economies, and the latest flip-flop followed a report from Bloomberg News saying U.S. negotiators expect a “Phase 1” trade agreement to be completed before U.S. tariffs are set to rise on Chinese products Dec. 15.

The report came a day after Trump said he wouldn’t mind waiting until after the 2020 elections for a deal, a remark that officials reportedly called off the cuff but nevertheless sent markets skidding.

“The trade war will be the key driver of sentiment in the immediate few weeks,” DBS Group analysts wrote in a report.

Health care and financial stocks drove much of Wednesday’s rally. Energy companies notched the biggest gain following a 4.2% increase in the price of U.S. crude oil. Materials stocks ended essentially flat.

The S&P 500 rose 19.56 points, or 0.6%, to 3,112.76. Despite recovering some losses, the index is still down 0.9% for the week.

The Dow Jones Industrial Average climbed 146.97 points, or 0.5%, to 27,649.78. The Nasdaq composite gained 46.03 points, or 0.5%, to 8,566.67. The Russell 2000 index of smaller company stocks picked up 11.27 points, or 0.7%, to 1,613.90.

Treasury yields also recouped some of their sharp drops from earlier in the week. Rising optimism on trade means less demand for safe investments, and when prices for Treasurys fall, their yields rise.

The yield on the 10-year Treasury rose to 1.77% from 1.71% late Tuesday. It was at 1.83% on Monday.

The stock gains are the first so far this month since the market closed out a strong November rally that brought major indexes to all-time highs.

Surprisingly good company earnings and solid economic data have helped keep investors in a buying mood this fall against a backdrop of optimism that the U.S. and China were nearing a trade deal.

Beyond China, Trump has been pushing ahead on trade disputes all around the world recently. On Tuesday, he proposed tariffs on $2.4 billion in French products in retaliation for a tax on global tech giants including Google, Amazon and Facebook. That follows a threat Monday to raise tariffs on steel and aluminum from Argentina and Brazil.

The trade war has hurt manufacturers and weighed on economic growth around the world. Central banks have cut interest rates and unloaded stimulus to help spur growth. In the U.S., a strong job market is helping to prop up the economy.

A report on the U.S. job market came in surprisingly weak, which could raise doubts about what’s been the strongest part of the economy. Private employers added just 67,000 jobs last month, according to payroll processor ADP. That’s roughly half of October’s hiring pace and weaker than economists expected.

The more comprehensive jobs report from the Labor Department will arrive on Friday, and it will likely have a bigger impact on the market.

A separate report showed that U.S. services industries grew last month, but not as quickly as economists expected.

Traders shrugged off the mixed economic data Wednesday.

“This market is trading under the assumption that global growth has put a bottom in and is in the process of recovering, and nothing in the data we’ve seen today disputes that conclusion,” said Scott Ladner, chief investment officer at Horizon Investments.

A rebound in the price of crude sent oil-related stocks to the market’s biggest gains. Energy stocks in the S&P 500 rose 1.6% for the biggest gain among the 11 sectors that make up the index. Halliburton rose 4.2%, and Devon Energy added 4.6%.

Benchmark U.S. crude climbed $2.33, or 4.2%, to $58.43 per barrel as members of OPEC prepare to meet later this week and vote on production levels. Brent crude, the international standard, rose $2.18, or 3.6%, to $63.

Financial stocks were strong after a rise in interest rates boosted profit expectations for companies making loans and sitting on large investment portfolios. JPMorgan Chase rose 2%, and Regions Financial gained 1.6%.

Expedia Group climbed 6.2% after the company shook its leadership and expanded its stock buyback program.

In other commodities trading, wholesale gasoline rose 4 cents to $1.60 per gallon and heating oil climbed 4 cents to $1.92 per gallon.

Natural gas fell 4 cents to $2.40 per 1,000 cubic feet. Gold slid $4.20 to $1,474.00 per ounce and silver dropped 33 cents to $16.80 per ounce. Copper, which often moves with expectations for global economic strength, rose 3 cents to $2.64 per pound.

The dollar rose to 108.93 Japanese yen from 108.57 yen on Tuesday. The euro weakened to $1.1075 from $1.1082.

European stock indexes finished higher, while Asian markets sank.

Copyright 2019 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.