Stock Spotlight: Major bank stocks have been socked by credit market problems. But analysts believe some banks have been unfairly punished.

NEW YORK (CNNMoney.com) -- The past five years were heady times for financial services companies as they lent money out at low interest rates to home buyers and corporations alike and watched profits soar.

Bank stocks climbed as the firms cashed in on a booming housing market. Strong merger activity, led by private equity firms borrowing money to finance deals, also boosted demand for loans.

But when it became apparent a few months ago that many banks handed out too much money too easily and that some borrowers weren't able to pay back their loans, the market panicked.

Companies like Countrywide (Charts, Fortune 500), a big mortgage lender that had lots of subprime borrowers -- borrowers with less-than-perfect credit -- were hit the hardest, but even those with less exposure to the subprime housing market weren't spared by the sell-off.

And now, the market is worried that the corporate debt market could also be heading into trouble, fueling further fears of a looming banking crisis.

But is this already priced in the shares of many bank stocks? The recent panic may have created some great values for investors.

Investment banks tank

Among the first victims of the subprime fallout was investment bank Bear Stearns (Charts, Fortune 500), which was caught holding securities that were backed by the risky mortgages.

"What's got investors worried is that this is beyond subprime," said Jaime Peters, an analyst with Morningstar. "As a result it's harder to fund bonds and commercial businesses are also having a harder time getting loans."

Investors are concerned that 2007 earnings will take a big hit because of the subprime problems.

Borrowing fuels economic growth across all sectors and has been a big part in the private equity-fueled M&A boom. So if the credit spigot shuts off, the whole economy and financial markets could suffer.

In the same way that soaring home prices justified banks' willingness to fund riskier loans over the past five years, the tanking mortgage and corporate bond markets are now making firms a lot more reticent about loaning money.

Goldman has taken a smaller hit than some of its investment banking rivals because it avoided securities backed by subprime mortgages. While the subprime market was booming, that didn't seem like a wise move, but in retrospect the decision seems prudent.

Of course, Goldman, like its rivals, could face more problems if the corporate debt and merger markets grind to a halt since that would lead to a big drop in fees.

That's because the company's management saw the subprime mess coming and sold much of its high-risk portfolio in 2006. It also tightened its lending standards.

Credit fallout = cheap stocks?

To be sure, if the credit market deteriorates further, bank earnings could take a big hit. But investors may be overestimating how bad the problems will be for some banks.

"I think the market is over-discounting bank stocks and they're very attractive at current levels," said Christopher Bingaman, portfolio manager at Diamond Hill Financial Long-Short Fund, which owns many bank stocks. He said diversified companies like Wells Fargo and Citigroup, which he owns in the fund, are good bargains.

Wells Fargo is trading at 12.6 times its expected 2007 earnings, near historical lows, while Citigroup is valued at only 10.3 times earnings. So now might be a good time to scoop up the largest banks while they are relatively cheap.

"People need to be looking at the firms that can weather the subprime problems the best," said Morningstar's Peters. "When the problems are done, these companies are going to be the largest players in a less competitive market. They're going to be even more profitable."

Peters thinks the best value in the sector is Bank of America, which is currently trading at less than 10 times earnings estimates for this year. The company has had its share of credit-related problems, but Peters thinks they can be offset by the surging growth in its retail and wealth management divisions.

Peters said JPMorgan Chase, which is valued at about 9 times 2007 earnings estimates, is undervalued as well. He points out that, despite mortgage problems, revenue growth has still been strong.

And some investors, if they are willing to tolerate the risk, might want to look at some of the troubled investment banks. Lehman Brothers, for example, is trading at such a low multiple -- just 7.6 times this year's earnings estimates - that it's widely considered to be a takeover target.

So even though it may seem like sky is falling for bank stocks, long-term investors should look for bargains.

None of the Morningstar own shares of the companies they cover, nor does Morningstar do business with any of the firms. The mutual fund that Bingaman manages owns shares of Wells Fargo and Citigroup.