Big winners on Wall Street are yesterday's dogs

FSLR v SP 500
Click for more market data.

The stock market is on track to end a bumpy quarter with respectable gains, but there are two companies that have staged dramatic comebacks.

First Solar was the best performing stock among the S&P 500, gaining more than 65% over the past three months.

It's a remarkable rebound for the leading maker of solar panels, which saw its stock fall 12% in the first quarter.

First Solar (FSLR) wowed investors in April with a surprisingly bullish outlook for the year. The stock shot up 43% in one day, after First Solar said it expected profits to be 28% above previous forecasts this year on healthy sales growth.

The solar industry has been in a slump as low-cost imports from China have depressed prices. But solar panel prices have stabilized and First Solar said demand is ramping up.

First Solar wasn't the only underdog to make a comeback.

J.C. Penney (JCP) shares gained more than 12% during the quarter, recovering about half of their first quarter losses.

The retailer ousted CEO Ron Johnson in April, after his controversial turnaround plan failed to show results. J.C. Penney publicly apologized for the changes, and ran an ad on its YouTube channel that practically begged customers to come back.

Related: Top hedge fund manager bets on a return to normal markets

In business for more than 100 years, J.C. Penney has been swimming in red ink as it struggles to compete with online retailers. But the company has been strengthening its finances in an effort to mount another turnaround. It scored a $1.75 billion loan from Goldman Sachs (GS) in April.

Other top performers in the quarter include popular momentum stocks, such as GameStop (GME), Micron Technology (MU) and Best Buy (BBY).

Best Buy has also been on a turnaround kick, cutting costs and closing under performing stores. Investors have welcomed the moves, sending shares up 26% in the quarter, despite a disappointing sales report in May.

It was also a good quarter for health insurance companies. Shares of Aetna (AET), WellPoint (WLP) and Humana (HUM) all rose by more than 23%.

Golden parachute? Mining companies were among the worst performers in the quarter as prices of precious and non-precious metals plunged.

Shares of Alpha Natural Resources (ANR) and Newmont Mining (NEM) fell more than 30%. Iron Mountain (IRM) and Freeport McMoRan (FCX) also suffered double-digit losses.

Investors have been dumping mining stocks as gold prices plunge.

Related: Gold plunges to two-year low

The precious metal is down 25% this quarter, falling below $1,200 an ounce this week for the first time since August 2010. The largest gold-backed ETF, the SPDR Gold Shares Trust (GLD), lost nearly 24% during the past three months.

Gold bugs getting whacked
Gold bugs getting whacked

While the sell-off in gold has caught the most headlines, mining stocks have also been hurt by the falling price of copper.

Copper prices plunged nearly 12% in the second quarter as demand from China slowed and supplies increased.

A number of energy companies were also hit hard.

Marathon Petroleum (MPC) shares are down more than 20% for the quarter, after gaining 42% in the first quarter. The company has been playing catch-up on the boom in domestic energy production, and is exposed to a slowdown in emerging market demand.

Peabody Energy (BTU), which specializes in coal mining, and gas station operator Valero (VLO) were also big losers in the quarter.

CNNMoney Sponsors