Before we jump into why we must backtest trading strategies, lets first understand what backtesting is!
Investopedia defines it best as: “Backtesting allows a trader to simulate a trading strategy using historical data to generate results and analyse risk and profitability before risking any actual capital.”
For us, the primary reason to backtest is to determine profitability and risk. How good was the strategy’s return historically? And how much did we risk to make that return? A backtest answers these questions quite well.
Backtesting, if used correctly, is a powerful tool to help evaluate trading strategies. However, as with any tool, it has limitations. As a silent observer over the past few months, we’ve witnessed people pile into now crowded strategies after backtesting them (ehm the #920Straddle and its variations). Some people made money. Others didn’t. Some lost a lot with the so called #freaktrades. Our purpose here is to explain the benefits and limitations of backtesting trading strategies in India as we understand them, while also making backtesting accessible to everyone interested.
Limitations of Backtesting Trading Strategies in India
There are some questions that a backtest doesn’t answer well though. Questions like:
- I have now discovered a strategy that has excellent backtest results. Will it continue to make money when deployed in live trading?Answer: Maybe.
- When it is time to enter or exit a trade based on my backtested strategy logic, what is the actual price I will get from the market? Eg if according to my strategy, it is time to buy a stock/option where the LTP (last traded price) is Rs 100. When I place an order to buy, at what price will I actually be able to buy? Rs 100? Or is it Rs 105? Maybe Rs 95?Answer: Depends.
So how should we actually use Backtesting Trading Strategies on AlgoTest?
We at AlgoTest use backtests as part of a 3-step strategy deployment cycle.
- Step 1, Backtest: Backtest strategy logic with historical data. Iterate until the results look promising.
- Step 2, Paper trade/Forward Test: Run the backtest logic as is on live data without actually entering trades. Log every potential trade and aggregate the trades to arrive at a simulated P&L.
- Step 3, Live deployment: If results of Steps 1 and 2 are close, you can deploy the strategy to the live market
Can we skip Step 2?
We see a lot of people using a fixed historical dataset, eg data from 2018-present to develop a strategy iteratively. They then add parameters and tweak them until the strategy backtest gives good results. This historical dataset is called “in-sample” data. Then they deploy this strategy to the live market, and don’t get as good results as the backtest result. One of the reasons behind this discrepancy is data snooping (or data dredging).
A key missing ingredient is Step 2: freeze your strategy parameters after a successful backtest, and follow that up with paper trading. Paper trading entails running your strategy on market data different from the data used for developing it. In this case, run your strategy against live market data. This data against which you’re testing the strategy parameters is called “out-of-sample” data. So you develop your strategy using in-sample data, freeze the strategy parameters, then run it against the out-of-sample data. If the results are comparable, then the odds of data-snooping are lower than before, and your strategy might be the real deal.
Data Snooping in Backtesting
From investopedia – “Similarly, traders must avoid data dredging, in which they test a wide range of hypothetical strategies against the same set of data, which will also produce successes that fail in real-time markets because there are many invalid strategies that would beat the market over a specific time period by chance. One way to compensate for the tendency to data dredge or cherry-pick is to use a strategy that succeeds in the relevant, or in-sample, time period and backtest it with data from a different, or out-of-sample, time period. If in-sample and out-of-sample backtests yield similar results, then they are more likely to be proved valid.”
Another approach for Step 2 could be to split your historical dataset into non-overlapping, in-sample and out-of-sample datasets. In this case, you develop your trading strategy using the in-sample dataset, and validate it using the out-of-sample dataset. If the results between the two datasets are similar, you can go live with more confidence.
Key market reality
This meme explains it best.
Past performance does not guarantee future performance. If there’s one thing you should take away from backtests, it’s this. Market regimes change all the time. Strategies that showed exceptional returns in the past through backtests may not be as profitable in the future. Strategies that were once profitable, but not anymore, may yet become profitable again.
Even if we complete Steps 1 and 2 well, we can still lose money in Step 3. In fact this is an inevitability, as market regimes change over time, execution issues via slippages, etc.