I am trying to implement a Rolling Window within the SymbolData class for an ensemble of SMA's. 

Essentially each security will have a RollingWindow dict to store the results of the various lookback windows - and it is using a Dict with a RollingWindow that is causing my troubles. The error I am receiving is…

  1. During the algorithm initialization, the following exception has occurred: AttributeError : 'dict' object has no attribute 'Add'
  2. at SmaUpdated
  3. self.smaWindow.Add(updated)
  4. File "main.py" in main.py:line 43
  5. AttributeError : 'dict' object has no attribute 'Add'

And the class is below. Any help would be greatly appreciated!

  1. class SymbolData:
  2. def __init__(self, symbol, algorithm):
  3. self.algorithm = algorithm
  4. self.Symbol = symbol
  5. self.sma = {}
  6. self.smaWindow = {}
  7. # Build an "Ensemble" of Moving averages
  8. self.sma = algorithm.SMA(self.Symbol, 9*21, Resolution.Daily)
  9. self.smaWindow = RollingWindow[IndicatorDataPoint](2)
  10. self.sma.Updated += self.SmaUpdated
  11. def SmaUpdated(self, sender, updated):
  12. '''Event holder to update the fast SMA Rolling Window values'''
  13. self.smaWindow.Add(updated)
+ Expand

Author

Mark Reeve

July 2021