The S&P 500 hit its highest level in nine months on Thursday as the U.S. economy showed further signs of recovery and optimism grew that a Greek bailout deal would be agreed next week.

Equity indexes continued to trade in tight ranges, with the S&P 500 facing strong resistance in the 1,355-1,360 area.

U.S. labor, manufacturing and housing data suggested sustained momentum in those key economic sectors and hinted the recovery continues at a steady pace.

We're getting this incredible flow of good data, said Jim Paulsen, chief investment officer at Wells Capital Management in Minneapolis. It's hard not to want to step into the market.

Greece expects to get approval on Monday from euro zone finance ministers to begin a debt swap with private bondholders, the spokesman for the Greek government said, moving closer to averting a disorderly default by Athens.

People are increasingly of the opinion that although Europe will continue to have flare-ups, it's not likely to become a calamity for the world economy, Paulsen said.

The Dow Jones industrial average <.DJI> added 118.29 points, or 0.93 percent, to 12,899.24. The S&P 500 Index <.INX> gained 13.29 points, or 0.99 percent, to 1,356.52. The Nasdaq Composite <.IXIC> rose 36.77 points, or 1.26 percent, to 2,952.60.

The S&P hit its highest level since May while the Nasdaq traded near its highest since December 2000 and the Dow was near a four-year high.

Bank shares rose, brushing off a warning from Moody's about possible downgrades to the credit ratings of 17 global and 114 European financial institutions.

Among the ratings threatened were those of Goldman Sachs , up 1.5 percent at $114.82, and Bank of America , up 3.2 percent at $8.03.

The KBW bank index <.BKX> rose 1.8 percent.

Apple shares, which largely dictated the direction of Wednesday's stock market, reversed early losses to trade up 1.2 percent at $503.

Trading in Apple topped 24 million shares, above its 19.5 million average in the past 10 days.

According to a Chinese newspaper website, some cities in China have asked retailers to take Apple iPad tablets off shelves in connection with a legal battle between a Chinese technology firm and Apple over trademark issues.

(Reporting by Rodrigo Campos; Editing by Kenneth Barry)