Requesting clues as to how to avoid issues when calculating talib metrics on securities that probably don't have data.
Running this code on a set of known securities with consistent data is no issue:
def HandleEntry(context, data):
closes = history(DailyPeriods + 1, "1d", "close_price").resample("1w")
closes = closes.dropna()
means = closes.apply(talib.MA, timeperiod = WeeklyPeriods, matype = MAType.TRIMA)
sigmas = closes.apply(talib.STDDEV, timeperiod = WeeklyPeriods)
zScores = ((closes - means) / sigmas).iloc[-1]
But if set_universe or update_universe is used, undoubtedly there will be issues with data for some security and at "iloc[-1]" I'll get an index out of bounds error.
So, anyone know how to protect against or eliminate the bad apples from the series before this calculation?
Perhaps retrieve the calculated series first and manually iterate looking for and nixing the rotten rabblerousers?