Stocks closed higher as investors grow cautiously optimistic the U.S. and China can make progress in upcoming trade talks and more in Thursday’s Stock Market Update.

Microsoft, the most valuable stock on the S&P 500, rose 1% and PayPal added 3%. Shares of Amazon gained 1.1% while Hasbro rose 1.8%.

Energy was the worst-performing sector as the price of oil fell 1.1% to $55.11 a barrel. Marathon Oil dropped 3.4%.

The U.S. agreed to delay another round of tariffs on Chinese imports by two weeks to Oct. 15. Meanwhile, Chinese importers have asked U.S. suppliers for prices for soybeans, pork and other farm goods — a sign they might step up purchases of American agricultural products.

The gestures stoked cautious optimism among investors that the next round of trade talks in October between Washington and Beijing may lead to some progress after a string of failed attempts at resolving the longstanding dispute.

“What’s driving markets today is the potential for an interim trade deal,” said Tony Roth, chief investment officer at Wilmington Trust. “There’s enough pain to (China’s) domestic economy and there’s enough pain to our domestic economy that it’s in both presidents’ interests to take a step back and have a little bit of breathing room right now. That’s what’s changed.”

STOCK MARKET UPDATE

The S&P 500 gained 8 points, or 0.3%, to 3,009, led by technology and consumer-focused companies, although the rally lost some steam in the final minutes of trading. The Dow Jones industrials rose 45 points, or 0.2%, to 27,182 after being up about 170 points earlier. The Nasdaq gained 24 points, or 0.3%, to 8,194.

The Russell 2000 index of smaller company stocks picked up just over 1 point, or 0.1%, to 1,577.

The U.S.-China talks have basically gone nowhere since early May, when the two sides appeared to be nearing a deal. Along the way, the countries have slapped import taxes on hundreds of billions of dollars’ worth of each other’s products.

Financial markets were rattled in August as the trade conflict escalated yet again, fueling worries that more tariffs and a slowing global economy could bump the U.S. into a recession. The economic uncertainty has also become a drag on companies.

The two countries’ conciliatory moves Wednesday and Thursday have raised hopes on Wall Street that the upcoming round of trade negotiations may yield a different outcome than previous attempts.

The reason? The trade war has begun to take its toll economically on both economies.

“Six months ago, even three months ago, you weren’t registering as much economic deterioration as you are now in both economies,” Roth said. “The markets are believing that there’s some credibility in the idea that there may be an interim trade truce, let’s call it, where they roll back some of the tariffs, the Chinese would by some stuff, and there would be relief to both economies.”

Several weeks of solid gains have helped the S&P 500 more than recoup its losses in August, nudging it closer to another record high close.

The index is also on track for its best September since 2013. The S&P 500 is up 3.1% this month after slipping 1.8% in August. That’s notable because the index has fallen in September 55% of the time since World War II, although the record has been better during the 10-year bull market.

Small companies are the star performers so far this month. The Russell 2000 index of smaller-company stocks is up 5.4%, with much of the gain coming this week. Those smaller companies are viewed as more insulated from the impact of volatile swings in the U.S.-China trade war.

Tech stocks notched solid gains Thursday. The sector’s companies, particularly chipmakers, are heavily impacted by the trade war because many of them make products in China or rely on Chinese suppliers.

Consumer-focused stocks also helped lift the market. McDonald’s rose 0.9%. Health care stocks also contributed to the rally. Medical device maker Abbott gained 0.8%.

Energy companies tumbled as oil prices slid 1.2%. Oilfield services company Schlumberger dropped 1.1%.

The yield on the 10-year Treasury rose to 1.78% from 1.73% a day earlier. Higher yields drive interest rates on mortgages and other consumer loans higher, helping boost bank profits. JPMorgan Chase and Citigroup each rose 0.6%.

Tailored Brands plunged 29.8% after the owner of Men’s Wearhouse and Jos. A Bank gave investors a dismal third quarter profit forecast and halted its dividend.

DXC Technology tumbled 11% after the information technology company said CEO Mike Lawrie retired and is being replaced by a member of the company’s board.

Stocks in Europe finished higher following the European Central Bank’s latest round of economic stimulus. The central bank cut the rate on deposits it takes from banks and said it will start buying bonds, which will help pump money into the financial system and lower borrowing costs.

The rate cut was widely expected as the European Union faces an uncertain future with Britain’s likely chaotic exit on Oct. 31. European nations are also facing a broad economic slowdown as the impact of the U.S.-China trade war reverberates globally.

© The Associated Press. All rights reserved.