How to Backtest an Options Trading Strategy?
Options trading is risky, but backtesting can help in making trading decisions objectively. It helps to gain valuable insights into your option strategy such as
- Find the best strike prices for multi-leg options strategy
- Discover on which assets which options strategy works
- Identify market conditions in which your options strategy works and when it fails
- Evaluate the performance of different options strategies such as straddle and strangle
We have covered different strategies and options backtesting in Quantitative Trading in Options Learning Track
Note that backtesting results do not guarantee future performance. The presented strategy results are intended solely for educational purposes and should not be interpreted as investment advice.
Complexity level: Intermediate
In this Quantra Classroom, we will cover the following topics:
- Why Should You Backtest an Options Trading Strategy?
- Example Of An Options Trading Strategy (Long Butterfly)
- Steps To Backtest The Options Trading Strategy
- Get Data
- Set Up Entry And Exit Rules
- Backtesting
- Analyse Trades and Performance
- Bonus: Tips on Risk Management
- Can The Strategy Code Be Reused For Other Strategies?
If you are new to options trading, Options Trading Strategies In Python: Basic course would be helpful.
Why Should You Backtest An Options Trading Strategy?
Just a quick recap on why options backtesting is crucial for the following reasons:
Evaluate Strategy Performance: Backtesting allows you to assess how well a trading strategy would have performed in the past. This gives you insights into whether it's worth implementing in real-world trading.
Risk Management: You can assess the strategy drawdowns, volatility exposure, and the overall risk-return profile, which makes it easier to quantify the risk associated with the strategy.
Build Confidence: Since you get an idea of how the strategy is performing, you are prepared to take the necessary actions in case you want to exit or modify the parameters if the strategy performance deviates from its expected result.
Example Of An Options Trading Strategy (Long Butterfly)
In this classroom, we will backtest the long butterfly strategy and analyse its performance. Of course, you can use the framework to backtest your choice of options strategy as well.
What is the long butterfly strategy?
A butterfly options strategy consists of four legs. They are as follows:
- Buy one lower strike put option
- Sell middle strike call option
- Sell middle strike put option
- Buy a higher strike call option
This strategy is structured to profit from minimal price movement in the underlying asset.
The resulting position forms a profit zone around the middle strike price, making it suitable for scenarios where the trader expects the market to remain relatively rangebound or stable.
Figure: Payoff Diagram of the Long Butterfly Strategy
Are there any variations to the long butterfly strategy?
Yes, you can create a butterfly strategy which includes only calls or puts.
How do you decide the strike prices?
You can choose the middle strike price which is closer to the at-the-money(ATM) of the underlying. The difference between the lower strike price and the ATM middle strike price can be the sum of the 2 ATM option premiums. The difference between the higher strike price and the ATM option strike price is given by the same sum.
Middle strike price (To short ATM call and put) :
The price which is closer to the at-the-money(ATM) of the underlying
strike price
Lower strike price (To long OTM Put) :
Middle strike price - (premium of ATM call + premium of ATM put)
Higher strike price (To long OTM Call) :
Middle strike price +(premium of ATM call + premium of ATM put)
For example, if the ATM strike price is 14050, and the sum of the premium of the two options is approximately 550, then we can select the lower strike price as (14050 - 550) = 13500. And the higher strike price will be (14050+550) = 14600
The butterfly legs, their positions and the premium are illustrated below:
Option Type |
Strike Price |
Position |
Premium |
ATM CE |
14050 |
-1 |
280.75 |
ATM PE |
14050 |
-1 |
279 |
OTM CE |
14600 |
1 |
69.25 |
OTM PE |
13500 |
1 |
103 |
Now that you have selected an options strategy, let us see how you can backtest the strategy. The first thing you need for backtesting is “DATA!”
Steps To Backtest The Options Trading Strategy:
Step 1: Get Data
What kind of data do we need to trade in options?
Type of data
- Option data, which includes the strike price, date of expiry, open interest, volume of the call option or a put option.
- Price quotes related to the option contracts. Starting with the historical price data, which is nothing but the open, high, low and close. And also the last traded price.
- Strike price and expiry are the terms of the contract. They are probably the most important piece of information that you need for trading in options. The strike price is the price at which the option can be exercised. While the expiry date is the day on which the contract expires.
- For high to mid-frequency strategy, you can also look at the bid/ask price. Additionally to get an idea of the volumes you should also look at the bid/ask quantity. A better way to understand volume is the open interest. It shows how many contracts are currently open or active. This can be considered as a good liquidity filter.
Apart from this, you will also need the underlying asset’s data because each option is linked to an underlying asset. The underlying asset data is useful to determine the moneyness of the option and also the option’s Greeks.
In this Quantra Classroom, you will need the OHLC of the underlying asset, the strike price, and the days to expiry.
Note: The link will be accessible only after logging into quantra.quantinsti.com.
Step 1 is done. Now, we move on to the strategising part.
Step 2: Set up Entry and Exit Rules
Can you set up a butterfly options strategy any time of the year and expect the strategy to be profitable?
Of course not. You need to define entry rules, which specify a condition that must be fulfilled before you can set up the trade.
For this classroom, we are creating a long butterfly options strategy expecting that the market will have low volatility. Thus, you can use the implied volatility percentile to keep a check on expected volatility.
What is implied volatility?
Implied volatility (IV) is a measure of the market's expectations for future volatility or price fluctuations of an underlying asset.
The implied volatility percentile (IV percentile, or IVP) compares the current implied volatility of an options contract to its historical range of implied volatility over a specific period. It is expressed as a percentage and helps traders and investors assess whether the current implied volatility level is relatively high or low compared to its historical context.
Entry Condition?
Let’s create one rule that we will set up the long butterfly option strategy only when the IVP is more than 1 but less than 15. This number is for illustration purposes and you can change this depending on your logic.
Is this the only rule to check before setting up a long butterfly strategy?
It is not necessary that you need to have only one rule. You can create your own logical rules for setting up the long butterfly to ensure low volatility. For example, you can also check if the underlying asset is trending or not.
Here, the ADX indicator will be of help. Remember that an ADX indicator value of more than 30 indicates that the asset is trending. Since we would want to deploy a long butterfly in low volatility conditions, you can define that a long butterfly is set up only when the ADX indicator value of the underlying asset is less than 20. Again, this number is used for illustration purposes only.
What about the exit?
You can create exit conditions as well. For the sake of simplicity, you can exit at expiry.
Now that we know how to set up the long butterfly and when to enter and exit, we will move to the exciting part of this exercise, i.e. backtesting.
Step 3: Backtesting
For backtesting the strategy, NIFTY options and NIFTY futures data have been used, but you can use any European options and underlying asset such as S&P500 and the entry and exit rules can be similar.
Note: This notebook will be in “Free Preview” for a limited time only. So make sure you go through the notebook as soon as possible.
- You can check the code to backtest the short butterfly strategy by clicking on the button above. You can change the number in the “Entry Conditions” part of the notebook for IVP and ADX-related conditions.
- In the “Backtesting” part of the notebook, change the direction parameter to “long” instead of “short” and you will be backtesting the long butterfly options strategy using the conditions mentioned in this classroom.
Note: The links in this tutorial will be accessible only after logging into quantra.quantinsti.com.
From the period January 1, 2019, to May 26, 2022, the strategy took a total of 11 trades.
Analyse Trades and Performance
Trade level analytics of the strategy show that we have a profit factor of 2.08 with 6 winning trades and 5 losing trades.
Total PnL |
16032.25 |
Winning Trades |
11 |
Losing Trades |
5 |
Win Percentage |
54.55% |
Loss Percentage |
45.45% |
Per Trade Profit Winners |
6649.17 |
Per Trade Loss Losers |
3833 |
Average Holding Time |
19 |
Profit Factor |
2.08 |
You can see the average holding time as well, which is reported in days. The cumulative PnL of the strategy was 1.24 which is shown below.
Figure: Strategy PnL of the Long Butterfly Options Strategy
The PnL is not the only measure we should look at. What if you want to know the risk related to this strategy?
The maximum drawdown of the strategy was -26.48%.
Figure: Maximum Drawdown of the Long Butterfly Options Strategy
Note that backtesting results do not guarantee future performance. The presented strategy results are intended solely for educational purposes and should not be interpreted as investment advice.
Bonus: Tips on Risk Management
You must have realised that in this strategy, we were only exiting at expiry. A prudent strategy would be to keep a take profit and stop loss level so that you can exit when your target price is hit. You can also have other exit conditions based on the ADX indicator or the IVP. In this manner, you will be able to optimise the strategy.
Can The Strategy Code Be Reused For Other Strategies?
In this classroom, you have seen how to convert the short butterfly strategy to the long butterfly strategy using the parameter “direction” in the function “setup_butterfly”.
In a similar manner, you only have to create the function of the required option strategy once, and then you can use the same notebook for backtesting purposes.
What to do next?
Quantra’s All Courses Bundle offers a wide array of courses covering algorithmic and quantitative trading. These courses cover various options trading strategies, portfolio management, machine learning, and single asset strategies like mean reversion and momentum, and statistical tests. Take advantage of our limited-time 85% discount on Quantra’s All Courses Bundle today!
IMPORTANT DISCLAIMER: This email is for educational purposes only and is not a solicitation or recommendation to buy or sell any securities. Investing in financial markets involves risks and you should seek the advice of a licensed financial advisor before making any investment decisions. Your investment decisions are solely your responsibility. The information provided is based on publicly available data and our own analysis, and we do not guarantee its accuracy or completeness. By no means is this communication sent as the licensed equity analysts or financial advisors and it should not be construed as professional advice or a recommendation to buy or sell any securities or any other kind of asset.