A look at market returns by month

November 30, 2011

[This article was first published on DataPunks.com » R, 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.

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.

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')

Photograph used with permission from mylittleshoebox.ca

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

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.

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.

Search R-bloggers


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)