BEIJING — Stocks swerved up and down Thursday before ending with a modest gain after China sent conflicting signals about how it would respond to President Donald Trump’s threats of new tariffs and investors took some solace in upbeat economic and earnings data.

The positive signs included an increase in U.S. retail sales in July, according to the Commerce Department, and stronger-than-expected earnings from Walmart, which raised its outlook for sales this year. The Chinese e-commerce giant Alibaba also released strong financial results.

By the end of trading Thursday, the S&P 500 gained 0.25%. Stocks in Europe ended lower, but clawed back some of their earlier losses.

US stock indexes end mostly higher after volatile day

The swings were just the latest in a turbulent stretch for investors. Markets around the world have been whipsawed this month by mixed signals about the state of the trade war between the United States and China and growing evidence that the dispute is already slowing global growth, especially in the manufacturing sector.

The volatility reflects the enormous uncertainty investors are feeling as the high-stakes dispute between the world’s two largest economies — one run by an opaque government, the other led by a president prone to firing off inflammatory messages on Twitter — drags on.

On Thursday, a statement from the Chinese government — released just before the start of U.S. trading — helped to lower the tension.

Advertising

“We hope the U.S. can work in concert with China to implement the two presidents’ consensus that was reached in Osaka, and to work out a mutually acceptable solution through equal-footed dialogue and consultation with mutual respect,” Hua Chunying, the foreign ministry representative, said in the statement.

The consensus in question was hashed out by Trump and Xi Jinping, China’s leader, in June, when they agreed to resume trade talks.

The truce appeared to disintegrate this month amid Trump’s threats of new tariffs and a decision by Chinese officials to allow the country’s tightly controlled currency weaken, developments that suggested the two sides were girding for a standoff that could last indefinitely.

In recent weeks, data has shown that the fight is taking a toll on industrial economies around the world. Closely watched surveys in Britain, China, Germany and Japan have all indicated that the industrial sectors in those countries are contracting.

There are also growing signs of industrial weakness in the United States. On Thursday, reports showed that America’s industrial production fell 0.2% in July from the month before, more than economists had expected.

On the flip side, there is little evidence that the consumer sector, the primary driver of U.S. growth, has been hurt by the trade fight. Unemployment remains near its lowest levels in a half-century. Government data released Thursday appeared to confirm consumer demand remains robust, with retail sales showing a better-than-expected 0.7% gain in July from the month before.

Advertising

But the trade fight is far from over, as an earlier statement from Beijing on Thursday showed.

That statement appeared to increase tensions by threatening a response should Trump carry out his vow to place a 10% tariff on billions of dollars of Chinese imports as of Sept. 1. The statement, attributed to an unidentified Chinese Cabinet official, did not specify what the countermeasures would be.

The threat of additional tariffs has added to fears about the global economic outlook and pushed markets lower around the world. Those fears were evident Wednesday, after investors worried about global growth gave Wall Street one of its worst days this year. The S&P 500 index fell 2.9%.

In the United States, bond markets have begun to hint that a recession there could come soon.

On Thursday, the yield on the 30-year Treasury bond fell below 2% for the first time on record, ending the New York trading day at 1.98%.

The drop reflected increased demand for Treasuries as investors pull their money from riskier stocks, said Joshua Mahony, a senior market analyst at IG Group in London. The drop below 2% for the first time was “historical and rare in nature” and “points toward substantial fear,” he added.

“Yields are falling across the board; it’s a flight to safety,” he said. The benchmark 10-year Treasury note ended the day at 1.53%, within striking distance of its record low of 1.36%, a level it touched in July 2016.

Complicating that outlook is the situation in Hong Kong, a semiautonomous Chinese territory. Hong Kong residents have been protesting China’s growing involvement in daily life. In recent days, violence has led Chinese state media to make thinly veiled threats about military intervention.

“There were a handful of catalysts adding to the markets’ roller-coaster ride, including continuing civil unrest in Hong Kong and escalating fears that trade relations with China are becoming even more derailed,” Tom Stringfellow, chief investment officer at Frost Investment Advisors, said in an emailed note, referring to Wednesday’s slump.

Late Wednesday, Trump suggested that the fate of the trade war and Beijing’s response to the Hong Kong protests could be linked.

“Of course China wants to make a deal,” he wrote on Twitter. “Let them work humanely with Hong Kong first!”

The tenor from many economists has grown more pessimistic as the trade war has escalated. Last week, global currency markets were shaken after Chinese officials raised the specter of a currency war with the United States in response to a new tariff threat from the Trump administration.

Advertising

“Markets are reacting on the fear that the additional threats of more tariffs by the Trump administration will result in a slower-growing global economy,” said Steve Cochrane, the chief Asia Pacific economist at Moody’s. “The risk of recession in the U.S. is not overstated.”

Last week, Goldman Sachs flagged concerns about the U.S. economy after Trump threatened to put the 10% tariffs on additional Chinese goods. Goldman said the threat added to fears of a recession.

Earlier this week, Trump administration officials clarified which tariffs they would increase Sept. 1, leaving certain Chinese goods off the list until December, like laptops, cellphones and toys.

That move did little to ease the concerns of some experts.

“We are in uncharted territory with few historical precedents to guide us,” said Shaun Roache, chief economist for Asia Pacific at S&P Global. “The latest temporary reprieve on tariffs does little to ease this uncertainty.”