S&P 500 sector strengths

October 10, 2012

(This article was first published on Portfolio Probe » R language, and kindly contributed to R-bloggers)

Which sectors are coherent, and which aren’t?


The post “S&P 500 correlations up to date” looked at rolling mean correlations among stocks.  In particular it looked at rolling mean correlations of stocks within sectors.

Of importance to this post is that the sectors used are taken from Wikipedia.

Relative correlations

The thought is that if the stocks within sectors really move together, then their mean correlation will be higher than the mean of the correlations across all stocks.  The difference in correlations is a measure of the strength of the coherence of the sector.

The data that went into Figure 1 were created by:

  • get the mean 50-day correlations of the sector with dates in 2012 (so returns in the last quarter of 2011 have some effect)
  • subtract the corresponding mean 50-day correlations for the whole universe
  • this makes 193 differences per sector

Figure 1 shows boxplots of the correlation differences sorted by their means.

Figure 1: Difference of sector and market mean 50-day correlations in 2012. Note that the width of the boxes is variability across time — there is no indication of the variability of correlations within the sector across stocks.

Financials, Utilities and Energy are the strongest sectors.

More interesting, I think, is that Consumer Staples, Telecommunications Services and Consumer Discretionary are being anti-sectors.  They have lower correlation among themselves than across the market as a whole.

Figure 2 shows the differences from the whole time period starting in 2006.

Figure 2: Difference of sector and market mean 50-day correlations back to 2006. 

Energy and Utilities have consistently been strong sectors, and Consumer Staples has consistently been an anti-sector.


Are the “anti-sectors” merely because the categorization isn’t very good?

This seems like a complicated way of approaching the coherence of sectors.  What are more direct ways of getting there?


Some sectors are more equal than others.

Appendix R

The computing and plotting were done in R.

compute differences

The function to create the differences conveniently is:

pp.corcompare <- function(sectorcors, marketcor) 
  dnam <- names(marketcor)
  ans <- array(NA, c(length(marketcor), 
     length(sectorcors)), list(dnam, names(sectorcors)))
  for(i in names(sectorcors)) {
    ans[, i] <- sectorcors[[i]]$cor[dnam] - marketcor
  attr(ans, "call") <- match.call()

This is used (with objects created in “S&P 500 correlations up to date”) like:

marketcor <- corboot.sp50$cor
marketcor12 <- marketcor[substr(names(marketcor), 1, 4)
   == "2012"]
corcomp12 <- pp.corcompare(corboot.sectors, marketcor12)


A function to create a plot is:

P.corcompare12 <-
  function (filename = "corcompare12.png") 
    if(length(filename)) {
      png(file=filename, width=512)
      par(mar=c(4,11, 0, 0) + .1, las=1)
    cco <- corcomp12[, order(colMeans(corcomp12))]
    colnames(cco)[colnames(cco) == 
       "Telecommunications Services"] <- 
    boxplot(cco, horizontal=TRUE, col="gold",
            xlab="Sector minus market correlations")
    abline(v=0, col="steelblue")

    if(length(filename)) {

This is the function that created Figure 1.

To leave a comment for the author, please follow the link and comment on their blog: Portfolio Probe » R language.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: , , , ,

Comments are closed.


Mango solutions

plotly webpage

dominolab webpage

Zero Inflated Models and Generalized Linear Mixed Models with R

Quantide: statistical consulting and training





CRC R books series

Six Sigma Online Training

Contact us if you wish to help support R-bloggers, and place your banner here.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)