NEW YORK (Reuters) - A wild Christmas week ride in global markets continued on Thursday as stocks rallied from significant losses to post gains for the day.

For the second consecutive session, early weakness in markets turned to strength by the time U.S. stocks closed as investors shuffled their portfolios.

“We had a very wild ride today,” said David Kelly, chief global strategist for JP Morgan Chase & Co’s asset management unit, on a conference call. “It really is not about fundamentals. There is nothing in the fundamental picture of the U.S. economy that would justify the kind of moves that we’ve seen.”

A report early in the day showed the number of Americans filing applications for jobless benefits fell marginally last week in a sign of labor market strength. But other news was dismal, including the Conference Board’s consumer confidence index dropping to a five-month low in December and earnings at China’s industrial firms falling in November for the first time in nearly three years.

Meanwhile, there is no end in sight to the U.S.-China trade war or the partial shutdown of the U.S. government.

Investors often sell assets that have done well and buy those that have done the worst, including many stocks, at the end of the quarter to “rebalance” their portfolios. Some traders also cited investors closing out short positions among the reasons for Wall Street’s late rally.

The Dow Jones Industrial Average rose 260.37 points, or 1.14 percent, to close at 23,138.82, the S&P 500 gained 21.13 points, or 0.86 percent, to 2,488.83 and the Nasdaq Composite added 25.14 points, or 0.38 percent, to 6,579.49. [.N]

Slideshow ( 3 images )

MSCI’s gauge of stocks across the globe gained 0.58 percent, rising further from near two-year lows hit earlier this week.

The late U.S. stock rally left intact other aspects of the bearish market trend that has developed of late, with a weaker U.S. dollar and lower oil prices, along with stronger demand for safe-haven government bonds, gold and the Japanese yen.International Brent crude futures settled down 4.2 percent at $52.16 per barrel after staging a big rally on Wednesday as concerns about an oil glut weighed on the market. [O/R]

U.S. Treasury prices reversed direction after falling sharply on Wednesday, with the 10-year note last rising 4/32 in price to yield 2.7845 percent. [US/]

Gold, another safe haven, was up 0.6 percent to $1,275 an ounce, around six-month highs. [GOL/]

Investors also bought yen, boosting the currency 0.27 percent versus the greenback at 111.08 per dollar. Against a basket of trading partners’ currencies, the dollar was down 0.52 percent. [FRX/]

“We have started to see the yen regain its place as the safe haven of choice,” said Lee Hardman, an analyst at MUFG in London.