GDP threshold Strategy

As a continuation of my analysis on the relationship between GDP and the markets, it is clear to see that if you place a simple threshold (the quarterly annualized GDP growth needs to be above zero) to your buy and hold then you significantly improve a vanilla buy and hold strategy. See results and code below. Sharpe Ratio improved from 0.49 to 0.61

Rplot Rplot02

 

library(quantmod)
library(Quandl)
library(PerformanceAnalytics)
library(gridExtra)
 
#Getting data from Quandl
GDP<- Quandl("FRED/GDP", trim_start="1947-01-01", trim_end="2014-07-01", transformation="rdiff", authcode="kvYEqCqKCTyL4anWz5Zv", type = "xts")
SP500<- Quandl("YAHOO/INDEX_GSPC", trim_start="1950-01-03", trim_end="2014-11-21", authcode="kvYEqCqKCTyL4anWz5Zv", type = "xts")
 
#need to make SP500 data quartetly using the quantmod function.
SP.q<- quarterlyReturn(SP500[,6], subset=NULL, type='arithmetic', leading=FALSE)
 
#cleaning up and aligning the data frame, I know this is fuzzy logic I am a novice coder
df1<- merge(GDP,SP.q)
df2<- merge(lag(df1[,1], k=1),df1)
m<- merge(df2[,1],df2[,3])
mt<- na.omit(m)
mb<- lag(mt[,2],k=1)
mc<- lag(mt[,2],k=2)
mt<- cbind(mt,mb,mc)
mt<- na.omit(mt)
colnames(mt) <- c("GDP", "S&P", "S&P -1", "S&P -2")
head(mt)
 
# Signal
gdp_sig <- ifelse(mt[,1] > 0, 1, 0)  ## I took out the lag function because of the built in lag in the DF
gdp_ret <- mt[,3] * gdp_sig
 
golden<- cbind(gdp_ret,mt[,3])
colnames(golden) = c('GDPtrigger','Buy&Hold')
 
t<- table.AnnualizedReturns(golden, Rf= 0)
grid.newpage(recording = FALSE)
grid.table(t)
 
charts.PerformanceSummary(golden, Rf = 0, main="GDP",geometric=FALSE)

Created by Pretty R at inside-R.org

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s