Two seasonal investors – R snippet

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

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)

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.

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)