U.S. stocks gained on Thursday as portfolio managers and hedge funds purchased high-performing shares near the end of the quarter, but options investors placed more defensive bets on the market.

Electronics retailer Best Buy Co Inc rose 2.5 percent to $32.64, lifting retail shares, after reporting better-than-expected earnings on strong smartphone sales. The S&P retail index added nearly 1 percent.

With the market near the end of the quarter end, portfolio managers will be buyers as they execute window dressing, and hedge funds cover short positions that are under pressure.

The Dow Jones industrial average <.DJI> advanced 47.57 points, or 0.39 percent, at 12,133.59. The Standard & Poor's 500 Index <.SPX> was up 3.80 points, or 0.29 percent, at 1,301.34. The Nasdaq Composite Index <.IXIC> put on 12.39 points, or 0.46 percent, at 2,710.69.

S&P 100 index <.OEX> traders were looking for a correction, though, as the put/call ratio surged near a five-year high on Wednesday, according to Jason Goepfert, president of sentimentrader.com.

Even during the past six months, such spikes in that ratio have led to more short-term weakness than strength, he said.

Concerns over a spreading euro zone debt crisis appeared to be receding. (The) Street appears ready to put concerns about Europe's fiscal health on the proverbial back burner, said Andrea Kramer, an analyst at Schaeffer's Investment Research in Cincinnati, Ohio.

The Portuguese prime minister resigned and warned of grave consequences for the country after parliament rejected his government's latest austerity measures aimed at avoiding a bailout.

Red Hat Inc rose 16 percent to $46.36 after a brokerage upgraded the stock. The company's earnings topped estimates late Wednesday.

(Additional reporting by Doris Frankel in Chicago, Editing by Jeffrey Benkoe)