NEW YORK (Reuters) - Wall Street advanced in heavy trading on Friday, with the S&P 500 and the Dow closing the book on their best June in generations, ahead of much-anticipated trade talks between U.S. President Donald Trump and Chinese counterpart Xi Jinping at the G20 summit now underway in Japan.

All three major U.S. stock indexes gained ground at the close of the week, month, quarter and first half of the year, during which time the U.S. stock market has had a remarkable run.

The S&P 500 had its best June since 1955. The Dow posted its biggest June percentage gain since 1938, the waning days of the Great Depression.

From the start of 2019, after investors fled equities amid fears of a global economic slowdown, which sent stock markets tumbling in December, the benchmark S&P 500 jumped 17.3%, its largest first-half increase since 1997.

“The market came to the realization that the world is not going to end,” said John Ham, financial adviser at New England Investment and Retirement Group in North Andover, Massachusetts. “Also, (Federal Reserve chair) Powell did a 180 since (the Fed’s) last (interest) rate hike, which has put wind in our sails in the first half of the year.”

Trump expressed hopes that his meeting with Xi at the G20 summit will be productive, but said he had not made any promises about a reprieve from escalating tariffs.

“Everybody is focused on the Trump/Xi meeting, and most investors are hoping for a ceasefire,” Ham added. “At this point it’s just a question of how much of a ceasefire we get.”

“They’re two strong leaders who want to save face. They both want to walk away from it claiming victory.”

Financial stocks led the gains in the S&P 500 and the Dow after the big U.S. banks passed the Federal Reserve's "stress test," with the central bank giving the companies a clean bill of health. The S&P 500 Bank index .SPXBK gained 2.4%.

FILE PHOTO: Traders work on the floor at the New York Stock Exchange (NYSE) in New York, U.S., June 5, 2019. REUTERS/Brendan McDermid/File Photo

Trading volume spiked amid the annual restructuring of the Russell indexes, traditionally one of the largest trading days of the year.

The Dow Jones Industrial Average .DJI rose 73.38 points, or 0.28%, to 26,599.96, the S&P 500 .SPX gained 16.84 points, or 0.58%, to 2,941.76 and the Nasdaq Composite .IXIC added 38.49 points, or 0.48%, to 8,006.24.

All 11 major sectors in the S&P 500 ended the session in positive territory.

Financials .SPSY, energy .SPNY and tariff-vulnerable industrials .SPLRCI were the biggest percentage gainers.

Shares of Apple Inc AAPL.O dropped 0.9% following its announcement that design head Jony Ive is leaving the company. Separately, the Wall Street Journal reported that the iPhone maker would move its Mac Pro production to China from the United States.

Constellation Brands Inc STZ.N reported better-than-expected quarterly results and raised its full-year guidance due to healthy beer demand, sending its shares up 4.6%.

In economic news, consumer spending rose moderately in May and prices edged higher, implying a slowdown in economic growth and benign inflation pressures, providing the Fed rationales for a possible interest rate cut in July.

Advancing issues outnumbered declining ones on the NYSE by a 2.84-to-1 ratio; on Nasdaq, a 2.66-to-1 ratio favored advancers.

The S&P 500 posted 23 new 52-week highs and no new lows; the Nasdaq Composite recorded 84 new highs and 51 new lows.

Volume on U.S. exchanges was 10.26 billion shares, compared with the 7.11 billion-share average for the full session over the last 20 trading days.