Shares of Freddie Mac/ Federal Home Loan Mortgage Corp (OTCBB:FMCC) rose about 2% Wednesday morning after the federally controlled mortgage buyer reported near-record quarterly profits. The return to profitability of Freddie and Fannie/  Federal National Mortgage Association (OTCBB:FNMA) in the last two years has largely occurred on the back of a continuing housing market recovery, marked by rising home prices and falling mortgage delinquencies. U.S. home prices are rising at the fastest pace since 2006. The S&P/Case Shiller index of property values in May showed home prices racked up a hefty 12.2 percent gain from the year before.

Freddie Mac

Freddie Mac quarterly profit is second-largest in the company’s history

Freddie Mac/ Federal Home Loan Mortgage Corp (OTCBB:FMCC) reported a $5 billion profit during the second quarter, the second-largest quarterly profit in the company’s history and the latest reminder of how surging profits at Freddie Mac/ Federal Home Loan Mortgage Corp (OTCBB:FMCC) and its larger sibling, Fannie Mae/ Federal National Mortgage Association (OTCBB:FNMA) could reshape the debate over the firms’ futures. The second-quarter earnings compare with a year-earlier gain of $3 billion and marked the seventh straight profit for the mortgage-finance company. Rising home prices, falling mortgage delinquencies, and higher loan fees have marked a sharp turnaround from a four-year period in which the company suffered heavy losses that forced it to seek massive infusions from the U.S. Treasury.

Freddie Mac will pay U.S. Treasury $4.4 billion

Freddie Mac/ Federal Home Loan Mortgage Corp (OTCBB:FMCC), which has operated under federal conservatorship since it was seized in 2008 during the financial crisis, said that based on its net worth of $7.4 billion, it will make a dividend payment of $4.4 billion to the U.S. Treasury as part of the reimbursement for its rescue aid.

While the company isn’t allowed to pay off the $71 billion in bailout money it received beginning five years ago, the latest payment will bring to $41 billion the amount of dividends it will have returned to the Treasury, leaving its net cost to taxpayers at around $30 billion.

Both companies have said they expect to remain profitable. The reversal of fortune has led speculators to bet that the companies might repay their debt to taxpayers and exit government control. Investors, led by a handful of hedge funds, have recently poured into both the common and preferred stock of Fannie Mae and Freddie Mac/ Federal Home Loan Mortgage Corp (OTCBB:FMCC) in the hope that the companies will eventually be able to buy their way out of government control.

Lifting the results were a $1.4 billion gain on interest-rate swaps that profited from the rise in interest rates during the quarter. The yield on the benchmark 10-year U.S. Treasury note, to which mortgage rates are tied, rose 1.05 percentage points in the second quarter on fears that the U.S. Federal Reserve may soon scale back its massive stimulus program, called quantitative easing.