//
you're reading...

Finance

Two seasonal investors – R snippet

In “A tale of 2 Seasonal Investors“, the Big Picture discusses the simple idea of comparing two simple investment approaches: being exposed to the market 6 months every year (from November to April), as opposed to investing in the other 6 months of every year (from May to October).

Going back 50 years in the past, the first partition of the year gives more than 40 times the initial investment, whereas the other partition is barely profitable. This is the idea that brought on seasonal investing, with those who are money-savvy and who like to visit sites like lovemoney.com for savings tips cottoning on to what was going on. The market can reach important lows and highs at certain times of the year and it is very valuable if you can keep track of these and work from them. Those who can capitalise on such statistics will find that they will go far in the investment world.

Below is some R code to verify this, and one could take this to research other highly asymmetries in seasonality.

 
require(quantmod)
require(PerformanceAnalytics)
 
getSymbols('^GSPC', from='1900-01-01')
 
d <- index(GSPC)
getMonth <- function(i) {
        as.numeric(format(i, format="%m"))
}
firstHalf <- function(i) {
        ifelse(getMonth(i) <= 4 || getMonth(i) >= 11, 1, 0)
}
hold1 <- unlist(lapply(d, firstHalf))
hold2 <- 1-hold1
hold1 <- xts(hold1, d)
hold2 <- xts(hold2, d)
 
perf <- merge(hold1 * ROC(GSPC[,4], type='discrete', n=1), hold2 * ROC(GSPC[,4], type='discrete', n=1))
colnames(perf) <- c("Nov - Apr", "May - Oct")
charts.PerformanceSummary(perf)

Discussion

3 Responses to “Two seasonal investors – R snippet”

  1. Eric,

    Thanks for this bit of code. What you hit upon is what old traders call the “Santa Claus Rally” and “Sell in May and go away.”

    Posted by Tom | November 2, 2011, 8:12 am
  2. Eric,

    Could you provide this dataset in your blog?

    Thx!

    @flavioclesio

    Posted by Flavio | December 10, 2011, 6:40 pm

Trackbacks/Pingbacks

  1. [...] 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 [...]

Post a Comment

About

Eric Nguyen is a data scientist with current focus on Finance, Economics, Big Data Analytics, and Social Mood analysis.

more

Topics