By Ellis Mnyandu

Consumer prices in June rose on a continued surge in gasoline prices, adding more pressure to an economy beset with a stressed banking system and the worst housing downturn in decades.

Even so, shares of financial services companies rose as investors bid the beaten-down sector higher, with shares of Wells Fargo up more than 18 percent to lead the S&P 500's advance.

Shares of embattled mortgage giants Freddie Mac and Fannie Mae also mounted a recovery, rising 15 percent and 14 percent, respectively. Investors appeared to be pulling money from energy shares into financials, with oil prices heading lower.

"There has been some help from some of the earnings news that came late yesterday and early this morning," said Michael Strauss, chief economist and market strategist at Commonfund, in Wilton, Connecticut.

"I also think when people are dissecting through CPI, everyone knew we were going to have a problem with energy prices in the CPI number and probably with food prices."

The Dow Jones industrial average <.DJI> rose 32.81 points, or 0.30 percent, to 10,995.35. The Standard & Poor's 500 Index <.SPX> added 4.66 points, or 0.38 percent, to 1,219.57. The Nasdaq Composite Index <.IXIC> gained 9.16 points, or 0.41 percent, to 2,224.87.

Wells Fargo, the fifth-largest U.S. bank, reported better-than-expected quarterly results on Wednesday and raised its dividend despite a 23 percent decline in profit caused by a surge in bad loans.

The results offered some comfort to investors worried about the impact of the credit crisis on the financial sector.

Wells Fargo shares climbed to $24.35 on the New York Stock Exchange, while shares of Fannie Mae rose to $8.16 and those of Freddie Mac climbed to $6.15.

Standouts among financials also included shares of Bank of America , the No. 2 U.S. bank, up 7.5 percent at $19.91. Shares of JPMorgan Chase rose more than 5.7 percent to $32.80.

On Nasdaq, shares of programmable chipmaker Altera Corp led gains, a day after the company posted a stronger-than-expected quarterly profit.

(Reporting by Ellis Mnyandu; Editing by James Dalgleish)