var neural(int Status, int model, int NumSignals, void* Data)
{
if(!wait(0)) return 0;
// open a Python script with the same name as the strategy script
if(Status == NEURAL_INIT) {
if(!pyStart(strf("%s.py",Script),1)) return 0;
pyX("neural_init()");
return 1;
}
// export batch training samples and call the Python training function
if(Status == NEURAL_TRAIN) {
string name = strf("Data\\signals%i.csv",Core);
file_write(name,Data,0);
pyX(strf("XY = pandas.read_csv('%s%s',header = None)",slash(ZorroFolder),slash(name)));
pySet("AlgoVar",AlgoVar,8);
if(!pyX(strf("neural_train(%i,XY)",model+1)))
return 0;
return 1;
}
// predict the target with the Python predict function
if(Status == NEURAL_PREDICT) {
pySet("AlgoVar",AlgoVar,8);
pySet("X",(double*)Data,NumSignals);
pyX(strf("Y = neural_predict(%i,X)",model+1));
return pyVar("Y[0]");
}
// save all trained models
if(Status == NEURAL_SAVE) {
print(TO_ANY,"\nStore %s",strrchr(Data,'\\')+1);
return pyX(strf("neural_save('%s')",slash(Data)));
}
// load all trained models
if(Status == NEURAL_LOAD) {
printf("\nLoad %s",strrchr(Data,'\\')+1);
return pyX(strf("neural_load('%s')",slash(Data)));
}
return 1;
}