I have been trying to add one of the universe filters from the documentation, but I am having an issue. The error code is that a number is not divisible by zero when creating the volume ratio. I tried changing the values to slightly  above zero, but that has not helped. Any advice?

 

 

 

class SelectionData(object):
       def __init__(self, symbol, period):
           self.symbol = symbol
           self.volume = 0.00000001
           self.volume_ratio = 0.0000000001
           self.sma = SimpleMovingAverage(period)
   
       def update(self, time, price, volume):
           self.volume = volume
           if self.sma.Update(time, volume):
               # get ratio of this volume bar vs previous 10 before it.
               self.volume_ratio = volume / self.sma.Current.Value           ## this line is the problem
class AddUniverse(QCAlgorithm):
   def Initialize(self):
       
       self.SetStartDate(2021, 5, 1)
       self.SetEndDate(2022, 5, 1)
       self.SetWarmUp(timedelta(days = 20))
       self.UniverseSettings.Resolution = Resolution.Minute
       self.AddUniverse(self.CoarseFilterFunction)
       
       
       self.SetCash(100000)
       self.SetTimeZone("America/New_York")
       self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Margin)
   
       self.timeCheck = False
       
 
       self.symbolData = {}
       self.stateData = {}
      
       for ticker in self.ActiveSecurities:
           symbol = ticker.Symbol
           self.symbolData[symbol] = SymbolData(self, symbol)
       everyday = self.DateRules.EveryDay()
       
       self.Schedule.On(everyday, self.TimeRules.At(10,00), self.SetEntryPrices)
       self.Schedule.On(everyday, self.TimeRules.At(15, 55), self.Liquidate)
       self.Schedule.On(everyday, self.TimeRules.At(15, 30), self.timeCheckNight)
       self.Schedule.On(everyday, self.TimeRules.At(10,00), self.timeCheckMorning)
       self.Schedule.On(everyday, self.TimeRules.Midnight, self.Reset)
       
       
       
       
   def CoarseFilterFunction(self, coarse):
       for c in coarse:
           if c.Symbol not in self.stateData:
               self.stateData[c.Symbol] = SelectionData(c.Symbol, 10)
           avg = self.stateData[c.Symbol]
           avg.update(c.EndTime, c.AdjustedPrice, c.DollarVolume)
       # filter the values of selectionData(sd) above SMA
       values = [sd for sd in self.stateData.values() if sd.volume > sd.sma.Current.Value and sd.volume_ratio > 0]
       
       # sort sd by the largest % jump in volume.
       values.sort(key=lambda sd: sd.volume_ratio, reverse=True)
       # return the top 10 symbol objects
       return [ sd.symbol for sd in values[:10] ]