ZURICH, July 31 (Reuters) - The Swiss National Bank on Friday reported a large increase in quarterly profit, thanks to rising equity markets, which compensated for a plunge in the price of gold.

The central bank reported a second-quarter profit of 25.7 billion Swiss francs ($31.84 billion), reversing a 22 billion franc loss a year earlier and up from a loss of 500 million francs in the first three months of the year.

The figure beat UBS forecasts for a profit of 19 billion to 24 billion Swiss francs.

Between April and June, the central bank made a profit of 39.9 billion francs on its foreign currency positions - representing dividends, interest payments and price gains on the mountain of stocks and shares it has built up.

The MSCI World Index gained 13% in the second quarter, as markets rallied in the U.S. and Europe due to accelerating investment in AI and a reduction in fears about the Iran war.

The SNB made a loss of 14.1 billion francs on its gold holdings, which represented the falling value of the 1,040 tonnes of the precious metal the SNB holds.

Gold lost 14% in value during the second quarter as investors priced in higher U.S. interest rates, and the stronger dollar weighed on demand.

The figures illustrated the wide swings in the SNB's results caused by its large balance sheet, said UBS economist Florian Germanier.

"The bank has profited in recent quarters from the gold price rally," Germanier said. "That has cooled now, but rising stock prices have more than made up for it."

($1 = 0.8071 Swiss francs)

(Reporting by John Revill, Editing by Miranda Murray and Mrigank Dhaniwala)

Find it fast

Looking for more insights? Explore our other news sections for updates on sustainable finance, companies and financial education