HomeServicesContactBlog

Developing a Trading Algorithm

This article will briefly cover the process of developing a trading algorithm, from the birth of an idea to launching the algorithm into "battle."

Finding an Idea

First, you need an idea for the algorithm. There is a wealth of underestimated ideas in open sources that can be exploited. In this article, we will consider medium-term algorithms as an example (about 250 trades per year).

Development

There is plenty of software for such tasks, for every taste. I use TSLab. To make algorithm testing results closer to reality, you can apply a condition — skip opening and closing trades during the first minute of the trading session. This is because the first minute of the trading session is often illiquid. It is necessary to set a commission. For RTS and SI, it is advisable to use a relative commission of 0.03%; for SBRF, an absolute commission of 3 points. This value should account not only for the broker and exchange commissions but also for slippage and spread. Depending on the algorithm, slippage will vary — breakout algorithms have high slippage, while trades executed at the bar close have lower slippage.

Optimization

Next, you need to optimize the parameters. At this stage, I optimize parameters on all available historical data. For TSLab users, it will be useful to know — before optimization, set the "Start from (bar)" property in the script settings to the value of the longest parameter +1. After optimization, pay attention to a couple of characteristics:

Forward Test or Blind Simulation

The next stage is the most labor-intensive, especially for TSLab users who have to use office packages — fortunately, TSLab allows data export. Walk forward analysis (WFA) is a method for evaluating effectiveness. The method was developed by Robert Pardo and is described in detail in his book. The method involves optimizing parameters on the in sample (IS) segment and testing these parameters on the blind out of sample (OOS) segment. Simply put, the algorithm is optimized on a data segment where subsequent parts are deliberately excluded. Then the algorithm's performance is tested using the obtained parameters on the excluded data. It is recommended to conduct at least ten tests, and the OOS window should not exceed 20% of the total segment. This approach eliminates the possibility of curve-fitting to historical data because parameters are determined based on past data, not current data, and are tested on a blind zone. There are two testing methods — fixed sliding window

images-6.jpg is 3 years, oos 1 year

images-7.jpg 2.5 years, oos half a year

and a constantly increasing IS period.

images-8.jpg oos 1 year

images-9 oos half a year

The fourth method shows more favorable results. I tested four algorithms and compared the sum: wfe (Ewfe), ratio drawdown (Erdd) and the ratio: wfe-ratiodd (Erwd), Ewfe-Erwd and Ewfe-Erdd (R f-g)

I agree that the very fact of choosing a testing method is already a form of curve-fitting, but the goal is to find the most reliable method without looking into the future. The method has a right to exist. The most important characteristics at this stage are:

Example of one of the algorithms. WFE 64.77, ratioDD 91.02

As we can see from the example above, the algorithm shows a profit at 64% of the optimization segment — this seems plausible. The average drawdown indicator at 91.02% is also acceptable, but if you look at the maximum value, it's quite possible that the real drawdown could be double the drawdown on the optimization segment.

The entire process analyzed above is not a guarantee of success, only a way to predict the algorithm's future performance, and by no means the only method.


Interesting materials:
Curve-fitting and other methods of parameter selection
On the subject of optimization