NEW YORK - Investors yesterday set aside some of their concerns about mounting debt levels around the world and looked for bargains after a two-day slide in stocks.

Stocks turned higher late in the session after a day of back-and-forth trading. Investors have been cautious about rising government debt levels in Spain, Greece, and other countries, including the United States.

The Dow Jones industrial average rose 51 points to regain about half of what it lost Tuesday.

Investors spent much of the day looking for safety after a decision by credit rating agency Standard & Poor's Corp. to reduce the outlook on Spain's debt rating.

S&P's move came a day after another agency lowered its credit rating on Greece's government. Investors have been watchful for other signs of problems with global debt ever since a state-run company in Dubai shocked investors two weeks ago by asking its creditors for a debt reprieve.

Meanwhile, stocks again followed moves in the dollar, as they have for months. When it falls, the dollar makes commodities cheaper for foreign buyers and increases profits for U.S. companies that do business outside the United States.

The dollar has steadied this week against other major currencies, interrupting a steady drop since March. The greenback has fallen as investors take advantage of cheap financing to invest in riskier, higher-yielding assets such as stocks and commodities. Signs that the economy is improving have cut into demand for safe investments.

In recent weeks, however, investors have been shuttling between buying stocks and hoarding cash as they try to lock in some of the big gains they've amassed in stocks since a rally started in March.

As the end of the year approaches, many investors have been building up defensive investments such as Treasuries. The uncertain tone in the market, combined with light trading volume, has made for choppy trading, which analysts expect to continue through the rest of the year.

The Dow rose 51.08, or 0.50 percent, to 10,337.05 after falling 104 on Tuesday. The S&P 500 index rose 4.01, or 0.37 percent, to 1,095.95, while the Nasdaq composite index rose 10.74, or 0.49 percent, to 2,183.73.

The ICE Futures US dollar index, which tracks the dollar against other major currencies, fell 0.3 percent.

Investors grew concerned that heavy debt loads in countries such as Greece and Spain as well as the United States and Britain could signal that the threat of defaults and higher borrowing costs could upend a nascent global economic rebound.

Hugh Johnson, chairman and chief investment officer of Johnson Illington Advisors L.L.C., of Albany, N.Y., said signs of improvement in the economy were disrupting advances in the markets because traders predict the Fed will be forced to raise interest rates sooner than expected to keep inflation in check.

Advancing stocks narrowly outpaced those that fell on the New York Stock Exchange yesterday.