S&P 500 sector strengths

[This article was first published on Portfolio Probe » R language, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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 about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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)