JPMorgan Chase & Co posted a higher-than-expected second-quarter profit as it wrote off fewer bad mortgages and credit card loans.

The second-largest U.S. bank made new loans faster than customers paid off existing ones during the quarter, a reversal from the first quarter and a good sign for a business long plagued by weak loan demand.

JPMorgan's revenue rose and it added staff in the quarter, and its shares closed 1.8 percent higher on Thursday. But the bank faces big expenses from mortgages as the effects of the housing crisis linger.

Foreclosures could take another 12 to 18 months to start declining, Chief Executive Jamie Dimon said on a conference call with reporters.

JPMorgan's revenue growth is a sign that things are getting better. They're just not getting better quickly, said Ralph Cole, portfolio manager at Ferguson Wellman Capital Management in Portland, Oregon. Ferguson Wellman owns JPMorgan shares.

Revenue of $27 billion was up 7 percent from a year earlier.

Although loans at the end of the second quarter were up from the end of the first quarter, average loans outstanding declined, signaling that even if loan demand is improving, growth is uneven.

JPMorgan is the first major U.S. bank to post quarterly results. Its performance hints at how other banks fared.

BOND TRADING

Bond trading revenue fell 18 percent from the first quarter, but the decline was less than some investors feared. Shares of investment banks Goldman Sachs Group Inc and Morgan Stanley rose on hopes that JPMorgan's trading results bode well, but turned negative later in the day.

JPMorgan earned $5.43 billion, or $1.27 a share, in the second quarter, beating the average Wall Street estimate by 6 cents a share, according to Thomson Reuters I/B/E/S.

The results were up from earnings of $4.8 billion, or $1.09 a share, a year earlier.

The bank benefited from not having to pay a British tax on bonuses. That tax reduced profits by $550 million, or 14 cents a share, last year.

JPMorgan made more loans during the quarter, net of customer loan repayments. Its loan book grew to $689.74 billion at the end of the quarter from $686 billion at the end of March as increased business lending offset a 2 percent decline in consumer lending.

The bank also gathered more deposits during the quarter; deposits rose 5 percent from the first quarter to $1.05 trillion. Chief Financial Officer Douglas Braunstein said mid-sized companies delivered much of the money.

Shrinking loan books and low interest rates since 2008 have made it difficult for banks to post profits, or increase them. A large part of earnings over the past year has come from setting aside less money to cover bad loans, or dipping into funds previously set aside.

Many analysts hope that banks will start to post loan growth in the coming quarters, which would be a sign of sustainable increases in profits.

Dimon, who is famously blunt, seemed optimistic about the outlook for profits. He said the bank will build capital levels in the coming months, and criticized regulators for not allowing it to return those funds to shareholders faster.

God knows why we have to hold all that capital, Dimon said, adding that banks' capital ratios are going to drive up so fast people are going to be surprised.

JPMorgan reduced the expense it recorded for credit costs to $1.81 billion in the second quarter from $3.36 billion a year earlier. However, that was up from $1.17 billion in the 2011 first quarter.

After announcing earnings, the bank went to the corporate debt market and sold $1.75 billion of bonds due in 30 years, an unusually long term for bank debt, but JPMorgan's second 30-year issue in nine months, according to IFR, a Thomson Reuters capital markets service.

TAKING TIME WITH MORTGAGES

Mortgage costs were down slightly, but Dimon cautioned that the housing market was still working through difficulties.

Unfortunately, it will take some time to resolve these issues and it is possible we will incur additional costs along the way, he said.

JPMorgan expects to have to repurchase $3.6 billion of mortgages that it packaged into bonds. Such repurchases are usually because a bank failed to properly collect payments on the mortgages, or should never have sold them to investors.

JPMorgan said it added $1.3 billion to its litigation reserves, mainly for mortgage-related matters. It also continued to add to its loan reserves for losses on mortgages.

It is possible we are very over-reserved in mortgage land, Dimon said in a conference call with analysts.

He expects to win a legal battle with the Federal Deposit Insurance Corp over liabilities left from busted lender Washington Mutual, pieces of which JPMorgan bought in a government-arranged deal during the financial crisis.

Credit card delinquencies are improving so quickly that the bank drew down its reserves for losses on those balances, adding 15 cents a share to second-quarter profit.

The charge-off rate for uncollectable card debt will be down to about 4.5 percent this quarter, nearly a year earlier than previously expected, said Chief Financial Officer Douglas Braunstein. The improvement echoed comments Wednesday from card lender Capital One Financial Corp.

JPMorgan has been hiring people to work out its problems with mortgages, still the biggest drag on its business. The bank said it hired 10,000 people in the second quarter. It has 250,095 people as of the end of June.

Compensation expenses slid in the last three months as pay for employees in the investment bank declined 22 percent from the first quarter when trading revenue shrank. Compensation costs at the investment bank fell by $730 million to 35 percent of revenue, down from 40 percent in the first quarter.

When revenues are down, JPM manages to bring down their costs faster than everyone else. That really did cushion some of the earnings decline, said Credit Suisse analyst Moshe Orenbuch.

(Reporting by David Henry and Dan Wilchins. Additional reporting by Maria Aspan, Joe Rauch and Knut Engelmann. Editing by John Wallace, Robert MacMillan and Tim Dobbyn)