Framerdate lamcoeffabsrhigh3 rhigh4rclose3sw sw

Info iconThis preview shows pages 13–15. Sign up to view the full content.

View Full Document Right Arrow Icon
rr=rollingSum(r, data.frame(r$date, lam=(coeff*abs(r$high3- r$high4)/r$close3)/sw ), sw ) rr$lam=ifelse(rr$lam==0, 0.001, rr$lam) x=cbind(x, x9=(rr$high3-rr$high4)/(rr$close3*rr$lam) ) rr=NA rr=rollingSum(r, data.frame(r$date, lam=(coeff*abs(r$low3-r$low4)/r$close3)/sw ), sw ) rr$lam=ifelse(rr$lam==0, 0.001, rr$lam) x=cbind(x, x10=(rr$low3-rr$low4)/(rr$close3*rr$lam) ) rr=NA rr=rollingSum(r, data.frame(r$date, lam=(coeff*abs(r$high- r$close)/r$close1)/sw ),sw ) rr$lam=ifelse(rr$lam==0, 0.001, rr$lam) x=cbind(x, d1=(rr$high-rr$close)/(rr$close1*rr$lam) ) rr=NA rr=rollingSum(r, data.frame(r$date, lam=(coeff*abs(r$close- r$close1)/r$close1)/sw ), sw ) rr$lam=ifelse(rr$lam==0, 0.001, rr$lam) x=cbind(x, d2=(rr$close-rr$close1)/(rr$close1*rr$lam) ) rr=NA rr=rollingSum(r, data.frame(r$date, lam=(coeff*abs(r$close-r$low)/r$close1)/sw ), sw ) rr$lam=ifelse(rr$lam==0, 0.001, rr$lam) x=cbind(x, d3=(rr$close-rr$low)/(rr$close1*rr$lam) ) require ("neuralnet") net.out <- neuralnet(d1+d2+d3~x1+x2+x3+x4+x5+x6+x7+x8+x9+x10, data=x, hidden=18, threshold=0.001, stepmax=1e+6) rollingSum=function(x, y, sw) { # c(date, colman=forumula) y=data.frame(y) y=y[order( y[,1], decreasing=T),] y_colnames= colnames(y[2]) for (i in 1:(length(y[,1])-(sw-1)))
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
{ tmpSum=sum(y[i:(i+sw-1), 2]) tmpDate= y[i,1] singleRow=data.frame(tmpDate, tmpSum ) if (i==1) retV=rbind(singleRow) else retV=rbind(retV,singleRow) } names(retV)[1]=paste("date") names(retV)[2]<-paste(y_colnames) retV=merge(x, retV, by="date") retV=retV[order( retV$date, decreasing=T),] return(retV) } #a=rollingSum(p, data.frame(p$date, lam1=abs(p$open-p$close)/p$close),2) rotate=function(x, colnlist, many) { x=x[order( x$code,x$date, decreasing=T),] numOfList=length(colnlist) retV=x for (i in 1:numOfList) { retV=rotateOneCol(retV, colnlist[i], many) } return(retV) } rotateOneCol=function (x, coln, many) { newidx=length(x[1,]) for (m in 1:many) { x[,(newidx+m)]=NA } for (m in 1:many) { newcolname=paste(coln, m, sep = "") colnames(x)[newidx+m]=newcolname } warning=F idx=which(colnames(x)==coln) for (i in 2: (length(x$code)-many)) { { for (m in 1:many) { #cat(i, newidx+m, x[i+m, idx], i+m, idx) if (is.na(x[i+m, idx])) warning=T x[i, newidx+m]=x[i+m, idx] } } } if (warning) print("please check data value as NA found") x= subset(x, is.na(x[,(newidx+1)])==F) return(x) } #rotate(p, "high", 2) # END ##############################################################################
Background image of page 14
Background image of page 15
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page13 / 15

framerdate lamcoeffabsrhigh3 rhigh4rclose3sw sw...

This preview shows document pages 13 - 15. Sign up to view the full document.

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