Stocks gained on Thursday as banks, builders and mortgage-related shares rose before a White House announcement about a plan to slow the wave of home foreclosures that has rattled investors.

Countrywide Financial Corp, the largest U.S. mortgage lender, and Fannie Mae, the biggest source of mortgage finance, rose before President George W. Bush was to outline a plan that would temporarily hold interest rates steady for subprime borrowers who could not afford to stay in their homes otherwise. Bush was set to speak at 1:40 p.m.

The big cause of concern has been not knowing what kind of losses the banks will take, said Scott Wren, senior equity strategist at A.G. Edwards & Sons in St. Louis. If we can stabilize the underlying subprime exposures, it will be favorable for financials.

The Dow Jones industrial average .DJI was up 41.38 points, or 0.31 percent, at 13,486.34. The Standard & Poor's 500 Index .SPX was up 5.01 points, or 0.34 percent, at 1,490.02. The Nasdaq Composite Index .IXIC was up 13.40 points, or 0.50 percent, at 2,679.76.

On the downside, retailers fell after Target Corp said its fourth-quarter earnings estimate could be at risk, hurting sentiment about the holiday shopping season.

Target stock was down 7.6 percent to $55.63. J.C. Penney Co Inc shares fell 5.7 percent to $43.26.

Fannie Mae shares gained 2.4 percent to $37.02. Shares of Countrywide, which have plunged 73 percent this year in the mortgage meltdown, were up 8.6 percent to $11.31.

Shares of home builder Lennar jumped 8.5 percent to $17.66.

Builders also got a boost from Toll Brothers after the largest U.S. luxury home builder reported a smaller-than-expected loss. Toll's shares were up 6.7 percent at $22.11. The Dow Jones home builder index .DJUSHB advanced 5.9 percent.

American International Group shares were up 3.9 percent to $60.43. The blue-chip insurer extended its rally for a second day after making positive comments about its subprime exposure.

(Editing by Kenneth Barry)