# 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

```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")

# 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])