Despite being one of the best performing stocks in the S&P 500 over the past two years, Bank of America (BAC 1.70%) still can't catch a break in the court of public opinion. The biggest reason why? The bank's near constant stream of public relations nightmares, most of which stemming from problem mortgage loans.

We're talking about robo-signed foreclosures, multibillion dollar lawsuits, poorly implemented checking account fees, and everything Occupy Wall Street.

It gets worse
In its 2013 annual report, Bank of America put aside over $13 billion in reserves for future expenses related to bad mortgages originated during the Countrywide heyday before the financial crisis. Countrywide sold mortgages to Fannie Mae and Freddie Mac with certain promises related to the quality of those loans. When it turned out those promises were not true, the bank is now obligated to buy back those mortgages. 

That's worth repeating. The crisis hit over five years ago, and just three months ago the bank still thinks that representation and warranty expenses will exceed $13 billion. That's after the multi-billion dollar settlements already finalized and on the books.

And that doesn't include other, undisclosed reserves for ongoing lawsuits pending or already filed by the Justice Department.

Darkest before dawn? Or perhaps the sun is already above the horizon
And yet, almost in spite of all the bad press and megareserves, Bank of America continues its steady march higher and higher in the market. What gives?

Well, most obviously is that net income has rebounded strongly. Check out this chart of the bank's quarterly net income over the past five years. After the tumult and chaos of 2009-2011, quarterly performance has been consistent and improving since 2012.

BAC Net Income (Quarterly) Chart

In fact, net income for the quarter ended December 31, 2013 is 73% higher for the quarter ended December 31, 2011. That's not bad.

Good banks are boring banks. They are predictable and reliable. Bank of America has made great strides to simplify its operations and to be more boring. Its working, and you can see it in the stability of the bank's earnings.

But there is a bigger driver than that
If we take a step back and really boil down Bank of America's problems into one primary component, we'd be left with a giant boiling pot of bad loans.

Over the past two years, and especially over the past few quarters, the bank's loan quality has made dramatic improvements. For the long term future, this improvement is even more significant than the improvement in earnings.

Breaking down Bank of America's loan quality data, we look at a few key metrics.

First is the level of non performing loans on the books. These are the worst of the worst -- loans that are no longer accruing interest, loans more than 90 days past due, and loans in foreclosure. As the chart below shows, this metric increased dramatically after the real estate bubble popped, but in recent quarters has been declining consistently.

Chart Source: BankRegData.com

The improvement in non-performing loan levels is also seen in the bank's charge off data. Charge offs are losses the bank accepts on loans determined to be beyond repair. The bank shows the charge off as a loss on the income statement and then reduces the value of that loan on the balance sheet. If a non performing loan is a loan in intensive care, then a charged off loan is buried in the graveyard.

At the end of the first quarter in 2011, Bank of America charged off 2.85% of the average total loans for the quarter. That number has gone down every quarter but one since, and was just 0.96% for the fourth quarter of 2013.

Looking forward
The stock market though doesn't care so much about what happened yesterday; what matters is what happens tomorrow.

To evaluate Bank of America's future levels of non-performing loans and charge offs, we look to the level of loans that are currently past due but not quite as severely. Generally this means loans that are 30-89 days past due.

Chart Source: BankRegData.com

The story is largely the same. After a very abrupt spike in medium term past due loans in 2008, the bank has made great improvements to shore up these problems.

In this light it certainly appears that Bank of America has indeed turned a corner. Bad loans were the central reason for all of the bank's woes, and those bad loans have nearly been digested. With billions already in reserve to manage the last of these problems, Bank of America appears poised to finally leave the ill will of the financial crisis behind. And after five years, its about time.