this is the AAPL optionchain data, I got from backtest.the time in slice is 20230704,AAPL close price is 192.4.optionchain's expiry is 20230707.in this data, delta = 0.3 option contract strike = 175.The strike price of the option is $20 away from the stock price.
i get some data from my brokers.you can see AAPL price at $193 now. delta =0.3 option contract strike between $192.5 and $190. The gap is only a few dollars.
backtest data:
TIME:2023-07-04 00:00:00,AAPL:192.4,Option:AAPL 230707P00149000,Strike:149.0,Expiry:2023-07-07 00:00:00,ASK:0.01,BID:0.01,Delta:-0.236478804261922
TIME:2023-07-04 00:00:00,AAPL:192.4,Option:AAPL 230707P00150000,Strike:150.0,Expiry:2023-07-07 00:00:00,ASK:0.01,BID:0.01,Delta:-0.239559598372378
TIME:2023-07-04 00:00:00,AAPL:192.4,Option:AAPL 230707P00155000,Strike:155.0,Expiry:2023-07-07 00:00:00,ASK:0.01,BID:0.01,Delta:-0.255162110087234
TIME:2023-07-04 00:00:00,AAPL:192.4,Option:AAPL 230707P00157500,Strike:157.5,Expiry:2023-07-07 00:00:00,ASK:0.01,BID:0.01,Delta:-0.263097663700724
TIME:2023-07-04 00:00:00,AAPL:192.4,Option:AAPL 230707P00160000,Strike:160.0,Expiry:2023-07-07 00:00:00,ASK:0.01,BID:0.01,Delta:-0.271134462146621
TIME:2023-07-04 00:00:00,AAPL:192.4,Option:AAPL 230707P00162500,Strike:162.5,Expiry:2023-07-07 00:00:00,ASK:0.01,BID:0.01,Delta:-0.279283726129787
TIME:2023-07-04 00:00:00,AAPL:192.4,Option:AAPL 230707P00165000,Strike:165.0,Expiry:2023-07-07 00:00:00,ASK:0.02,BID:0.01,Delta:-0.288489067819784
TIME:2023-07-04 00:00:00,AAPL:192.4,Option:AAPL 230707P00167500,Strike:167.5,Expiry:2023-07-07 00:00:00,ASK:0.02,BID:0.01,Delta:-0.297221259150151
TIME:2023-07-04 00:00:00,AAPL:192.4,Option:AAPL 230707P00170000,Strike:170.0,Expiry:2023-07-07 00:00:00,ASK:0.03,BID:0.02,Delta:-0.307713950871447
TIME:2023-07-04 00:00:00,AAPL:192.4,Option:AAPL 230707P00172500,Strike:172.5,Expiry:2023-07-07 00:00:00,ASK:0.04,BID:0.03,Delta:-0.318382991974949
TIME:2023-07-04 00:00:00,AAPL:192.4,Option:AAPL 230707P00175000,Strike:175.0,Expiry:2023-07-07 00:00:00,ASK:0.04,BID:0.03,Delta:-0.328631358062776
TIME:2023-07-04 00:00:00,AAPL:192.4,Option:AAPL 230707P00177500,Strike:177.5,Expiry:2023-07-07 00:00:00,ASK:0.05,BID:0.04,Delta:-0.340465486635744
TIME:2023-07-04 00:00:00,AAPL:192.4,Option:AAPL 230707P00180000,Strike:180.0,Expiry:2023-07-07 00:00:00,ASK:0.06,BID:0.05,Delta:-0.353065225818468
TIME:2023-07-04 00:00:00,AAPL:192.4,Option:AAPL 230707P00182500,Strike:182.5,Expiry:2023-07-07 00:00:00,ASK:0.07,BID:0.06,Delta:-0.366730092849534
TIME:2023-07-04 00:00:00,AAPL:192.4,Option:AAPL 230707P00185000,Strike:185.0,Expiry:2023-07-07 00:00:00,ASK:0.09,BID:0.08,Delta:-0.38287388205752
TIME:2023-07-04 00:00:00,AAPL:192.4,Option:AAPL 230707P00187500,Strike:187.5,Expiry:2023-07-07 00:00:00,ASK:0.16,BID:0.15,Delta:-0.404782075889471
TIME:2023-07-04 00:00:00,AAPL:192.4,Option:AAPL 230707P00190000,Strike:190.0,Expiry:2023-07-07 00:00:00,ASK:0.45,BID:0.44,Delta:-0.435523303326642
TIME:2023-07-04 00:00:00,AAPL:192.4,Option:AAPL 230707P00192500,Strike:192.5,Expiry:2023-07-07 00:00:00,ASK:1.28,BID:1.26,Delta:-0.471817280492187
TIME:2023-07-04 00:00:00,AAPL:192.4,Option:AAPL 230707P00195000,Strike:195.0,Expiry:2023-07-07 00:00:00,ASK:2.9,BID:2.85,Delta:-0.510988013737577
broker's data:

Mia Alissi
The discrepancy you're seeing between the backtest data and your broker's data could be due to a number of factors. Here are a few possibilities:
Data Source: The data source used by QuantConnect might be different from your broker's data source. Different data sources might have slightly different prices due to factors like data cleaning methods, data collection methods, etc.
Data Time: The data time could also be a factor. The prices of options can change rapidly within a single day. If the QuantConnect data is from a different time than your broker's data, this could explain the discrepancy.
Modeling Assumptions: The Black-Scholes model, which is often used to calculate option prices and Greeks, makes several assumptions (e.g., constant volatility, no dividends, etc.). If QuantConnect and your broker use different assumptions or models, this could lead to different prices and Greeks.
To get the delta of an option contract in QuantConnect, you can use the
Greeks.Delta
property of the contract object. Here's an example in Python:To check if a contract is in the portfolio, you can use the
Portfolio
property of the algorithm object:If you want to select a contract with a specific delta, you can sort the contracts by the absolute difference between their delta and the target delta. Here's an example:
Sources:
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
HONGYUZHANG
The discrepancy is so large that it makes it difficult for me to properly determine which Delta contracts I should select in backtesting. In live trading, I usually choose contracts with Delta=0.3.
Mia Alissi
I understand your concern. The discrepancy between backtesting and live trading can indeed affect the selection of contracts. However, it's important to note that backtesting is a simulation based on historical data and it may not perfectly match live trading due to various factors such as data source differences, data time, and modeling assumptions as mentioned earlier.
In QuantConnect, you can select contracts based on Delta in your algorithm. Here's an example of how you can iterate through the contracts in the OptionChain to check their delta values:
You can adjust the
tolerance
variable to control how close the contract's delta needs to be to 0.3.Remember, the performance of the strategy in backtesting is just an estimation of its performance in live trading. It's always a good idea to use paper trading to validate your strategy before going live.
Sources:
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
HONGYUZHANG
Can I choose other option pricing models in backtesting?
Mia Alissi
Yes, you can choose different option pricing models in QuantConnect for backtesting. The pricing model of an option can be set using the
PriceModel
property. Here's an example of how you can set the price model to CrankNicolsonFD in Python:If you don't have access to the
Option
object when you subscribe to the Option universe or contract, you can set the price model in a security initializer.Please note that different pricing models might result in slightly different estimated implied volatility, which could affect the calculation of Greeks and option prices.
Source: Documentation: Pricing
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
HONGYUZHANG
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!