Factor.R myATR <- function(x) ATR(HLC(x))[,'atr'] mySMI <- function(x) SMI(HLC(x))[,'SMI'] myADX <- function(x) ADX(HLC(x))[,'ADX'] myAroon <- function(x) aroon(x[,c(2,3)])$oscillator myBB <- function(x) BBands(HLC(x))[,'pctB'] myChaikinVol <- function(x) Delt(chaikinVolatility(x[,c(2,3)]))[,1] myCLV <- function(x) EMA(CLV(HLC(x)))[,1] myEMV <- function(x) EMV(x[,c(2,3)],x[,c(5)])[,2] myMACD <- function(x) MACD(Cl(x))[,2] myMFI <- function(x) MFI(x[,c(2,3,4)], x[,c(5)]) mySAR <- function(x) SAR(x[,c(2,3)]) [,1] myVolat <- function(x) volatility(OHLC(x),calc="garman")[,1] T.ind.R T.ind <- function(quotes,tgt.margin=0.025,n.days=10) { v <- apply(HLC(quotes),1,mean) r <- matrix(NA,ncol=n.days,nrow=NROW(quotes)) for(x in 1:n.days) r[,x] <- Next(Delt(v,k=x),x) x <- apply(r,1,function(x) sum(x[x > tgt.margin | x < -tgt.margin])) x } Recylin.R recylin=function(p,n){ pr=array(1:n) for (i in 1: n){ stock.lin=lda(as.factor(T)~x1+x2+x3+x4+x5+x6+x7+x8+x9+x10+x11+x12+x13+x14+x15+x16+x17,data=stock[i:p+i-1,]) pr[i]=predict(stock.lin,stock[p+i,])$class } pr-2 } Recyrp.R recyrp=function(p,n){ pr=array(1:n) for (i in 1: n){ stock.rp=rpart(as.factor(T)~x1+x2+x3+x4+x5+x6+x7+x8+x9+x10+x11+x12+x13+x14+x15+x16+x17, data=stock[0+i:p+i-1,],method="class") pr[i]=predict(stock.rp,stock[p+i,],type="class") } pr-2 } Recyrf.R recyrf=function(p,n){ pr=array(1:n) for (i in 1: n){ stock.rf=randomForest(as.factor(T)~x1+x2+x3+x4+x5+x7+x8+x9+x10+x11+x12+x13+x14+x15+x16+x17, data=stock[500+i:500+p+i-1,],importance=TRUE,proximity=TRUE) pr[i]=predict(stock.rf,stock[500+p+i,],type="response") } pr-2 }