dt <- read.table("D:/R/MY_script/RTS_ALL(Clear).txt",sep=",",head=T) dt <- tail(dt,150000) train <- 1:100000 test <- 100001:nrow(dt) dt.tr <- dt[train,] N.col <- 5 HE <- function(data, r=N.col) { do.call(cbind, lapply(0:(r-1),function(i) { data[(i+1):(length(data)-(r-1-i))]}))} O <- HE(dt.tr$X.OPEN.) H <- HE(dt.tr$X.HIGH.) L <- HE(dt.tr$X.LOW.) C <- HE(dt.tr$X.CLOSE.) V <- HE(dt.tr$X.VOL.) W <- HE(dt.tr$X.HIGH.-dt.tr$X.LOW.) O <- t(apply(O, 1, function(x) {scale(x,T,T)})) ; colnames(O) <- paste0("open",N.col:1) H <- t(apply(H, 1, function(x) {scale(x,T,T)})) ; colnames(H) <- paste0("high",N.col:1) L <- t(apply(L, 1, function(x) {scale(x,T,T)})) ; colnames(L) <- paste0("low",N.col:1) C <- t(apply(C, 1, function(x) {scale(x,T,T)})) ; colnames(C) <- paste0("close",N.col:1) V <- t(apply(V, 1, function(x) {scale(x,T,T)})) ; colnames(V) <- paste0("volume",N.col:1) W <- t(apply(W, 1, function(x) {scale(x,T,T)})) ; colnames(W) <- paste0("volatil",N.col:1) dat <- cbind(dt.tr[-c(1:(N.col-1)),],O,H,L,C,V,W) dat <- na.omit(dat) TSLAB.train <- dat[,1:9] colnames(TSLAB.train) <- c("","","","