This series of strategy development articles serves to illustrate the development process used for my algorithmic (or automated) trading strategies.
There are two main development workflows, depending on your choice of software. The first uses Metatrader 4’s strategy tester module, where we build a strategy from the ground up by incrementally adding entries, exits and finally filters.
The second workflow uses StrategyQuant, where we first run a genetic algorithm to automatically generate a basket of profitable strategies, which will then be subjected to several rounds of selection and robustness testing.
After developing a number of strategies, our focus then shifts to portfolio composition and monitoring techniques for live trading.
Through these articles, I hope to convince you that algorithmic trading is well within the means of the average retail trader. Feel free to use this development process as a reference or starting point; you should customize it to suit your particular trading style or market.
As a primer for the development process, this article will provide a brief overview of some strategy development concepts. Let’s dive right in!
What Is an Algorithm?
An algorithm is a computer program that converts an input to an output using a quantitative set of rules. In the case of trading, the input would be the market prices from your broker, while the output would be a certain trading action. Trading rules usually take the form of IF/THEN statements. For example, IF the price exceeds the 20-day moving average, THEN enter the market.
Your challenge as an algorithmic trader is to determine a profitable set of rules. Evaluating your profitability requires backtesting the algorithm using historical price data.
Robustness is a central theme in systematic trading. Simply put, robustness is the ability for a trading strategy to perform well over many markets. Because markets are always changing, I consider robustness to be the single most important quality in a strategy.
The chart below shows a trend strategy that was backtested on 5 forex majors over 17 years. All markets are profitable, which indicates strategy robustness. Unfortunately, this is the exception, rather than the norm.
On the flip side, it is quite common to produce a strategy that works great on one market, but fails on others. There usually has to be a trade-off between robustness and spectacular single-market performance.
Robustness is typically achieved by having a simple set of trading rules. As the saying goes, loose pants fit all.
Most authors in the trading literature seem to agree that a robust strategy should contain no more than four trading rules. Adding too many rules will constrain your algorithm to very specific market conditions. Your backtest will undoubtedly look great, but your live trading performance will suffer once the market deviates from your backtest conditions.
Optimization and Parameter Stability
Once you have determined your trading rules, you will need to decide whether you wish to optimize its parameters.
Using the algorithm example above (Buy if price exceeds 20-day moving average), the lookback period of the moving average may be optimized. A 50-day moving average may perform better than a 20-day moving average, especially if your market is often choppy.
If you plot your strategy performance as a function of your lookback period, you will likely get an optimization chart that resembles the hypothetical one below.
When selecting your parameter value, look for high plateaus on the graph. The parameter should be in a stable region, such that minor changes in parameter value will not drastically affect strategy performance.
In the chart above, a lookback period of 73 would be a more prudent option than 54. Although trading performance appears to be weaker, the strategy will be far more resilient to changing market conditions.
Strategies With Multiple Optimizable Parameters
What if your strategy contains more than one optimizable parameter?
For example, in addition to the ‘Buy if price exceeds 20-day moving average’ condition, suppose you wish to restrict your market entry to certain hours of the day. You may be wondering whether you should optimize your trading hours as well.
If you compare your optimization charts obtained before and after optimization of the second parameter, you may get either of the two graphs shown below.
The graph on the left shows that optimization of the second parameter has increased performance over a broad range of values, and is thus a robust improvement. On the other hand, the graph on the right shows an increase in peak performance at the expense of robustness.
For the second scenario, it is best to assign a constant value to the additional parameter, or omit the parameter entirely.
Simultaneous Parameter Optimizations
If you do decide to have several optimizable parameters, try not to optimize more than one parameter simultaneously. Apart from a serious increase in computation time, simultaneous optimization increases the risk of overfitting your trading rules to historical data, reducing your strategy’s robustness.
You may miss out on a particular combination of parameters that results in peak performance, but the improvement in robustness will be worth it.
For a more in-depth look at robustness in trading strategy development, I recommend the excellent book ‘Trading Systems: A new approach to system development and portfolio optimization’ by Emilio Tomasini and Urban Jaekle.
As a trading strategy developer, you will be running tons of backtests. Regardless of software, you will have to balance the conflicting requirements of test precision and computation speed.
Due to the countless variations of trading strategies that exist, I recommend a less precise backtest during the early stages of development. A high precision backtest will only be done on strategies that have passed all the selection criteria specified during development.
For example, during the Strategy Development portion of this roadmap (Parts 3a & 3b), backtests will be done using OHLC prices only. Promising strategies will be subsequently retested using tick data, under the Strategy Verification portion.
The vast majority of strategies I have developed tend to perform equally well or slightly worse (up to 10% poorer performance) when tested using tick data.
There is a small possibility that you will miss a great strategy by backtesting with lower precision in the early stages, but the overall time savings will more than compensate for it. After all, trading is a practical money-making endeavour, not an academic exercise.
Hopefully these basic strategy development concepts will help kickstart your algorithmic trading journey.
Personally, these are the core concepts that I adhere to during development. Of course, the list above is by no means exhaustive. As you acquire knowledge and experience, your list of core concepts will grow accordingly.
In the next section, we’ll talk about trading preferences and goals.