Here you will find daily news and tutorials about R, contributed by over 573 bloggers.
There are many ways to follow us - By e-mail:On Facebook: If you are an R blogger yourself you are invited to add your own R content feed to this site (Non-English R bloggers should add themselves- here)

In his detailed research on RSI(2) indicator, MarketSci emphasized several times that the contrarian strategies based on the RSI(2) indicator didn’t start working until the 80s. I remembered this observation recently when I observed another interesting anomaly …

In statistics, an important initial step in studying time series data is to consider the auto correlation of the series. In R, the simplest way to accomplish this is to use the acf function (for more details see Introductory Time Series with R). The R code to visualize the auto correlations is:
library(quantmod)
getSymbols("^GSPC", from="1900-01-01")
acf(diff(Cl(GSPC["2009"])), na.action=na.pass, main="S&P 500 - Correlation between Lags in 2009")

The result looks exactly “as expected”. There is no statistically significant correlation (the dotted lines) at any of the lags.

S&P 500 – Correlation between Lags in 2009

Imagine my surprise when I run the same command for the 1965:

S&P 500 – Correlations between Lags in 1965

Now there is a statistically significant correlation at lag 1! At this point I remembered MarketSci statement and decided to dig further. To make the long story short, for the most of the 60s and 70s, this correlation existed. I can hear some of you saying so what?

Here is what, a strong correlation in lag 1 means that the returns of the previous day are very predictable of the returns of the next day. In other words, I would expect a very simple strategy as take a long position at the close if market is up or take a short position at the close if the market is down, to perform quite well. This is like taking a heavily biased bet with the odds on the better’s side! Using some R code I quickly tested it and lo and behold, it seemed to work quite well! The detailed results would have to wait a next posting though …