32. Critical Mistakes in Backtesting

Published at 1654310305.49181

Testing on past data provides algorithmic traders a perspective into the future. They can form reasonable expectations on profit margins, maximum drawdown, and other key indicators. Some serious errors in this phase can make prediction results meaningless and invalid, and leave actual results to randomness.

Properly executing backtesting will form reasonable assumptions about the future trading results of the algorithm. Without careful design and proper assumptions, test results can create wrong expectations for high profits while consistently losing on real trades.

Below are five critical mistakes in the backtesting phase.

Overfitting

This is the most common mistake that gives algorithmic traders the illusion of finding the holy grail. Overfitting can appear in a variety of ways:

  • Buy at the lowest price of the candle chart and vice versa. For example, buy a stock at 100,000 VND even though the current share price is 105,000 VND.

  • Gain knowledge of future events or use future data to make decisions at the moment. A simple approach is to buy a stock if its price rises 20% next month. It can be done in backtesting and often gives outstanding results.

  • Find the best set of parameters. By adding parameters to an algorithm, a trader can always find the best set that gives an outstanding return on investment. It’s often confused between overfitting and optimization. Many experienced algorithmic traders still do not distinguish these two important concepts.

Excluding Transaction Fees

Many algorithmic traders set the transaction cost to zero, and expect a small difference in real trading. This is a mistake since transaction fees in the real market significantly reduce profit margins.

As of June 3, 2022, on the Vietnamese derivatives market, the total transaction fees in both directions are approximately 0.12% of trading value. Assuming an active algorithmic trader trades one long position and closes it every day, the investment result will be negative 30% at year-end by transaction fees only. If the expected portfolio return is at an impressive rate of, say, 25%, the trader will still lose at year-end.

The figure below simulates an algorithm with a 25% expected return before transaction fees. It shows the real return after fees in a year with two trades every day:

Ignore Slippage

The next irrational assumption is zero price slippage. This assumption even causes more harm than zero transaction fees. The concept of slippage is the same as transaction fees. It occurs in every transaction, and the difference is the slippage may be almost twice the transaction fees. From hundreds of thousands of contracts traded on the Vietnamese derivatives market, ALGOTRADE expects a two-way slippage at 0.7 points or 0.25% of trading value with market orders. This cost can significantly reduce the profit margin and can turn a potential algorithm into a disastrous failure.

The figure below simulates an algorithm with a 25% annual expected return before any slippage. It shows the real return after slippage in a year with two trades every day using market orders.

No Liquidity Restrictions

This is an assumption that makes algorithms unable to trade. It’s more common for large investors. The reason is that in backtesting phases, the algorithm can buy or sell an unlimited number of shares and contracts at the market price. In real trading, algorithmic traders may see positions unmatched in this scenario.

Fastest Speed on the Market

This is an assumption from many high-frequency traders. They often assume algorithms can achieve the best speeds in the current market. This assumption creates an illusion of outstanding performance but may in fact result in unmatched orders. Even worse, algorithms  only buy or sell at a matched price completely different from their expectations.