Stocks surged more than 4 percent on Thursday as world leaders agreed to a trillion-dollar deal to fight the economic downturn and banks were allowed more flexibility to value toxic assets that have clogged up the financial system.

Underpinning the rally was optimism that the economic downturn was showing signs of moderating as data showed U.S. factory orders rose in February, breaking a six-month streak of declines. Industrial shares climbed, while Caterpillar , up nearly 10 percent, was among those giving the biggest boosts to the Dow.

The Dow Jones industrial average <.DJI> gained 305.69 points, or 3.94 percent, to 8,067.29. The Standard & Poor's 500 Index <.SPX> rose 33.23 points, or 4.10 percent, to 844.31. The Nasdaq Composite Index <.IXIC> jumped 69.90 points, or 4.51 percent, to 1,621.50.

(Reporting by Leah Schnurr; Editing by Jan Paschal)