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