Investing with the Odds

[This article was first published on The Average Investor's Blog » 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 this previous post, I showed that a look at the correlations in the daily returns of S&P 500 should have lead to a very profitable investing strategy. I also promised to show the results of this strategy in the 80s, but I am not going to do that, because MarketSci has done so in several posts already.

Instead, let’s try to find a more recent “arbitrage” situation like that. Looking into more recent history, and using 126 (half a year) days to compute the autocorrelation function, I got back to August the 30th, 2007:

S&P 500 ACF on August 29 and 30, 2007

S&P 500 ACF on August 29 and 30, 2007

As the graph illustrates, the correlation moved into significant territory at the close of August 30. There is a significant negative correlation in the first lag. Looking at this chart, our strategy should be “go short at the close of a positive day, go long at the close of a negative day”. This situation (strong correlation in the first lag) seemed to last until February the 2nd, 2008. Computing the returns (some of the code was borrowed from an article on FOSS Trading, code at the end) we get the following equity chart:

Equity Growth August 30, 2007 - February 4, 2008

Equity Growth August 30, 2007 – February 4, 2008

How do we know to stop trading using this strategy on February 4th? Why, by the ACF graph of course.

Unless I got something wrong looks damn impressive!

Note, that this is not a trading system, it is just an attempt to approach markets in a much more scientific and systemic way.

Finally the R code:

getSymbols("^GSPC", from="2005-01-01")
GSPC.diffs = diff( Cl( GSPC ) )
GSPC.up = lag( ifelse( GSPC.diffs > 0, -1, 0 ), 1 )
GSPC.down = lag( ifelse( GSPC.diffs < 0, 1, 0 ), 1 )
GSPC.both = GSPC.up + GSPC.down
GSPC.ret = ROC(Cl(GSPC), 1)
GSPC.eq = cumprod( 1 + GSPC.both["2007-08-30/2008-02-04"]*GSPC.ret["2007-08-30/2008-02-04"] )
plot( GSPC.eq, main="Equity Growth Aug 30, 2007 - Feb 04, 2008" )

To leave a comment for the author, please follow the link and comment on their blog: The Average Investor's Blog » 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)