Bill Ackman's Pershing Square Capital revealed nearly 10% stakes in Fannie Mae and Freddie Mac and said it may hold discussions with both mortgage lenders. 

The activist hedge fund said in a filing with the Securities and Exchange Commission the shares of both companies are "undervalued" and represent an "attractive investment."

Pershing disclosed a 9.77% stake in Freddie and a 9.98% holding in Fannie. 

The New York-based fund said it "may engage in discussions with management, the board, other stockholders" in light of an offer made Wednesday by Fairholme Capital Management to buy the two mortgage giants' mortgage-backed securities businesses. 

Fannie and Freddie are both government-sponsored entities that purchase mortgages from lenders, package them as securities and then insure them against default. Together, they guarantee about two-thirds of all American home loans, according to a recent report from Reuters

Shares of both GSEs rallied more than 10% in mid-morning trading on the over-the-counter market Friday. Both stocks have posted gains of more than 1000% for the year as the housing market has rebounded and the U.S. government has eyed an eventual exit from the companies. 

Pershing's plans for the lenders wasn't immediately clear, and representatives for the fund declined to comment on the subject.

Fannie spokesperson Andrew Wilson and Freddie representative Brad German declined to comment on Pershing's acquisition. Stefanie Johnson, a communications official at the Federal Housing Finance Agency that supervises the two companies, also declined to comment. 

Follow Adam Samson on Twitter @adamsamson.