Backtesting a rule based trading system

Trading the markets requires taking tough decisions under uncertainty. In markets, nothing is a sure thing. Anything can happen anytime. Under such conditions, the only aid we have is past data. We can never predict the future, but can only bet on the probability of something happening. If probabilities are in favour, we win in the long term. With enough data, we can find patterns which have given returns over long term in the past. Using such patterns gives us an edge in the market and thus a chance to make money. Finding such patterns and validating their effectiveness is called backtesting.

In this blog, I am going to present a trading system, which has all the rules of entry, exit and stop loss defined beforehand. The benefit of having pre-defined rules is that emotions do not influence our decision during live market hours. I will also present the backtest results of this system on the past data which will give confidence to the trader on its effectiveness.

I would like to thank Aneesh for introducing me to this system and allowing me to publish it on my blog. I also heard that the system was presented by expert trader Kirubakaran in one of his webinars. Though I did not get a chance to attend it but a big kudos to him as well. None of these strategies are trading recommendations from me, Aneesh or Kirubakaran.

Special Announcement

Before I begin with defining the system and providing the backtest results, I have a special announcement to make. I am starting a paid service for backtesting your trading strategies on Nifty spot, BankNifty spot, Nifty50 stocks, Nifty options & BankNifty options. I will write code exclusively for your strategy, and test it on upto 12 years of data. I will provide a few months of analysis for free for the choice of your underlying. If you like it, you can request for more months by paying a certain amount. For each backtest, I will be charging a fee of Rs. 75 per scrip for each additional month of analysis.

For availing the backtesting service you can contact me on tradewithoptionji@gmail.com

Defining the rules of the system

Coming back to our discussion on the rule based trading system, I will start by defining the exact rules on how to enter the trade, exit it, take profits, limit losses. This way, we do not have any ambiguity during live market hours.

  • This is a strictly intraday system. So any open position whether in profit or loss will be squared off at the end of the day. 
  • More than 1 trade can be taken per day.
  • There could be days with no trades taken at all.
  • Defining the Range.
    • Upper Range = Previous trading day high – Previous trading day open
    • Lower Range = Previous trading day open – Previous trading day low
    • Range = maximum of Upper Range & lower Range
  • Entry
    • Go Long if price goes above (Today Open + Range)
    • Else, Go Short if price goes below (Today Open – Range)
  • Exit
    • Keep SL at the open price of the day. So if the price touches the open price of the day, exit the position.
    • If SL is not hit, exit at 3:15 PM 
  • Trail SL
    • Do not trail the stop loss.
  • Underlying used for backtest : Nifty spot
  • Number of lots traded : 1
  • Lot size : 75

Now we have all the rules defined for our trading system. If you notice, we have not left any decisions to emotions or discretions. We exactly know where to enter & where to exit. Now the next step is to see how this system has actually performed in the past. Based on this backtest analysis, we will get some confidence if we should trade it with real money or not.

Backtest results

I will present the backtest results for 1 year data from 1 Jan 2019 to 31 Dec 2019

Note: Analysis includes brokerage of Rs. 20 per order, GST, STT, Stamp duty, other charges and some slippage

Pnl chart

Please zoom-in to the picture if it is not visible properly.

Net returns: Rs. 68214.39

Total trades: 125

Number of profits: 62

Number of loss: 63

Max Profit streak: 4

Max Loss streak: 8

Max drawdown duration: 53 trades

Max drawdown loss: -27963.39

Sharpe ratio: 1.76

Details of individual trade can be accessed by clicking on this link

Volatility analysis: I have done analysis of returns in different market volatility. Volatility is tracked using INDIA VIX index. In the below table, VIX is divided into ranges. For example, a VIX bucket of [10, 14] tells that on the day of entry, the VIX was in range [10, 14]

VIX analysis

What do these results say ?

The strategy was clearly profitable in 2019 after including charges and slippage. The net profit per Nifty lot is ~ Rs. 68K 

The strategy was a winner ~50% times in 2019. Even with a 50% win rate, 8 continuous losses were seen.

The maximum drawdown per Nifty lot given by this strategy in 2019 is ~ Rs. 28K

The strategy was profitable in all VIX conditions in 2019.

Let say that the starting capital for 1 Nifty lot was 3L. The strategy gave a return of ~22% after brokerage and slippage in 2019. The drawdown incurred was ~9.5% on the capital. Depending on the risk appetite, traders can trade 1 lot for lesser or more capital. Lower capital will ensure higher ROI at the cost of increased drawdown. Higher capital will lead to lower ROI with the advantage of reduced drawdown.

A word of caution [Very important] :

These results are just for the year 2019. Based on market conditions the results may significantly vary in different years. So these returns and drawdowns are only an indicative figure to give you an idea that the strategy may work. There is still not any guarantee that strategy will surely work in the future. The more number of years we do the backtest, the more confidence we get to deploy the strategy with real money.

The results are based on the backtest of Nifty spot data. The exact results may vary for trading futures & options. The spot data is only a good indicator for the behavior of derivatives and not the exact replica.

Want backtest results for more years or other stocks ?

The backtest I presented is only for Nifty in the year 2019. I can do the same analysis for many more years maybe uptil 2008, depending on the underlying. I have the results available for Nifty spot, BankNifty spot, Nifty50 stocks.

If you wish to get more backtest results for any of the mentioned underlying, you can get that for a fee of Rs 75 per scrip per additional month of data asked. For example if you need 6 months of backtest results on ASIANPAINT, you would need to pay Rs. 450 (6 * 75)

To get the backtest results, please contact me on tradewithoptionji@gmail.com

Want to backtest your own strategy ?

I am starting a paid service for backtesting your trading strategies on Nifty spot, BankNifty spot, Nifty50 stocks, Nifty options & BankNifty options. I will write code exclusively for your strategy, and test it on upto 12 years of data. I will provide a few months of analysis for free for the choice of your underlying. If you like it, you can request for more months by paying a certain amount. For each backtest, I will be charging a fee of Rs. 75 per scrip for each additional month of analysis.

For availing the backtesting service you can contact me on tradewithoptionji@gmail.com

Read about backtesting on BankNifty weekly options here.

Please subscribe to my blog and follow me on twitter to get all the latest updates.

Disclaimer: Stock market trading involves substantial risk and is not suitable for all investors. Investors may lose the entire amount of their investment in a relatively short period of time. It is possible to owe more than you have invested in your brokerage account. Please be aware of your broker’s requirements for trading. Before you decide to invest in the market you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a substantial loss which could total more than your initial investment in a short period of time. Therefore you should not invest money that you cannot afford to lose. If you have any questions or concerns regarding the risks associated with trading, you should confer with a trusted and reliable independent financial advisor. None of the information provided in this blog constitutes a solicitation to trade any investment or security of any kind.

Leave a Reply

Your email address will not be published. Required fields are marked *