Countrywide Financial (CFC) reported a 27% rise in second-quarter profits, as the big mortgage banker continues to make money despite a slowdown in the housing market.

The mortgage bank's earnings were fueled by a big gain from the sale of loans and securities, mostly mortgage-backed securities. Earnings at Countrywide rose even as its volume of home loans funded in the quarter dropped by 3%.

In the quarter, the California-based lender earned $722 million, or $1.15 a share, up from $566 million, or 92 cents a share. Revenue surged 30% to $3 billion.

Earnings and revenue both exceeded analysts expectations. The Thomson Financial consensus had Countrywide earning $1.14 a share on revenue of $2.93 billion.

Revenue from the sale of loans and securities rose 33% to $1.53 billion. Net interest income, the revenue derived from its lending and deposit operation, rose 28% to $690.5 million. Fees from servicing the home loans in Countrywide's giant mortgage servicing portfolio rose 18% to $1.2 billion.

Even though Countrywide is making fewer loans because of the housing slowdown, its mortgage servicing business continues to grow. In the quarter, the firm's loan servicing portfolio grew 24% to $1.2 billion. Mortgage servicing, collecting payments and fees for other mortgage lenders, has become a bigger portion of Countrywide's business.

Countrywide also raised its full-year earnings guidance. The firm now expects to earn between $4 and $4.80 a share. The analyst consensus estimate has Countrywide earning $4.43 a share this year.

Shares of Countrywide in premarket trading were up 31 cents to $39.66

More from Stocks

Dow Gets Swept Into Nasty Reversal Even as Nasdaq Posts New Record

Dow Gets Swept Into Nasty Reversal Even as Nasdaq Posts New Record

REPLAY: Jim Cramer on Fed Rate Hikes, Oil Prices and Starbucks Worries

REPLAY: Jim Cramer on Fed Rate Hikes, Oil Prices and Starbucks Worries

What Will GM Do With Cruise -- and Is Its Stock Worth $55?

What Will GM Do With Cruise -- and Is Its Stock Worth $55?

3 Must Reads on the Market From TheStreet's Top Columnists

3 Must Reads on the Market From TheStreet's Top Columnists

This Should Be Your Retirement Savings Plan When the Stock Market Crashes

This Should Be Your Retirement Savings Plan When the Stock Market Crashes