I'm trying to implement an algorithm using option spreads. To decrease the memory usages and manual filtering in “on_data”, I would like to create an option filter with 2 strike price ranges. For example, I want all the call options that have a strike price between 0.7 and 0.8 of the underlying stock price AND all the call options that have a strike price between 1.03 and 1.05 of the underlying stock price. I don't want to see any other options in the option chain.

It feels like the right idea is to use “.set_filter” in the “initialize” method:

class MySpreadOptionAlgorithm(QCAlgorithm):
    def initialize(self):
    	...
    	equity = self.algorithm.add_equity("SOME EQUITY SYMBOL", Resolution.HOUR)
        equity.set_data_normalization_mode(DataNormalizationMode.RAW)
        self.symbol_equity = equity.symbol
		option = self.add_option(self.symbol_equity, Resolution.HOUR)
		option.set_filter(filter_function)
		...

Then, implement the filter_function:

def filter_function(universe:OptionFilterUniverse):
    current_equity_price = universe.underlying.price
    # Logic to reduce the option universe to only the call options with the specific strike price ranges

I've scoured code examples, documentation and exhausting dialogs with Mia, but I can't figure out how to implement that logic.

Can anyone point me in the right direction?

Thank you.