Machine learning in trading: theory, models, practice and algo-trading - page 1064

 
Maxim Dmitrievsky:

Because models still sucks ^) with big errors, need models that work longer

For example 2 months learning and 1 week trade

You may be correct, but I don't think that any such models will ever be discovered by RDF which an work even for one complete day until we can do unlimited random candle simulations similar to "ALPHA ZERO" algo.

Because markets change almost every hour and one model will terribly fail if suddenly a news event will occur or if the market will change its behavior for some reason. But if we have done millions of candle simulations, then probably the system can recover with minimal loss upon market change and can quickly recover the loss afterwards. That seems to be possible.

I will try both your method of model selection and my method of candle simulation to see how everything goes:))

By the way, I tried 1 day training,5 days training etc. and it failed on next day:))))))))))))))))

So one model may not work...though I may be wrong...

 

Also, I have one more request Maxim...

When you publish your article, please try to comment the code as much as possible so that it will be quick and easy for others to understand the code so that we can progress faster...

Otherwise, if it will take a long time for me to understand the code, then it will take even more time to modify it.

So I request you to add as many comments and explanations of the code as possible. For now I will try to understand it quickly and will ask you if I don't understand anything:))

 
FxTrader562:

Also, I have one more request Maxim...

When you publish your article, please try to comment the code as much as possible so that it will be quick and easy for others to understand the code so that we can progress faster...

Otherwise, if it will take a long time for me to understand the code, then it will take even more time to modify it.

So I request you to add as many comments and explanations of the code as possible. For now I will try to understand it quickly and will ask you if I don't understand anything:))

Ok, now I just constantly change many things and no sense to comment it

also you can think about how to change outputs... maybe use zigzag with different settings instead of reward function or something else
 
Maxim Dmitrievsky:

Ok, now I just constantly change many things and no sense to comment it

Also you can think about how to change outputs... maybe use zigzag with different settings instead of reward function or something else

I just had a quick overview of the code. But till now I have not figured out exactly where are the indicators or how it decides the trade entries. So I am not sure as what to do with output. You mean output using GDMH?

I just run the test with various settings, but it seems to place completely random trades.

Also, in the testing phase it doesn't create the "Mtrees" text files.right?

I mean the code which you provided is not complete.right? Or is it capable of placing trades if it is attached directly to the chart without optimization.

 
FxTrader562:

I just had a quick overview of the code. But till now I have not figured out exactly where are the indicators or how it decides the trade entries. So I am not sure as what to do with output.

I just run the test with various settings, but it seems to place completely random trades as well as as it showed some strange behavior and hence, I just rebooted my server. Does it have to do anythign with real kernels of the VPS?

Also, in the testing phase it doesn't create the "Mtrees" text files.right?

When first run in tester choose "true".

He will make random trades and learn then and save the models

The 2nd run choose false. Thats it. And he upload models and will trade in +

Next, in EA you can add agents, now you have 5 agents, 100 features for each agent, 50 trees

CRLAgents *ag1=new CRLAgents("RlExp1iter",5,100,50,regularize,learn);

In this function we add 100 close prices for each agent (100 predictors). And then normalize data. You can add different indicators, for example first 50 features - close prices, next 25 rsi, next 25 adx, or change the number of predictors when you declare agent

void calcSignal()
  {
   sig1=0;
       
   for(int i=0;i<ArraySize(ag1.agent);i++) - the agents are stored in "ag1.agent" array. We have 5 agents, so array size is 5
     {   
      CopyClose(_Symbol,0,0,100,ag1.agent[i].inpVector); - for each agent from array (now we have 5 agents) fill predictors (100 close prices). For each feature we fill a single value
      normalizeArrays(ag1.agent[i].inpVector);
     }
   sig1=ag1.getTradeSignal(); this function return averaged signal for all agents
  }

After each deal he update policies, when close trade - update reward (TD, temporal difference RL)

void placeOrders()
  {
   if(countOrders(0)!=0 || countOrders(1)!=0)
     {
      for(int b=OrdersTotal()-1; b>=0; b--)
         if(OrderSelect(b,SELECT_BY_POS)==true)
            switch(OrderType())
              {
               case OP_BUY:
                  if(sig1>0.5)
                  if(OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Red))
                     ag1.updateRewards();

                  break;

               case OP_SELL:
                  if(sig1<0.5)
                  if(OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Red))
                     ag1.updateRewards();

                  break;
              }
      return;
     }

   if(sig1<0.5 && (OrderSend(Symbol(),OP_BUY,lotsOptimized(),SymbolInfoDouble(_Symbol,SYMBOL_ASK),0,0,0,NULL,OrderMagic,INT_MIN)>0))
     {
      ag1.updatePolicies(sig1);
     }

   else if(sig1>0.5 && (OrderSend(Symbol(),OP_SELL,lotsOptimized(),SymbolInfoDouble(_Symbol,SYMBOL_BID),0,0,0,NULL,OrderMagic,INT_MIN)>0))
     {
      ag1.updatePolicies(sig1);
     }

Really simple library usage

In train mode he will show you logs with errors for each iteration

2018.09.16 01:33:27.319 2018.09.13 23:59:59   Agent 5 Model 40 passed with errors: 0.2422178988326848  0.5097276264591439
2018.09.16 01:33:27.319 2018.09.13 23:59:59   Agent 5 Model 41 passed with errors: 0.2295719844357977  0.4824902723735409
2018.09.16 01:33:27.319 2018.09.13 23:59:59   Agent 5 Model 42 passed with errors: 0.2558365758754864  0.4961089494163424
2018.09.16 01:33:27.319 2018.09.13 23:59:59   Agent 5 Model 43 passed with errors: 0.2422178988326848  0.4863813229571984
2018.09.16 01:33:27.319 2018.09.13 23:59:59   Agent 5 Model 44 passed with errors: 0.2422178988326848  0.4766536964980545
2018.09.16 01:33:27.319 2018.09.13 23:59:59   Agent 5 Model 45 passed with errors: 0.245136186770428  0.5379377431906615
2018.09.16 01:33:27.319 2018.09.13 23:59:59   Agent 5 Model 46 passed with errors: 0.2587548638132296  0.4912451361867704
2018.09.16 01:33:27.319 2018.09.13 23:59:59   Agent 5 Model 47 passed with errors: 0.2480544747081712  0.4776264591439689
2018.09.16 01:33:27.319 2018.09.13 23:59:59   Agent 5 Model 48 passed with errors: 0.2636186770428016  0.5009727626459144
2018.09.16 01:33:27.319 2018.09.13 23:59:59   Agent 5 Model 49 passed with errors: 0.2616731517509728  0.490272373540856

In trade mode in tester show final errors on train and test subset for each agent

2018.09.16 01:34:18.107 2018.09.13 23:59:59   RlExp1iter TRAIN LOGLOSS
2018.09.16 01:34:18.107 2018.09.13 23:59:59   0.23249 0.22763 0.24222 0.24125 0.24416
2018.09.16 01:34:18.107 2018.09.13 23:59:59   RlExp1iter OOB LOGLOSS
2018.09.16 01:34:18.107 2018.09.13 23:59:59   0.46790 0.46887 0.46498 0.46790 0.47471

Result for 100 close prices:


 
Maxim Dmitrievsky:

When first run in tester choose "true"

He will make random trades and learn then and save the models

The 2nd run choose false. Thats it. And he upload models and will trade in +

Next, in EA you can add agents, now you have 5 agents, 100 features for each agent, 50 trees

In this function we add 100 close prices for each agent (100 predictors). And then normalize data. You can add different indicators, for example first 50 features - close prices, next 25 rsi, next 25 adx, or change the number of predictors when you declare agent

After each deal he update policies, when close trade - update reward (TD, temporal difference RL)

Really simple usage of library

Yes, this seems much simple as well as robust at the same time...let's experiment and see...Great job!!!!!

So where is the use of GDMH?

I was thinking of writing my GDMH code. You can just show me the code where RDF input and output is happening or where exactly you are trying to implement GDMH so that I will try to write my piece of code and then, we can compare the results both your code and my code and evaluate.

 
FxTrader562:

Yes, this seems much simple as well as robust at the same time...let's experiment and see..Great job!!!!!

So where is the use of GDMH?

I was thinking of writing my GDMH code. You can just show me the code where RDF input and output is happening or where exactly you are trying to implement GDMH so that I will try to write my piece of code and then, we can compare the results both your code and my code and evaluate.

Here I use simple kernel CRLAgent::kernelizedMatrix(void) (in library), so need to change this function for gdmh

 
Maxim Dmitrievsky:

Here I use simple kernel CRLAgent::kernelizedMatrix(void) (in library), so need to change this function for gdmh

Ok, let's see if I can write my own code....

If it is just about the GDMH logic, then I can easily translate or convert the GDMH algo into MQL5 code, but if it has to do with some other kernel functions or libraries, then I need time to study and convert...

 
FxTrader562:

Another feature: you can configure each agent in committee

CRLAgents *ag1=new CRLAgents("RlExp1iter",5,100,50,regularize,learn);
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   ag1.setAgentSettings(0,100,50,0.1); for each agent you can set number of features, number of trees and r setting, individually
   ag1.setAgentSettings(1,50,50,0.2);
   ag1.setAgentSettings(2,30,50,0.05);
   ag1.setAgentSettings(3,20,50,0.1);
   ag1.setAgentSettings(4,10,50,0.05);
//---
   return(INIT_SUCCEEDED);
  }

When fill predictors values just change here:

void calcSignal()
  {
   sig1=0;
       
   for(int i=0;i<ArraySize(ag1.agent);i++)
     {   
      CopyClose(_Symbol,0,0,ArraySize(ag1.agent[i].inpVector),ag1.agent[i].inpVector);
      Print(ArraySize(ag1.agent[i].inpVector));
      normalizeArrays(ag1.agent[i].inpVector);
     }
   sig1=ag1.getTradeSignal();
  }

Also you can add different groups of agents

CRLAgents *ag1=new CRLAgents("RlExp1iter1",5,100,50,regularize,learn);
CRLAgents *ag2=new CRLAgents("RlExp1iter2",1,20,50,regularize,learn);
CRLAgents *ag3=new CRLAgents("RlExp1iter3",18,5,50,regularize,learn);

 
FxTrader562:

Ok, let's see if I can write my own code....

If it is just about the GDMH logic, then I can easily translate or convert the GDMH algo into MQL5 code, but if it has to do with some other kernel functions or libraries, then I need time to study and convert...

If you can just convert gmdh logic - it will be very helpful, then I can change it for my library

Reason: