Discussion of article "Parallel Particle Swarm Optimization"


New article Parallel Particle Swarm Optimization has been published:

The article describes a method of fast optimization using the particle swarm algorithm. It also presents the method implementation in MQL, which is ready for use both in single-threaded mode inside an Expert Advisor and in a parallel multi-threaded mode as an add-on that runs on local tester agents.

From an algorithmic point of view, the PSO method is relatively simple. The main idea is to generate a set of virtual "particles" in the space of the Expert Advisor's input parameters. The particles then move and change their speed depending on the EA's trading metrics at the corresponding points in space. The process is repeated many times until the performance stops improving. The pseudo-code of the algorithm is shown below:

Particle Swarm Optimization Pseudo-Code

Particle Swarm Optimization Pseudo-Code

According to this code, each particle has a current position, speed and memory of its "best" point in the past. Here, the "best" point means the point (a set of EA input parameters), where the highest value of the objective function for this particle was achieved. Let us describe this in a class.

  class Particle
      double position[];    // current point
      double best[];        // best point known to the particle
      double velocity[];    // current speed
      double positionValue; // EA performance in current point
      double bestValue;     // EA performance in the best point
      int    group;
      Particle(const int params)
        ArrayResize(position, params);
        ArrayResize(best, params);
        ArrayResize(velocity, params);
        bestValue = -DBL_MAX;
        group = -1;

The size of all arrays is equal to the dimension of the optimization space, so it is equal to the number of the Expert Advisor parameters being optimized (passed to the constructor). By default, the larger the objective function value, the better the optimization. Therefore, initialize the bestValue field with the minimum possible -DBL_MAX number. One of the trading metrics is usually used as a criterion for evaluating an EA, such as profit, profitability, Sharpe ratio, etc. If optimization is performed by the parameter whose lower values are considered better, such as for example drawdown, appropriate transformations can be made to maximize opposite values.

Arrays and variables are made public to simplify access and their recalculation code. Strict adherence to the OOP principles would require hiding them using the 'private' modifier and describing read and modify methods.

Author: Stanislav Korotky

Stanislav Korotky
Stanislav Korotky  

Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий

Обсуждение статьи "Параллельная оптимизация методом роя частиц (Particle Swarm Optimization)"

Stanislav Korotky, 2020.08.24 10:45

I am attaching a slightly modified header file and an example of a test EA. The Settings class, helper functors, and templated event handlers have been added to the ParticleSwarmEmbed.mqh file. It is assumed that the user is satisfied with the default implementation. Then the code of the Expert Advisor ExprBotPSOEmbed.mq5 is greatly simplified. It is enough to describe your trading calculation and to forward the handlers to the PPSO_EventHandlers class. The input variables also contain the PSO dynamics adjustment factors (inertia, etc.), as well as the disabling of index files.