JPMorgan Chase & Co posted a record quarterly profit on Friday as falling interest rates and a recovering housing market brought big increases in mortgage lending.

The mortgage market, long a drag on bank results, is starting to lift lenders' earnings again, and JPMorgan Chief Executive Jamie Dimon said he was hopeful about the outlook for U.S. residential real estate.

"We believe the housing market has turned the corner," Dimon said in a statement.

JPMorgan suffered only modest losses in the latest quarter from the "London whale" trades that brought it $5.8 billion of losses in the first half of the year, signaling that it is moving on after the scandal.

The improving housing market brought the bank a 36 percent increase in mortgage lending revenue in the third quarter and made up for the drag of weak demand from borrowers. In fact, a $993 million increase in total mortgage fees neatly offset an $831 million decrease in net interest income.

Analysts expect mortgage lending volume to continue to rise after the Federal Reserve said in September that it would buy up to $40 billion of mortgage bonds every month until the labor market improved materially.

That announcement from the Fed has lowered mortgage rates. According to the Mortgage Bankers Association, applications for home loans jumped 16.6 percent in the week ended September 28 from the week before.

Wells Fargo & Co also benefited from the mortgage bonanza, posting a 22 percent increase in third-quarter profit on Friday.

But investors and analysts were concerned that JPMorgan's profitability of loans, known as its "net interest margin," contracted. The bank's stock fell as much as 1.8 percent during the day.

"The margin compression worries investors about what that means for future earnings," said analyst Marty Mosby of Guggenheim Securities.

The bank said the difference between its cost of funds and yield on assets fell to 2.43 percent from 2.47 percent in the second quarter and 2.66 percent a year earlier.

MORTGAGE MARGINS DOUBLE

The bank's profit margins on mortgages that it sells to investors, in contrast, is currently double the normal level, Dimon noted.

Analysts asked the CEO whether the mortgage refinancing wave will last until the economy strengthens enough to lift lending profits.

"We don't expect to count on high margins and mortgage origination forever," Dimon said. The refinancing trend, he added, will continue "next quarter, maybe for a couple of quarters after that, but it won't last much longer."

Dimon said he is not sure whether the latest Federal Reserve move will drive the economy. "If the economy gets better we are fine," Dimon said, explaining that the benefits would more than offset a decline in refinancing.

The Fed's buying program did boost JPMorgan's profits in fixed-income trading, which rose 33 percent, excluding adjustments for changes in the value of the bank's debt. That increase could bode well for other big investment banks due to report results over the next week, including Goldman Sachs Group Inc and Morgan Stanley.

JPMorgan's third-quarter net income was $5.71 billion, or $1.40 a share, up from $4.26 billion, or $1.02 a share, a year earlier.

Analysts had expected, on average, $1.24 a share, according to surveys by Thomson Reuters I/B/E/S. It was not immediately clear whether the analyst forecast was comparable to the reported results.

Profits at JPMorgan's investment bank, excluding accounting adjustments for changes in the value of JPMorgan debt, rose to $1.7 billion from $1.2 billion a year earlier, when the European debt crisis cast a darker shadow over the capital markets.

Dimon told analysts that risk in the remaining piece of the "London whale" derivatives portfolio was reduced by about one-third during the quarter after its management was taken over by the company's investment bank from its Chief Investment Office. Another related credit derivatives portfolio which had remained in the CIO was closed out during the quarter with a $449 million loss, bringing the total loss associated with the whale trades to about $6.2 billion.

The bank set aside an additional $684 million, before taxes, in the third quarter to cover legal settlements and judgments. A year earlier, it boosted its legal reserves by $1 billion.

JPMorgan was sued last week by the New York state attorney general over allegations that Bear Stearns, salvaged by the bank in a 2008 takeover assisted by the government, had deceived investors buying mortgage-backed securities in 2006 and 2007. Though the allegations were similar to ones already made by private investors in civil suits, the lawsuit raised concerns among analysts that there are more litigation costs to come for JPMorgan and other banks.

Dimon on Wednesday said the lawsuit was "unfair" because JPMorgan had done the Fed "a favor" by taking over a broken Bear Stearns.

JPMorgan shares were down 1.8 percent at $41.36 on Friday afternoon. Through Thursday the shares were up 27 percent this year, almost twice the rise in the Standard & Poor's 500 stock index but about three percentage points less than the KBW Bank stock index.

(Reporting by David Henry, Jed Horowitz and Lauren Tara LaCapra in New York; editing by Dan Wilchins, John Wallace and Alden Bentley)