Hi,

I'm trying to run very simple code with filtering SPXW weekly options. It just loops over option chains between 2012 and 2024 years. At some point (around 35% progress) I get the System.outOfMemoryException or more strange error “Error invoking ?SPXW data reader. Line: StreamReader Error: string must be splittable on space into two parts”. I have a backtesting node with 8 Gb RAM. I do not understand why memory consumption increases while executing the code. Could somebody help to resolve the issue? 

 

 

 

from AlgorithmImports import *

class WeeklyPuts(QCAlgorithm):

    def initialize(self):
        self.set_start_date(2012, 1, 2) 
        self.set_end_date(2024, 12, 12)  
        
        self.set_cash(1_000_000)
        self.resolution = Resolution.HOUR

        self.index = self.add_index('SPX', resolution=self.resolution)
        self.index_symbol = self.index.symbol
        
        self.spxw_option = self.add_index_option(self.index_symbol, "SPXW", resolution=self.resolution)
        self.spxw_option.set_filter(self.spxw_filter)
        self.spxw_symbol = self.spxw_option.symbol

    def spxw_filter(self, universe: OptionFilterUniverse) -> OptionFilterUniverse:
        # return universe.include_weeklys().strikes(-1, 1).puts_only().expiration(0, 8)
        return universe.weeklys_only().strikes(-1, 1).puts_only().expiration(0, 8)


    def on_data(self, data: Slice):
        spxw_chain = data.option_chains.get(self.spxw_symbol)
        if spxw_chain is None or len(spxw_chain.contracts) == 0:
            return