(Reuters) – JPMorgan Chase’s profit rose in the second quarter, buoyed by rising investment banking fees and an $8 billion accounting gain from a share exchange deal with Visa.

Investment banks have benefited from a resurgence in capital-raising activity both in debt and equities markets.

Wall Street banks are also seeing an uptick in fee income from advising on M&A deals as companies become more confident on the U.S. economy’s ability to avoid a major downturn.

“While market valuations and credit spreads seem to reflect a rather benign economic outlook, we continue to be vigilant about potential tail risks,” CEO Jamie Dimon said adding that the risks included a changing geopolitical situation, which remains the most dangerous since World War II.

The largest U.S. bank’s profit was $18.15 billion, or $6.12 per share, for the three months ended June 30, compared with $14.47 billion, or $4.75 per share, a year earlier, it said on Friday.

The bank benefited from a plan to exchange some of its shares in Visa, the world’s largest payment network.

Investment banking fees grew 50%, compared with a low base, but was higher than an earlier company prediction of 25% to 30%.

JPMorgan also extended its gains from lending, with net interest income (NII) – the difference between what it earns on loans and pays out on deposits – growing 4% to $22.9 billion versus a year earlier.

Lending has remained healthy even as banks compete for deposits and face pressure to shell out more to depositors to store their money.

(Reporting by Niket Nishant in Bengaluru and Nupur Anand in New York, editing by Lananh Nguyen and Anil D’Silva)