Stocks rose, with the Standard & Poor’s 500 Index capping its biggest weekly gain since October, as data showing faster-than-estimated growth boosted confidence in the world’s largest economy.

Red Hat Inc. surged 14 percent as the software company raised its full-year profit and sales forecasts. CarMax Inc. declined 9.4 percent as the largest U.S. seller of used cars posted earnings that missed analysts’ estimates.

The S&P 500 added 0.5 percent to a record 1,818.32. The Dow Jones industrial average rose 42.06 points, or 0.3 percent, to 16,221.14, also an all-time high. About 9.2 billion shares changed hands on U.S. changes in the busiest trading since June as futures and options contracts expired Friday in a process known as quadruple witching, and the operator of the S&P 500 rebalanced the index in a quarterly move to adjust member weightings.

“The market is feeling somewhat confident,” said Robert Pavlik, chief market strategist in New York at Banyan Partners LLC, which manages about $4.5 billion. “It’s encouraging as an investor and consumer to see GDP get up to these levels. GDP reaching 4 percent makes you feel good about the economy and where we’re headed.”

The S&P 500 rose 2.4 percent this week, halting a string of two weekly declines and erasing a loss for the month, after the Federal Reserve’s decision to slow the pace of its stimulus boosted investor confidence that the recovery in the world’s largest economy is on course.

The Dow’s weekly advance of 3 percent was its biggest since September.

The S&P 500 has rallied 27 percent so far in 2013, on course for its best performance since 1997. Three rounds of central-bank bond purchases have helped propel the equity benchmark 169 percent higher from a 12-year low in 2009.

Announced index changes, such as the addition of Facebook Inc.’s inclusion in the S&P 500, took effect after the markets closed.

Money managers needed to buy and sell about $13.8 billion of shares as they shuffled their funds to mimic changes in the S&P 500 quarterly rebalance, according to estimates from Howard Silverblatt, a senior index analyst at S&P Dow Jones Indices in New York.

He forecast utility companies will see the biggest increase in their representation while the weighting of consumer staples will drop the most.

Red Hat surged 14 percent to $56.10. Adjusted earnings for its 2014 financial year will be $1.46 to $1.48 per share, the company predicted, up from its previous forecast of $1.36 to $1.38. Revenue may be about $1.53 billion, exceeding the average analyst estimate for $1.51 billion.

Jazz Pharmaceuticals Plc jumped 8 percent to $123.91. The maker of the narcolepsy treatment Xyrem said it will buy Gentium SpA, a rare-disease drug developer, in a deal valued at $1 billion. Gentium’s American depositary receipts added 2.8 percent to $57.22.

Textron Inc. rallied 14 percent to $37.29. The manufacturer of Cessna aircraft and Bell helicopters was near a $1.4 billion purchase of planemaker Beechcraft Corp., the Financial Times reported, citing unidentified people familiar with the matter. Dave Sylvestre, a spokesman for Textron, said the company had no comment on the newspaper’s report.

Allergan Inc. advanced 3.8 percent to $107.73. The maker of the Botox wrinkle treatment may be issued a patent for its Restasis eye drops as soon as January, Ken Cacciatore, an analyst with Cowen & Co., said in a note, citing legal consultants.

Ariad Pharmaceuticals Inc. rallied 16 percent to $6.43. The cancer-drug maker will return its only product, Iclusig, to the U.S. market after regulators approved a new prescribing and risk management plan.