Hi Guys,
Noobie here when it comes to coding. I'm struggling trying to figure out how to calculate Net Open Interest for the SPX in my algorithm. I'm thinking (I could be wrong) the best way to go about it would be to calculate it and then store the values in a dictionary to be looped through on a daily basis since I'll be using significant net oi levels as an integral part of my trading strategy.
I know there is an option filter method for OI but I can't use that to determine significant net values that I'll need daily. I've looked through the documentation as well and had no luck, maybe I'm just missing something. Here is a snippet of my failed code, which I already know is incorrect so any help would be greatly appreciated!
def Initialize(self):
# Set starting cash and backtest dates.
self.SetCash(100000)
# Example: if today is 2025-02-09, start one month ago:
self.set_start_date(2025, 1, 9)
self.set_end_date(2025, 2, 9) # adjust as needed
# Add the SPX index at minute resolution.
self.index_symbol = self.add_index("SPX", Resolution.Minute).symbol
# Add the options chain for the SPX index.
option = self.add_index_option(underlying = self.index_symbol, target_option="SPXW", resolution=Resolution.Minute)
option.set_filter(lambda option_filter_universe: option_filter_universe.include_weeklys().expiration(0, 0).strikes(-10, 10))
#Finding Net OI
Net_OI = option.calls_only().oi - option.puts_only().oi
Mia Alissi
Sources: Basic Template Index Options Algorithm, Basic Template S P X Weekly Index Options Algorithm, Index Option Bull Call Spread Algorithm, Basic Template Index Daily Algorithm, Index Option Iron Condor Algorithm
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.
Nicholas T
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!