Commodity prices took a hit on Thursday, but North American stock markets managed to post gains, including a third consecutive day of growth for Toronto’s benchmark index.

The S&P/TSX composite index finished the day up 364.65 points, or 3.73%, at 9,856.21.

The materials group displayed the most strength, gaining 5.68% even though gold futures erased earlier gains and closed lower. Gold for December delivery fell US$15.50, or 2.1%, to end at US$738.50 an ounce on the Comex division of the New York Mercantile Exchange.

The sub-gold index rose 4.6%.

Shares of Barrick Gold Corp. gained 7.1% to close at $29.88 despite reporting a 26% drop in third-quarter profit, which came in at US$254 million.

Agrium Inc. shares enjoyed a gain of more than 10% for a second consecutive day, rising $4.50 to close at $47.50. Potash Corp. shares rose 6.81% to finish at $104.64.

The energy group on the TSX also defied commodity price trends, gaining 5% despite a downward shift in oil futures. Crude for December delivery fell US$1.54, or 2.3%, to close at US$65.96 a barrel on the New York Mercantile Exchange.

Driving gains among energy companies was Canadian Natural Resources Ltd., up 7% to $62.34. EnCana Corp. shares rose 5.9% to end at $62.70, and Husky Energy Inc. shares soared 9.2% to close at $35.77.

The financials group rose 2.54%, led by gains of nearly 5% for shares of both Royal Bank of Canada, which closed at $47.58 and the Bank of Nova Scotia, which ended at $40.80. Also higher was Canadian Imperial Bank of Commerce, closing at $56.00, up 3.7%.

Canaccord Capital Inc. dipped 2% to $5.73 after it announced it is laying off about 10% of its staff and cutting executive salaries.

Shares of asset manager Sprott Inc. gained 6.7% after the company posted third-quarter earnings of $3.7 million, up from $3.5 million a year earlier, despite financial-market turmoil. The shares closed at $3.50.

The Canadian dollar continued its recovery with a half-cent gain against the American dollar, closing at US82.10¢.

News that the decline in U.S. GDP during the third quarter was smaller than expected helped markets in New York rally Thursday.

A gain on the Dow Jones industrial average marked the blue-chip index’s sixth daily gain for the entire month of October. It finished 189.73 points higher, or 2.1%, to 9,180.69.

The Nasdaq composite index rose 41.31 points, or 2.5%, to 1,698.52, and the S&P 500 increased 24 points, or 2.5%, to 954.09.