Yesterday morning, July 19, the bank posted the largest quarterly loss in its history, thanks to a nasty combination of problems. Revenue continued to slide, and losses from defective mortgages continued to climb.

Revenue, including mortgage costs, plummeted to $13.5 billion—a 50.2% drop from the second quarter of 2010. Even excluding those mortgage costs, revenue still fell by 10% from the second quarter of 2010, and declined 2.2% from the first quarter of 2011.

Earnings for the second quarter, including these mortgage-related charges, came to a loss of 90 cents a share. Excluding those charges, the bank reported net income of 33 cents a share. (Bank of America reported earnings of 27 cents a share in the second quarter of 2010.)

Bank of America’s mortgage problem is different from that faced by many of its big-bank peers.

At Citigroup, for example, the bank had to put aside reserves for mortgages that might default. Those reserves came out of earnings, but recently—as the rate of credit losses has fallen—those reserves have started to add back into earnings.

At Bank of America, though, the big problem has been lawsuits from investors in mortgage-backed assets, and from bond issuers who have sued the company claiming that Bank of America—or more specifically the mortgage business, Countrywide Financial, it bought in 2008—used false or misleading information in writing mortgages that later defaulted.

On June 29, Bank of America told investors that it would book more than $20 billion this quarter in charges from faulty mortgages. The $20 billion wound up breaking down this way:

$8.5 billion for a June settlement with a group of big investors who had bought mortgage-backed assets that went sour;

$5.5 billion to cover future claims;

and $6.4 billion for a number of other charges.

Not all the bank’s businesses turned in bad quarters. Revenue from sales and trading climbed by $666 million. Investment banking fees rose 28%.

But the mortgage losses overshadowed everything, because they raised questions about the bank’s plan to raise its dividend by the end of 2011, as well as the possibility that the bank would need to raise capital.

CEO Brian Moynihan said he didn’t think the bank needed to raise capital: It finished the quarter with a common equity ratio of 8.23%.

But under the proposed Basel III rules, the bank will need to achieve a 9.5% ratio of capital to risk-weighted assets between 2013 and 2019. According to guidance from the bank in June, that would mean the bank would have to either raise $50 billion in capital or reduce the total of risky assets on its books.

Bank of America is reported to be considering the sale of all or part of its $21 billion stake in China Construction Bank. That would raise capital and reduce the bank’s assets simultaneously.

I think the bank has more quarters of big mortgage-related charges ahead of it. And the biggest US bank by assets will have to sell some of those assets and raise capital.

I certainly would stay away from these shares in the current crisis environment, when Wall Street analysts are asking nasty questions along the lines of, "how much more capital will you have to raise if Greece defaults, and the credit-rating companies downgrade the US credit rating?"

But at some point, these shares become cheap enough to buy—as a trade—for a recovery in the bank’s core businesses. At the moment, I’d peg that price level at about $8 a share.

Full disclosure: I don’t own shares of Bank of America in my personal portfolio. The mutual fund I manage, Jubak Global Equity Fund (JUBAX), may or may not now own positions in any stock mentioned in this column. The fund did not own shares of Bank of America as of the end of March. For a full list of the stocks in the fund as of the end of March, see the fund’s portfolio here.