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? 

 

 

 

  1. from AlgorithmImports import *
  2. class WeeklyPuts(QCAlgorithm):
  3. def initialize(self):
  4. self.set_start_date(2012, 1, 2)
  5. self.set_end_date(2024, 12, 12)
  6. self.set_cash(1_000_000)
  7. self.resolution = Resolution.HOUR
  8. self.index = self.add_index('SPX', resolution=self.resolution)
  9. self.index_symbol = self.index.symbol
  10. self.spxw_option = self.add_index_option(self.index_symbol, "SPXW", resolution=self.resolution)
  11. self.spxw_option.set_filter(self.spxw_filter)
  12. self.spxw_symbol = self.spxw_option.symbol
  13. def spxw_filter(self, universe: OptionFilterUniverse) -> OptionFilterUniverse:
  14. # return universe.include_weeklys().strikes(-1, 1).puts_only().expiration(0, 8)
  15. return universe.weeklys_only().strikes(-1, 1).puts_only().expiration(0, 8)
  16. def on_data(self, data: Slice):
  17. spxw_chain = data.option_chains.get(self.spxw_symbol)
  18. if spxw_chain is None or len(spxw_chain.contracts) == 0:
  19. return
+ Expand

Author

Alexander Suvorov

December 2024