The financial sector as a whole hasn't been a great performer recently. Many banks have underperformed the S&P 500 as investors fear a recession leading to a rise in defaults, as well as a slowdown in consumer spending.

However, for patient long-term investors there are some attractive opportunities in the banking space. Here are two in particular -- both of which are cornerstones of my own stock portfolio -- that are trading at cheap valuations and could deliver market-beating total returns in the years ahead.

A great play in a rising rate environment

Bank of America (BAC 1.70%) has seen its margins increase dramatically as interest rates rise. In fact, the bank's net interest income in the fourth quarter was 29% higher year over year. However, the stock trades for a low valuation of just over 1.1 times book value and less than 11 times forward earnings, and one of the biggest reasons is a fear that a recession could lead to widespread consumer defaults.

To be sure, banks are seeing a bit of an uptick in net charge-offs, but they're still well below historical average levels. Meanwhile, Bank of America added more than 1 million net new checking accounts in 2022, saw $115 billion in net inflows to investment accounts, and grew its digital sales (which make the business more efficient) by 22% year over year.

An ideal scenario for Bank of America would be a combination of an elevated interest rate environment and a so-called "soft landing" for the economy where a recession is avoided, and consumer demand and credit quality stays strong. Recent data shows this is more of a possibility than previously thought, but even if not, Bank of America is a cheap bank stock that should deliver excellent long-term returns regardless of what the economy or stock market does over the next few years.

Stellar growth and several big catalysts

Banking disruptor SoFi Technologies (SOFI 4.55%) recently released its fourth-quarter earnings, and to say the numbers were impressive would be a massive understatement. Even in the challenging economic climate, SoFi managed to add 480,000 new members to its ecosystem -- the second most in a single quarter in its history.

The number of financial services products (mainly bank accounts, credit cards, and brokerage accounts) used by SoFi members increased by 60% year over year. Not only does this show tremendous traction in SoFi's user-friendly platform, but this is significant for two big reasons.

First, growth in the banking side of its business gives SoFi a low-cost funding source for its lending operations. SoFi has impressively grown its deposit base from zero at the start of 2022 (when it got a banking charter) to more than $7.3 million now. Second, having a massive banking customer base creates a natural marketing funnel for its lending business. SoFi is one of the leaders in student loan refinancing, and with loan payments set to finally resume this year, having millions of new customers to cross-sell lending products to could be a major growth catalyst.

To be sure, SoFi's business isn't profitable yet, but with 60% year-over-year revenue growth that's OK. Plus, even after a recent rebound, SoFi trades for just 1.03 times its book value -- that's cheaper than Bank of America, Wells Fargo, and JPMorgan Chase despite none of those banks having anywhere close to SoFi's growth momentum. If the bank can achieve profitability by the end of 2023 like management thinks it can, this fintech that encourages people to "break up with bad banking" could have an extremely bright future.

These banks could deliver market-beating performance

Banks are often considered to be boring businesses, but they have the potential to produce excellent long-term returns. In fact, Bank of America has beaten the S&P 500's total returns over the past decade, and that's despite the recent downturn in its stock price. These are the two largest bank stock positions in my own portfolio, and I plan to continue to build my positions over time.