What an October it's been for the markets!

It's hard to imagine that mere weeks ago the S&P entered a brief bear market. Heading into Friday's trading, the S&P 500 was up 3.7% on the week. At the S&P's current October gains, the month is on track to be strongest monthly performance since 1974. Despite hand-wringing across a brutal summer, the S&P is now up about 2% on the year.

Here's a look at which sectors saw the highest -- and lowest -- gains through last Thursday in a generally upbeat market. All data courtesy of researcher and analytics provider S&P Capital IQ.

Top 3 Performing Sectors

S&P Sector

Weekly Price Change

October Price Change

Financials 7.2% 19%
Materials 7.1% 21.9%
Energy 5.3% 21.8%

Bottom 3 Performing Sectors

S&P Sector

Weekly Price Change

October Price Change

Consumer Staples 0.4% 5.9%
Telecommunications 0.9% 3.1%
Utilities 1.1% 4.9%
Source: S&P Capital IQ. Data as of Oct. 27 price change. Monthly price change is Sept. 30 to Oct. 27.

With the markets bring driven by a deal to take a "voluntary" 50% writedown on Greek bonds, along with recapitalizing European banks and leveraging up a European stability fund, it's no surprise that financials drove the markets. All these moves were aimed at shoring up not only European banks, but also the debt many banks hold on their balance sheets.

This Week's Top 5 Performing S&P 500 Companies

S&P Sector

Weekly Price Change

Nabors Industries (NYSE: NBR) 23.1%
F5 Networks (Nasdaq: FFIV) 18.9%
Peabody Energy (NYSE: BTU) 17.9%
Advanced Micro Devices (NYSE: AMD) 17.4%
Helmerich & Payne (NYSE: HP) 17.2%
Source: S&P Capital IQ. Data as of Oct, 27 price change.

Both F5 and Advanced Micro Devices make the list on the back of strong earnings. The IT sector has seen its share of hits and misses this earnings season. However, many of these stocks are bouncing so high off their September lows because rampant pessimism drove them so far off their 52-week highs.

Nabors also posted strong earnings that sent shares soaring. The contract driller had especially strong earnings offshore and in Canada. Peabody made the list in spite of missing earnings, but its bullish long-term outlook helped drive shares higher. Overall, energy and basic materials stocks were among the highest performers as market optimism pushed commodity prices higher.

This Week's Bottom 5 Performing S&P 500 Companies

S&P Sector

Weekly Price Change

Netflix (Nasdaq: NFLX) (28.6%)
First Solar (Nasdaq: FSLR) (16.3%)
Hospira (NYSE: HSP) (15.7%)
Sprint Nextel (NYSE: S) (13.5%)
BMC Software (Nasdaq: BMC) (12.1%)
Source: S&P Capital IQ. Data as of Oct, 27 price change.

Both Netflix and First Solar are unfortunate regulars on the bottom-performers list. First Solar is the second worst performing S&P stock in 2011, and Netflix comes in at No. 4. In the case of Netflix, the company issued weak forward subscriber guidance, causing investors to flee. It's been a brutal summer ride for the disc slinger, and investors are concerned that its bold plans to bolster its streaming services while de-emphasizing its disc unit aren't panning out.

BMC was another loser in the technology sector. The company's earnings didn't impress investors, and shares continued a slide that started in July. Still, sometimes these short-term drops present opportunities for investors. BMC operates on long-term contracts that are recognized over time, meaning its actual cash flow is much stronger than reported earnings. With BMC trading at only 5.5 times its trailing free cash flow relative to its value after subtracting out its net cash, this is one stock I'll be adding to my personal watchlist.

That's it for our recap of this week's biggest gainers and laggards. To stay updated on any of the companies listed here, add them to your Watchlist by clicking the "+" sign next to the respective tickers. Don't have a Watchlist yet? You can start one for free