Hi,
Does anyone has any idea why this is happening during the NEURAL testing after training ?
Getting "subscript out of bounds" from the R script when there are multiple assets or NumWFOCycles >60.
If I remove 1 of the 2 asset, or set NumWFOCycles=50 , this issue is not happening.


/////////////////////////// Zorro script
#include <r.h>

var change(int n)
{
return scale((priceClose(0) - priceClose(n))/priceClose(0),100)/100;
}

function run()
{
NumCores = -1;
Script = "DeepLearnMXDEBUG";
Verbose = 31|DIAG;
StartDate = 2016;//2016;
BarPeriod = 1440; // 1 hour
LookBack = 100;
Weekend=0;

NumWFOCycles = 60;

assetList("History\AssetsBitmex.csv");
while(loop(Assets))
{
asset(Loop1);
set(RULES);

LifeTime = 3;
if(Train) Hedge = 2;
var Threshold = 0.5;

set(LOGFILE|PLOTNOW);
if(adviseLong(NEURAL+BALANCED,0,
change(1),change(2),change(3),change(4)) > 0.5)
enterLong();
if(adviseShort() > 0.5)
enterShort();

PlotWidth = 800;
PlotHeight1 = 340;

}
}

////////////////////////// Zorro assets

Name,Price,Spread,RollLong,RollShort,PIP,PIPCost,MarginCost,Leverage,LotAmount,Commission,Symbol,Type
ETH/BTC,1,0,0,0,0.00000001,0.00000001,0,1,1,-0.25,ETH/BTC,
BCH/BTC,1,0,0,0,0.00000001,0.00000001,0,1,1,-0.25,BCH/BTC,

/////////////////////////// R File

# how to install
#cran <- getOption("repos")
#cran["dmlc"] <- "https://s3-us-west-2.amazonaws.com/apache-mxnet/R/CRAN/"
#options(repos = cran)
#install.packages('mxnet')
# - or (if not yet available for current version) -
#install.packages("https://s3.ca-central-1.amazonaws.com/jeremiedb/share/mxnet/CPU/mxnet.zip", repos = NULL)
library('mxnet', quietly = T)
library('caret', quietly = T)

neural.train = function(model,XY)
{
X <- data.matrix(XY[,-ncol(XY)])
Y <- XY[,ncol(XY)]
Y <- ifelse(Y > 0,1,0)
Models[[model]] <<- mx.mlp(X,Y,
hidden_node = c(30),
out_node = 2,
activation = "sigmoid",
out_activation = "softmax",
num.round = 20,
array.batch.size = 20,
learning.rate = 0.05,
momentum = 0.9,
eval.metric = mx.metric.accuracy)
}

neural.predict = function(model,X)
{
if(is.vector(X)) X <- t(X)
X <- data.matrix(X)
Y <- predict(Models[[model]],X)
return(ifelse(Y[1,] > Y[2,],0,1))
}

neural.save = function(name)
{
for(i in c(1:length(Models)))
Models[[i]] <<- mx.serialize(Models[[i]])
save(Models,file=name)
}

neural.load <- function(name)
{
load(name,.GlobalEnv)
for(i in c(1:length(Models)))
Models[[i]] <<- mx.unserialize(Models[[i]])
}

neural.init = function()
{
mx.set.seed(365)
Models <<- vector("list")
}

neural.test = function()
{
neural.init()
XY <<- read.csv('MyZorroPath/Data/DeepLearnMX.csv',header = F)
splits <- nrow(XY)*0.8
XY.tr <<- head(XY,splits)
XY.ts <<- tail(XY,-splits)
neural.train(1,XY.tr)

X <<- XY.ts[,-ncol(XY.ts)]
Y <<- XY.ts[,ncol(XY.ts)]
Y.ob <<- ifelse(Y > 0,1,0)
Y.pr <<- neural.predict(1,X)
confusionMatrix(as.factor(Y.pr),as.factor(Y.ob))
}

///////////////////////////// Zorro output

Error in Models[[model]] : subscript out of bounds
Calls: neural.predict -> predict
Execution halted

Attached Files
DeepLearnDEBUG.c (1 downloads)