(AP) -- Stocks finished with broad gains on Wall Street Thursday, driving the Dow Jones Industrial Average more than 300 points higher.
The buying spree gave the market its second straight gain after a wobbly start to the week. The S&P 500 is now on track for its first weekly gain in five weeks.
The rally was spurred by fresh hope among investors that new talks between the U.S. and China set for September can lead to progress in the nations' ongoing trade war.
"Investors are hoping that some sort of renewed discussions could lead to a genuine truce," said Sam Stovall, chief investment strategist at CFRA. "All the market is trading on today is optimism, not on reality."
The S&P 500 rose 36.64 points, or 1.3%, to 2,924.58. The Dow climbed 326.15 points, or 1.3%, to 26,362.25. The Nasdaq gained 116.51 points, or 1.5%, to 7,973.39.
Investors favored smaller company stocks for the second straight day. The Russell 2000 index added 24.01 points, or 1.6%, to 1,496.72.
Major stock indexes in Europe also closed broadly higher.
While the major indexes have stemmed some of their losses from earlier this month, they remain down about 2% for the month with one trading day left in August. If those losses hold, August would be the second monthly drop for the market this year after May.
Uncertainty over the costly and long-running trade conflict fueled a wave of market volatility through much of August as traders worried that it could knock the global economy into a recession and hurt corporate profits.
But Thursday brought some tendrils of optimism for traders. A published report noted that China's commerce ministry said it is discussing the next round of in-person trade negotiations with the U.S. to be held next month.
In an interview with Bloomberg, Treasury Secretary Steven Mnuchin said talks with China are ongoing and are expected to continue in Washington, though he did not specify when.
Trade negotiators are due to meet in September for new negotiations, though there has been no sign of progress in recent days since an escalation by both sides earlier this month.
The glimmer of hope gave investors reason to shift some of the money they've been plowing into the safety of U.S. government bonds back to stocks.
Even so, long-term bond yields remained below short-term ones, a so-called inversion in the U.S. yield curve that has correctly predicted previous recessions.
The yield on the 10-year Treasury rose to 1.50% from 1.47% late Wednesday. The 2-year Treasury yield rose to 1.53% from 1.49% the day before. The yield for the 10-year Treasury has been flat or below that of the 2-year this week.
That's fueled fears that the economy could be headed for a recession. Still, while an inverted yield curve has preceded every U.S. recession, it is not a signal that one is imminent. It has taken 14 to 34 months for past recessions to begin following a yield curve inversion. And the stock market has continued to climb in those months or years before a recession.
"The global economy is slowing, and the question is whether trade will tip that into a global recession or whether or not it will just be a garden-variety slowdown," said Jason Katz, senior portfolio manager at UBS Wealth Management USA.
Last week, the trade conflict escalated again with both sides threatening new tariffs on each other's goods, triggering a sharp sell-off in global markets.
Some of the Trump administration's additional tariffs on Chinese products take effect Sunday and others on Dec. 15. In addition, higher tariffs on a separate group of Chinese products are to take effect Oct. 1.
A mixed batch of new economic data didn't dampen Thursday's market rally.
The government reported that gross domestic product, the broadest gauge of economic health, advanced at a moderate 2% annual rate in the April-June quarter, down from a 3.1% gain in the first quarter. The figure was lower than the government's initial estimate a month ago of 2.1% growth.
And business investment, which has weakened in the face of the Trump administration's trade wars, was revised lower and subtracted from growth in the April-June period.
At the same time, consumer spending shot up to an annual rate of 4.7% in the second quarter, the best showing since the final quarter of 2014. That helped put investors in a buying mood.
"While GDP was in line or slightly lower, the consumer piece of it, which accounts for two-thirds of our economy, was really strong and that's one of the reasons behind the rally," Katz said.
Technology companies accounted for a big slice of Thursday's gains. Microsoft rose 1.9% and Apple added 1.7%. Financial, industrials and communication services stocks also were big winners. JPMorgan climbed 2.3%, American Airlines Group gained 3.9% and Facebook rose 2.1%.
Dollar General led all stocks in the S&P 500 after the discount retailer reported quarterly results that were better than analysts were expecting. Its shares vaulted 10.7%. Rival Dollar Tree gave up an early gain, sliding 1.9%.
Walmart gained 1.2%, Nordstrom rose 2.8% and Amazon added 1.3%.
Other retailers didn't fare so well. Best Buy slumped 8%, one of the biggest decliners in the S&P 500, after the consumer electronics chain reported strong quarterly profit that was overshadowed by disappointing revenue growth. The company lowered its revenue outlook for the year, citing the expected impact of U.S. tariffs on Chinese imports.
Abercrombie & Fitch slid 15.1% after the teen clothing retailer lowered its full-year sales forecast.
Crude oil rose 93 cents to settle at $56.71 a barrel. Brent crude oil, the international standard, gained 59 cents to close at $61.08 a barrel. Wholesale gasoline was unchanged at $1.68 per gallon. Heating oil climbed 1 cent to $1.86 per gallon. Natural gas rose 5 cents to $2.30 per 1,000 cubic feet.
Gold fell $12.30 to $1,526.50 per ounce, silver dropped 15 cents to $18.17 per ounce and copper added 1 cent to $2.56 per pound.
The dollar rose to 106.62 Japanese yen from 106.03 yen on Wednesday. The euro weakened to $1.1052 from $1.1079.