Lagsignal lagparamshedgeratio

Info iconThis preview shows pages 11–14. Sign up to view the full content.

View Full Document Right Arrow Icon
return.pairtrading=Return(price.pair, lag(signal), lag(params$hedge.ratio)) plot(100*cumprod(1+return.pairtrading), main="Performance of pair trading") #UNIT 10 ############################################################################# #One-output XOR #Example 10.1 x1=ts(c(1,1,0,0)) x2=ts(c(1,0,1,0)) d1=ts(c(0,1,1,0)) x=cbind(d1, x1, x2) require ("neuralnet") print(net.out <- neuralnet(d1~x1+x2, data=x, hidden=10, threshold=0.01)) plot(net.out) x1=ts(c(0.9,0.8,0.3,0.2)) x2=ts(c(0.76,0.4,0.7,0.22)) test=cbind( x1, x2) cbind(test, compute(net.out, test)$net.result) #NEURAL NET RESULT #Two-output XOR #Example 10.2 x1=ts(c(1,1,0,0)) x2=ts(c(1,0,1,0)) d1=ts(c(0,1,1,0)) d2=ts(c(1,0,0,1))
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
x=cbind(d1, d2, x1, x2) require ("neuralnet") net.out <- neuralnet(d1+d2~x1+x2, data=x, hidden=10, threshold=0.01) x1=ts(c(0.9,0.8,0.3,0.2)) x2=ts(c(0.76,0.4,0.7,0.22)) test=cbind( x1, x2) cbind(test, compute(net.out, test)$net.result) #NEURAL NET RESULT #Asset Price Example #Example 10.3 #prepare data set library(quantmod) SS36=getSymbols("600036.SS", auto.assign=F) SS36=as.data.frame(SS36) names(SS36)[1]=paste("open") names(SS36)[2]=paste("high") names(SS36)[3]=paste("low") names(SS36)[4]=paste("close") names(SS36)[5]=paste("vol") SS36=cbind(SS36, date=as.Date(rownames(SS36)) ) SS36["code"]=600036 SS36=subset(SS36, date>="2012-10-01") r=rotate(SS36, c("high", "low", "close") ,4) coeff=4 sw=3 rr=NA rr=rollingSum(r, data.frame(r$date, lam=(coeff*abs(r$open-r$close1)/r$close1)/ sw ), sw) rr$lam=ifelse(rr$lam==0, 0.001, rr$lam) #(rr$open-rr$close1)/(rr$close1*rr$lam) x=data.frame(date=rr$date, x1=(rr$open-rr$close1)/(rr$close1*rr$lam)) rr=NA rr=rollingSum(r, data.frame(r$date, lam=(coeff*abs(r$close1- r$close2)/r$close1)/sw ),sw ) rr$lam=ifelse(rr$lam==0, 0.001, rr$lam) (rr$close1-rr$close2)/(rr$close1*rr$lam) x=cbind(x, x2=(rr$close1-rr$close2)/(rr$close1*rr$lam) ) rr=NA rr=rollingSum(r, data.frame(r$date, lam=(coeff*abs(r$high1- r$high2)/r$close1)/sw ), sw ) rr$lam=ifelse(rr$lam==0, 0.001, rr$lam) x=cbind(x, x3=(rr$high1-rr$high2)/(rr$close1*rr$lam) ) rr=NA rr=rollingSum(r, data.frame(r$date, lam=(coeff*abs(r$low1-r$low2)/r$close1)/sw ), sw ) rr$lam=ifelse(rr$lam==0, 0.001, rr$lam) x=cbind(x, x4=(rr$low1-rr$low2)/(rr$close1*rr$lam) ) rr=NA rr=rollingSum(r, data.frame(r$date, lam=(coeff*abs(r$close2- r$close3)/r$close2)/sw ),sw ) rr$lam=ifelse(rr$lam==0, 0.001, rr$lam) x=cbind(x, x5=(rr$close2-rr$close3)/(rr$close2*rr$lam) )
Background image of page 12
rr=NA rr=rollingSum(r, data.frame(r$date, lam=(coeff*abs(r$high2- r$high3)/r$close2)/sw ), sw ) rr$lam=ifelse(rr$lam==0, 0.001, rr$lam) x=cbind(x, x6=(rr$high2-rr$high3)/(rr$close2*rr$lam) ) rr=NA rr=rollingSum(r, data.frame(r$date, lam=(coeff*abs(r$low2-r$low3)/r$close2)/sw ), sw ) rr$lam=ifelse(rr$lam==0, 0.001, rr$lam) x=cbind(x, x7=(rr$low2-rr$low3)/(rr$close2*rr$lam) ) rr=NA rr=rollingSum(r, data.frame(r$date, lam=(coeff*abs(r$close3- r$close4)/r$close3)/sw ),sw ) rr$lam=ifelse(rr$lam==0, 0.001, rr$lam) x=cbind(x, x8=(rr$close3-rr$close4)/(rr$close3*rr$lam) ) rr=NA rr=rollingSum(r, data.frame(r$date, lam=(coeff*abs(r$high3-
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 14
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page11 / 15

lagsignal lagparamshedgeratio

This preview shows document pages 11 - 14. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online