I'm working with 0DTE SPX options in a research notebook and I am wanting to get the PnL of options held to expiration. I started to pull the daily SPX close price but noticed that doesn't match up the actual settlement price for SPX so my PnL will be wrong by some amount. What is the correct way to get option settlement pnl in a research notebook?
Mia Alissi
To calculate the PnL of options held to expiration, you need to consider the settlement price of the options. In QuantConnect, you can use the
GetOptionHistory
method to get historical data for an entire Option chain. This method returns anOptionHistory
object, which you can iterate through to get each slice in theOptionHistory
object.Here is an example of how you can use this method in Python:
In the
all_history
DataFrame, you can find the settlement prices of the options. You can use these prices to calculate the PnL of the options held to expiration.Please note that the settlement price of SPX options is determined by the opening prices of the individual stocks in the S&P 500 index, not the closing prices. Therefore, the daily close price of SPX may not match the actual settlement price of the options.
For more information, you can refer to the QuantConnect documentation on US Equity Options.
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.
Jay Steinman
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!