A look at market returns by month

November 30, 2011
By

(This article was first published on DataPunks.com » R, and kindly contributed to R-bloggers)

I’ve been reading The Big Picture, and again, there was a discussion about seasonality in stock markets (see
Fourth Quarter is Da Bomb).

I’ve already discussed the two seasonal investment scenarios (Nov. to Apr VS May to Oct) in this post, and was wondering if one could break it down further into a monthly analysis.

The quick R snippet below, edited in an informal way like this blog likes it, shows us a little boxplot (yes, I’m a sucker for those) of market returns per month. This suggests that the months of February and September are not witnessing great returns of the S&P 500.

 
require(quantmod)
require(PerformanceAnalytics)
 
getSymbols('^GSPC', from='1900-01-01')
m <- lapply(d, getMonth)
t <- monthlyReturn(GSPC)
d <- index(t)
getMonth <- function(i) {
        as.numeric(format(i, format="%m"))
}
t$month <- lapply(d, getMonth)
boxplot(monthly.returns ~ month, t)
title('Market returns by month')
abline(0,0)

Photograph used with permission from mylittleshoebox.ca

To leave a comment for the author, please follow the link and comment on his blog: DataPunks.com » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: 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...

Comments are closed.