Stocks Close Up Sharply On Earnings, Debt Talks

Stocks posted their biggest gains since March on Tuesday following a handful of upbeat corporate earnings and President Obama's positive comments on a possible debt agreement.

The Dow Jones Industrial Average surged 202.26 points, or 1.63 percent, to close at 12,587.42, its biggest point and percent gain this year.

IBM and Microsoft were the biggest blue-chip index gainers.

The S&P 500 rose 21.29 points, or 1.63 percent, to finish at 1,326.73.

The tech-heavy Nasdaq rallied 61.41 points, or 2.22 percent, to end at 2,826.52.

The CBOE Volatility Index, widely considered the best gauge of fear in the market, slid near 19. All key S&P sectors were higher, led by techs and consumer discretionary.

Stocks added to earlier gains after President Obama endorsed the debt dealproposed by the bipartisan "gang of six" senators to cut the deficit by more than $4 trillion.

Meanwhile, Republican Senator Roger Wicker said a bipartisan budget plan introduced Tuesday could pass the Senate with a majority of 60 or 70 votes.

"It certainly seems like they're trying to get a deal...and that will take one uncertainty out of the market," said Joe Saluzzi, co-manager of trading at Themis Trading. "Now it's just a question of what kind of deal it will be."

'As of right now, [stocks are] going to rally on any chance of a deal," said Saluzzi.

“Markets are swinging on a pendulum between macro and microeconomic issues,” said Nicholas Colas, chief market strategist at ConvergEx Group. “It’s hard to know which side of the fence the metronome’s going to swing.”

On the earnings front, Wells Fargo posted a higher quarterly profitas the bank dipped into funds previously set aside for bad loans.

However, Goldman Sachs reported earnings that fell far short of Wall Street estimates, sending shares lower. And Bank of America posted a loss after an $8.5 billion settlementwith mortgage bond investors.

Financials have been under pressure in the last few sessions and is the only sector in the red for the year.

"The financial sector is really the 'canary in the coal mine' and it’s the sector that will have to lead us higher and lower," said Colas. Despite the large pullback, Colas advised investors to stay cautious on the sector.

Meanwhile, IBM surged after the tech giant posted stronger-than-expected earningsafter-the-bell Monday and raised its full-year guidance, helped by strong sales of its computers and software. At least three brokerages raised their price targets on the firm.

Coca-Cola earnings topped estimates, helped by strong growth in markets outside the U.S. And Johnson & Johnson also said earnings beat estimates.

And Harley-Davidson soared almost 10 percent to lead the S&P 500 index after the motorcycle maker posted a higher-than-expected profit on strong sales and raised its forecast for shipments.

Investors will be focusing on Apple and Yahoo , which are due to report earnings after-the-bell. Shares of Apple hit a 52-week high as investors bet that the iPod maker will beat earnings estimates, as it has done for every quarter since 2004.

Cisco gained after the tech bellwether said it plans to cut its workforce by 11,500 employees as part of its plan to cut annual expenses by $1 billion and revive its business.

News Corp's Rupert and James Murdoch spoke before UK members of parliamenton the ongoing phone hacking scandal. The S&P putting the company's debt on "ratings watch negative." However, shares were still trading higher. (Read More: Man Attempts to Hit Murdoch With Foam Pie at Hearing)

Oil prices ralliedamidstrong economic data as U.S. light, sweet crude gained $1.57 to settle at $97.50 a barrel and London Brent crude climbed $1.01 to settle at $117.06. Meanwhile, gold eased off its record highs, trading below $1,590 an ounce.

Volume continued to be light with the consolidated tape of the NYSE at 3.75 billion shares, while 871 million shares changed hands on the floor.

On the economic front, housing starts rose more than expected in June to touch a six-month highand permits for future construction saw a surprise increase, according to the Commerce Department.

Lennar and D.R. Horton climbed more than 5 percent following the news.

European shares ended higherafter banks bounced back from two-year lows ahead of a crucial meeting of political leaders aimed at resolving the regional debt crisis.

Coming Up This Week:

WEDNESDAY: Weekly mortgage apps, existing home sales, oil inventories; Earnings from Altria, United Tech, Abbott Labs, Blackrock, AmEx, Intel, Qualcomm and Ebay
THURSDAY: Weekly jobless claims, Philadelphia Fed survey, money supply; Earnings from AT&T, Morgan Stanley, Nokia, PepsiCo, Freeport McMoran, Travelers, Mircrosoft, AMD and SanDisk
FRIDAY: No major econ. news expected; Earnings from Caterpillar, GE, McDonald's, Schlumberger, Verizon, Honeywell

More on CNBC.com