Discussion of article "Applying the Monte Carlo method for optimizing trading strategies"

 

New article Applying the Monte Carlo method for optimizing trading strategies has been published:

Before launching a robot on a trading account, we usually test and optimize it on quotes history. However, a reasonable question arises: how can past results help us in the future? The article describes applying the Monte Carlo method to construct custom criteria for trading strategy optimization. In addition, the EA stability criteria are considered.

Let's explain all above by the graph. It shows several capital curves. Each of them is determined by the generated sequence of trades. I marked the curves with different colors for more convenience. In fact, their number is much larger — several tens of thousands. For each of them, we calculate the necessary parameters and make statistical conclusions based on their totality. Obviously, the most important of these characteristics is the final profit.

Generated capital curves

Other approaches to probabilistic formalization and further EA operation modeling are possible as well. For example, instead of sequences of trades, we can simulate price sequences and study the aggregate profits the EA has obtained on them. The principle of generating price series can be selected depending on a task you want to solve. However, this method requires much more computing resources. In addition, MetaTrader currently provides no regular ways to use it with a random EA.

Author: Aleksey Nikolayev

 

Функция setks() вычисляет массив прибылей сделок, исходя из истории торговли. 

bool setks(double &k[])
  {
   if(!HistorySelect(0,TimeCurrent())) return false;
   uint nhd=HistoryDealsTotal();
   int nk=0;
   ulong hdticket;
   double capital=TesterStatistics(STAT_INITIAL_DEPOSIT);
   long hdtype;
   double hdcommission,hdswap,hdprofit,hdprofit_full;
   for(uint n=0;n<nhd;++n)
     {
      hdticket=HistoryDealGetTicket(n);
      if(hdticket==0) continue;

      if(!HistoryDealGetInteger(hdticket,DEAL_TYPE,hdtype)) return false;
      if(hdtype!=DEAL_TYPE_BUY && hdtype!=DEAL_TYPE_SELL) continue;

      hdcommission=HistoryDealGetDouble(hdticket,DEAL_COMMISSION);
      hdswap=HistoryDealGetDouble(hdticket,DEAL_SWAP);
      hdprofit=HistoryDealGetDouble(hdticket,DEAL_PROFIT);
      if(hdcommission==0.0 && hdswap==0.0 && hdprofit==0.0) continue;

      ++nk;
      ArrayResize(k,nk,NADD);
      hdprofit_full=hdcommission+hdswap+hdprofit;
      k[nk-1]=1.0+hdprofit_full/capital;
      capital+=hdprofit_full;
     }
   return true;
  }

The highlighted assumes that some closing trades with zero profit are somehow not included in the sample, while some opening trades are.

Try DEAL_ENTRY.


Do swap and commission have to be calculated when analysing Monte Carlo trades? They have no systemic value.

I would recommend using the ratio of opening and closing prices as profit. Here we can discuss "should lots be taken into account?".

 

On the one hand it is assumed that transactions are independent.

On the other hand, it is difficult to imagine a TS where trades are independent.


For example, if you already have a position open, you cannot ignore this circumstance when deciding to make a trade.

It turns out that monte carlim is a non-random value. Or do I not understand something?

 
fxsaber:

The highlighted assumes that some closing trades with zero profit are somehow not included in the sample, while some opening trades are.

Try DEAL_ENTRY.

For simplicity of the model, we consider as deals only those that affect the capital curve.

 
fxsaber:

Do swap and commission have to be calculated when analysing Monte Carlo trades? They do not have a systemic value.

It depends on the EA device, I think. If their value is small, it will not affect the calculation of the optimisation criterion, if it is large, neglecting them will distort the optimisation results.

 

fxsaber:

I would recommend using the ratio of opening and closing prices as profit. Here we can discuss the topic "should lots be taken into account?".

What you are talking about is similar to what I called profitability in the article about risk. In that article, we are studying the EA from the inside, while here we take it as a given - a "black box" and managing the trade size is an integral part of it. This means that the distribution of profits can be very different from the distribution of returns. So, if we rely only on returns, we will be optimising a very different EA.

 
fxsaber:

On the one hand, it is assumed that the transactions are independent.

On the other hand, it is difficult to imagine a TS where transactions are independent.


For example, if you already have an open position, you cannot ignore this circumstance when deciding to make a trade.

It turns out that monte carlim is a non-random value. Or do I not understand something?

Of course, independence of trades is an idealisation. If two trades do not overlap much in time, we can consider them independent because prices can be considered a random process with independent increments to a first approximation. That is, independence and randomness are determined by the exit price of the transaction. For definiteness, a trade here is what in MT4 is called a position. I have already tried to give some considerations on the subject of independence of trades in the article.
 
Aleksey Nikolayev:
Of course, the independence of trades is an idealisation. If two deals do not overlap much in time, then we can consider them independent, because prices in the first approximation can be considered as a random process with independent increments. That is, independence and randomness are determined by the exit price of the transaction. For definiteness, a trade here is what in MT4 is called a position. I have already tried to give some considerations on the topic of trades' independence in the article.

But other trades that did not open because they were already open - what about them? And those trades that opened, according to the signals of the same torus logic, but which were just lucky that there were no other trades open at the moment of the trade signal - are they any special?

This is where some contradiction lies. Perhaps it would be reasonable to montecarlise trade signals. They really do not depend on each other, as they are a function of price only.

 
fxsaber:

But other trades that did not open because they were already opened - what about them? And those trades that opened, according to the signals of the same torus logic, but which were just lucky that there were no other trades open at the moment of their opening trade signal - are they any special?

This is where some contradiction lies. Perhaps it would be reasonable to montecarlise trade signals. They really do not depend on each other, as they are a function of price only.

The approach of the article is precisely that we do not go into the logic of the Expert Advisor, but take the result of its work "as it is". Your approach will probably give more accurate results, but will require much more work in programming and analysing the results.
 

Thanks for the article, but didn't see the tests on the forward, as the main goal was to improve the robustness of the TS on the new sample by introducing new optimisation criteria

But there is a lot to think about.

 
Maxim Dmitrievsky:

did not see tests on the forward, as the main goal was to improve the stability of the TS on a new sample by introducing new optimisation criteria

You are right, it is lacking. But for a meaningful result it would be necessary to conduct it for a sufficiently large number of time intervals, symbols and EAs (law of large numbers). There was no desire to bloat the article too much.