U.S. stocks rallied for a fourth day on Thursday after JPMorgan's strong results fed growing optimism about the quarterly earnings season and technology shares rose in anticipation of more good news.

Gains in International Business Machines Corp helped the market shake off its earlier malaise. The broad S&P 500 extended the week's gains to tally its best four days since March as stocks recovered from 12-year lows.

IBM provided the Dow's biggest boost ahead of earnings that beat expectations after the market closed. The bellwether also raised its outlook for the full year, sending its shares up 1.6 percent to $112.41 in extended trade.

IBM closed the regular session up 3.2 percent at $110.64.

As the market rallies, implicit in that is the expectation that we'll continue to see a recovery in corporate profits, said Dean Curnutt, president of Macro Risk Advisors in New York.

JPMorgan Chase & Co continued the week's streak of positive results, posting a strong quarterly profit, but warning of deteriorating consumer credit. The bank's stock was kept under water for most of the day, edging down 0.4 percent to $36.13 on the New York Stock Exchange.

Much better-than-expected results from Goldman Sachs and Intel set the tone early in the week amid expectations of a lousy second quarter marked by falling revenues and cost cuts.

S&P 500 UP 7 PERCENT FOR THE WEEK

The Dow Jones industrial average <.DJI> rose 95.61 points, or 1.11 percent, to 8,711.82.

The Standard & Poor's 500 Index <.SPX> gained 8.06 points, or 0.86 percent, to finish at 940.74, and has climbed 7 percent for the week so far. The Nasdaq Composite Index <.IXIC> advanced 22.13 points, or 1.19 percent, to 1,885.03.

Results from Web search leader Google Inc also came in better than expected after the bell, but the stock was off 2.4 percent at $432.19 in extended trade. During the regular session, Google had recovered from earlier losses to gain 1 percent and close at $442.60 on Nasdaq.

Comments from leading economist Nouriel Roubini further boosted sentiment after he said the worst is past in terms of economic and financial conditions.

Shares of Qualcomm Inc lifted the Nasdaq after RBC Capital Markets started coverage of the cellphone chip supplier with an outperform rating. Qualcomm gained 1.4 percent to $46.72.

On the economic front, government data showed the number of U.S. workers filing new claims for jobless benefits fell last week to their lowest level since January, but the seasonally adjusted data was amplified by earlier auto industry plant shutdowns.

A separate report showed factory activity in the U.S. Mid-Atlantic region shrank for the 10th consecutive month in July, a worse-than-expected decline that raised questions about the speed of the economic recovery.

Volume was moderate on the New York Stock Exchange, with 1.18 billion shares changing hands, below last year's estimated daily average of 1.49 billion, while on the Nasdaq, about 2.11 billion shares traded, below last year's daily average of 2.28 billion.

Advancing stocks outnumbered declining ones on the NYSE by a ratio of about 7 to 3, while on the Nasdaq, about eight stocks rose for every five that fell.

(Editing by Jan Paschal)