Hello All,

I have a universe selection algorithm already successfully stores OHLC (Open, High, Low, Close) data into rolling windows and prepopulates those windows with historical data. I would like add another rolling window that stores the timestamps associated with those OHLC entries, but I am not sure how query the timestamps from historical pandas dataframe. Can anyone offer some guidance? The last line of the block of code below is where I am trying to query the timestamp.

  1. def OnSecuritiesChanged(self, algorithm, changes):
  2. # clean up data for removed securities
  3. symbols = [ x.Symbol for x in changes.RemovedSecurities ]
  4. if len(symbols) > 0:
  5. for subscription in algorithm.SubscriptionManager.Subscriptions:
  6. if subscription.Symbol in symbols:
  7. self.symbolDataBySymbol.pop(subscription.Symbol, None)
  8. subscription.Consolidators.Clear()
  9. # initialize data for added securities
  10. addedSymbols = [ x.Symbol for x in changes.AddedSecurities if x.Symbol not in self.symbolDataBySymbol]
  11. if len(addedSymbols) == 0: return
  12. self.windowLength = max(self.strategyLookback + 90,self.volatilityLookback)
  13. history = algorithm.History(addedSymbols, self.windowLength, self.resolution)
  14. for symbol in addedSymbols:
  15. self.openWindows[symbol] = RollingWindow[float](self.windowLength)
  16. self.highWindows[symbol] = RollingWindow[float](self.windowLength)
  17. self.lowWindows[symbol] = RollingWindow[float](self.windowLength)
  18. self.closeWindows[symbol] = RollingWindow[float](self.windowLength)
  19. self.timestampWindows[symbol] = RollingWindow[float](self.windowLength)
  20. for tuple in history.loc[symbol].itertuples():
  21. self.openWindows[symbol].Add(tuple.open)
  22. self.highWindows[symbol].Add(tuple.high)
  23. self.lowWindows[symbol].Add(tuple.low)
  24. self.closeWindows[symbol].Add(tuple.close)
  25. self.timestampWindows[symbol].Add(tuple.time)
+ Expand

Author

Garrett Grow

May 2022