Stocks added to gains reached on optimism over prospects of a Greek bailout package, despite several reports of economic weakness, but the gains weren't enough to erase a month of losses.
The Dow Jones Industrial Average gained more than 100 points and ending lower for fourth straight week on Friday.
Most Dow components gained, with Intel among the lead performers. The chipmaker unveiled a new category of laptops its calling Ultrabooks at a trade show in Taiwan.
Cisco also climbed after the tech bellwether said it has collaborated with SAP to in order to deliver enhanced business intelligence solutions for enterprises.
TheS&P 500 and the Nasdaq also rose. The CBOE Volatility Index, widely considered the best gauge of fear in the market, rose above 16.
All key S&P 500 sectors gained, led by technology, health care and energy.
Stocks initially got a boost from news some officials in Germany will allow Greece to restructure its debt.
That news also pushed the euro to a three-week high against the dollar and oil prices also gained. U.S. light, sweet crude rose 2 percent Tuesday to $102.70 a barrel; for the month, sweet crude fell 9.86 percent. In London, Brent crude climbed 1.79 percent to $116.73. For the month, Brent fell 7.28 percent.
Precious metals fell, as gold 0.03 percent to settle at $1,535.90 an ounce. For the month, gold fell 1.29 percent. Silver rose slightly on Tuesday to settle at $38.30 an ounce, but fell more than 21 percent for the month.
The brighter performance for stocks on the last day of the month is unlikely to turn around the market's negative performance in May. As of Friday, the Dow was down nearly 3 percent, the S&P 500 was down 2.4 percent, and the Nasdaq was down 2.7 percent. All major indices remain higher for the year, however.
If history is a guide, stocks won't turn around in June. The Dow has fallen for the last six Junes, and has been up only twice since 2000. Overall, the market has been down in June in the last four years.
Several key economic reports are expected later this week to reveal more about the state of the nation’s manufacturing output and jobs growth, said Phil Orlando, chief equity market strategist at Federated Investors.
The numbers are unlikely to show the economy or jobs growth gaining strength, Orlando said, but he does believe that many of the headwinds facing the U.S. are transitory and will become less of a factor as the year goes on.
These headwinds include the supply disruptions from the Japan earthquake, severe April weather, and the debate over the nation’s debt ceiling, Orlando said. The low point in quarterly growth was probably in 1.8 percent gain of the first quarter, he said.
“We’ll see something closer to 4 percent by the back end of the year,” Orlando said. In his weekly outlook the strategist also noted the S&P 500 “will approach or exceed” 1,450 by year end.
On the tech front, Nokia tumbled after the handset maker cut its sales outlookand said it expects net sales from its products and services to be far worse than initial projections.
Apple, meanwhile, gained after news CEO Steve Jobs would offer the keynote speech at the iPhone maker's annual worldwide developers conference on June 6. The company will be unveiling several software developments at the conference.
Dell advanced after the tech giant announced it is searching for acquisitions to strengthen its data center business.
Meanwhile, Dreamworks Animation slipped after a disappointing opening weekend for Kung Fu Panda 2. Also, Caris cut its rating on the firm to "above average" from "buy."
Goldman Sachs gained after JPMorgan upgraded the investment firm to "overweight," citing overreaction to a report by a U.S. Senate panel and prospects for future business. Goldman was also in the news on Tuesday after a Wall Street Journal report that the bank had given Libya a chance to be a big shareholder during the financial crisis.
In M&A news, Ashland jumped to a 52-week high after news the company would pay about $3.2 billion for International Specialty Products.
Massey Energy gained despite pressure from shareholdersto block the company's purchase by Alpha Natural Resources, saying the deal would allow the coal company's directors to avoid responsibility for the April 2010 mine explosion that killed 29 miners. The shareholders have asked a judge to block the acquisition.
And Fortis agreed to acquire Central Vermont , the largest electric utility in Vermont, for about $700 million. Central Vermont's shares skyrocketed more than 40 percent.
Anadarko Petroleum rose after Wells Fargo said it expects the stock to rise once the oil company is able to fill "pent-up demand." The brokerage raised its price target on the stock to about $100 a share from $84.
Meanwhile, solar stocks surged after reports that Germany planned to close all of its nuclear reactorsby 2022. LDK Solar , GT Solar and and First Solar all gained.
Fertilizer companies gained after a report by Citigroup that said some companies will benefit from fewer Chinese exports and a delay in U.S. plant. The brokerage upgraded Mosaic and Potash to "buy" from "hold," and raised Mosaic's price target to $85 a share from $84 and Potash's to $67 a share from $61.
Fertilizer company Agrium also gained.
On the IPO front this week, Sabre Industries plans to offer 7 million shares at $12 to $14 each to raise about $91 million. The engineered products provider is expected to trade on the Nasdaq under the symbol "SABR."
One economic report after another pointed to weakness in the U.S. economy Tuesday after the Conference Board's May reading on consumer confidencefell to a six-month low at 60.8 from 66.0 in April. Economists surveyed by Reuters had expected the index to rise to 66.5.
Also, the Chicago Purchasing Managers Index fell to 56.6 in May from 67.6 in April. Economists surveyed by Reuters had expected the index to fall to 62.6.
And prices for U.S. single-family homes sank to a new low for the year, providing clearer evidence of a double-dip in housing. The S&P/Case Shiller composite index of 20 metropolitan areas fell 0.2 percent in March from the month before, which was in line with expectations.
Investors are also looking ahead to the government's monthly nonfarm payroll figures at the end of the week. The widely-watched jobs report is expected to show nonfarm payrolls increased by 180,000 jobs in May, according to a Reuters survey, down from the 244,000 created in April. The May unemployment rate is projected to slip to 8.9 percent, after the rate gained to 9.0 percent.
Asian stocksgained on a more upbeat outlook from manufacturers in Japan.
In Europe, shares ended higher lifton expectations there would be a bailout package for Greece, and despite the fact German unemployment fell less than expected in May.
On Tap This Week:
WEDNESDAY: Mortgage applications, Challenger job-cut report, ADP employment report, ISM manufacturing index, construction spending, auto sales; D9: All Things Digital Conference.
THURSDAY: Chain store sales, jobless claims, factory orders, natural gas inventories, oil inventories, money supply.
FRIDAY: Non-farm payroll report, ISM non-manufacturing index; Wal-Mart shareholder meeting.
More on CNBC.com