Stocks recovered from opening losses to post modest gains on Tuesday as housing and consumer confidence data fueling hopes a recession was easing offset concerns that major banks may need to raise more money.

Citigroup Inc is talking to the U.S. government about its capital levels after receiving early results of its stress test, but if it needs more capital, it does not expect to get it from the government, people familiar with the matter told Reuters.

The Wall Street Journal reported U.S. regulators have told Bank of America Corp and Citigroup they may need to raise more capital. The shortfall amounts to billions of dollars at BofA, the newspaper said, citing people familiar with the bank, adding that it is likely the U.S. Federal Reserve will have determined other banks might also need more capital.

Encouraging data helped stocks pare losses, as a report showed prices of single-family homes fell in February, but the rapid pace of decline had slowed, while consumer confidence rose to its highest this year with some expectations the recession is reaching a bottom.

What it says is that as of now the rate of decline is decelerating, said Jim Awad, managing director at Zephyr Management in New York, speaking about the housing numbers.

Those are the green shoots that everybody's been talking about but you still have a lack of clarity on the timing and parameters of the recovery.

The Dow Jones industrial average <.DJI> added 12.50 points, or 0.16 percent, to 8,037.50. The Standard & Poor's 500 Index <.SPX> edged up 0.93 points, or 0.11 percent, at 858.44. The Nasdaq Composite Index <.IXIC> put on 3.07 points, or 0.18 percent, to 1,682.48.

The broad S&P 500 is up nearly 26 percent from March's bear market lows on increased optimism over the state of banks and signs the recession may be easing.

The KBW Bank index <.BKX> slid 2.1 percent, Bank of America tumbled 6 percent at $8.39, and Citigroup lost 3.3 percent to $2.96.

Worries over the economic impact of the threat of a flu pandemic also nagged, as New Zealand and Israel confirmed cases of swine flu, making them the latest countries hit by a new strain that has killed up to 149 people in Mexico.

International Business Machines Corp was a bright spot for the Dow, up 1.6 percent at $101.56 after its board approved a 10 percent increase in its dividend and authorized a stock buyback.

(Reporting by Leah Schnurr)