Hey guys, I'm trying to reproduce the Deep learning algo that JCL used to calculate the probability of the AI getting the next candle right with the 60 minutes time frame.
From what I've gathered and understood, it looks like this:
#include <r.h>
void main(int mode, int model, int numSignals, void* Data)
{
if(!wait(0)) return 0;
// open an R script with the same name as the stratefy script
if(mode == NEURAL_INIT) {
if(!Rstart(strf("%s.r",Script),2)) return 0;
Rx("neural.init()");
return 1;
}
// export batch training samples and call the R training function
if(mode == NEURAL_TRAIN) {
string name = strf("Data\\signals%i.csv",Core);
file_write(name,Data,0);
Rx(strf("XY <- read.csv('%s%s',header = F)",slash(ZorroFolder),slash(name)));
Rset("AlgoVar",AlgoVar,8);
if(!Rx(strf("neural.train(%i,XY)",model+1),2))
return 0;
return 1;
}
// predict the target with the R predict function
if(mode == NEURAL_PREDICT) {
Rset("AlgoVar",AlgoVar,8);
Rset("X",(double*)Data,numSignals);
Rx(strf("Y <- neural.predict(%i,X)",model+1));
return Rd("Y[1]");
}
// save all trained models
if(mode == NEURAL_SAVE) {
print(TO_ANY,"\nStore %s",strrchr(Data,'\\')+1);
return Rx(strf("neural.save('%s')",slash(Data)),2);
}
// load all trained models
if(mode == NEURAL_LOAD) {
printf("\nLoad %s",strrchr(Data,'\\')+1);
return Rx(strf("load('%s')",slash(Data)),2);
}
return 1;
}
and
library('deepnet', quietly = T)
library('caret', quietly = T)
# called by Zorro for training
neural.train = function(model,XY)
{
XY <- as.matrix(XY)
X <- XY[,-ncol(XY)] # predictors
Y <- XY[,ncol(XY)] # target
Y <- ifelse(Y > 0,1,0) # convert -1..1 to 0..1
Models[[model]] <<- sae.dnn.train(X,Y,
hidden = c(20,20,20),
activationfun = "tanh",
learningrate = 0.5,
momentum = 0.5,
learningrate_scale = 1.0,
output = "sigm",
sae_output = "linear",
numepochs = 100,
batchsize = 100,
hidden_dropout = 0,
visible_dropout = 0)
}
# called by Zorro for prediction
neural.predict = function(model,X)
{
if(is.vector(X)) X <- t(X) # transpose horizontal vector
return(nn.predict(Models[[model]],X))
}
# called by Zorro for saving the models
neural.save = function(name)
{
save(Models,file=name) # save trained models
}
# called by Zorro for initialization
neural.init = function()
{
set.seed(365)
Models <<- vector("list")
}
# quick OOS test for experimenting with the settings
Test = function()
{
neural.init()
XY <<- read.csv('C:/Project/Zorro/Data/signals0.csv',header = F)
splits <- nrow(XY)*0.8
XY.tr <<- head(XY,splits) # training set
XY.ts <<- tail(XY,-splits) # test set
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 <<- neural.predict(1,X)
Y.pr <<- ifelse(Y > 0.5,1,0)
confusionMatrix(Y.pr,Y.ob) # display prediction accuracy
}
But I don't seem to understand how they interact with each other and how they're supposed to get data from the software itself, does anyony have some recommendation on how to do that?