Derek Melchin gave me the following code as example:

class MyAlphaModel(AlphaModel):
def __init__(self, algorithm):
fastPeriod = 20
slowPeriod = 60
self._tolerance = 1 + 0.001
self.IsUpTrend = False
self.IsDownTrend = False

symbol = algorithm.AddEquity("SPY", Resolution.Daily).Symbol
self._fast = algorithm.EMA(symbol, fastPeriod, Resolution.Daily)
self._slow = algorithm.EMA(symbol, slowPeriod, Resolution.Daily)

# Warm up history
history = algorithm.History(symbol, slowPeriod, Resolution.Daily).loc[symbol]
for idx, row in history.iterrows():
self._fast.Update(idx, row.close)
self._slow.Update(idx, row.close)

def Update(self, algorithm, slice):
if not (algorithm.UtcTime.hour == 16 and algorithm.UtcTime.minute == 0 and algorithm.UtcTime.second == 0):
return []

insights = []
for symbol in slice.Keys:
if symbol.SecurityType != SecurityType.Future:
continue
insights.append(Insight.Price(symbol, timedelta(minutes=59), InsightDirection.Up))

return insights

and I want to adjust it to IBS indicator.

So I have written the following:

class MyAlphaModel(AlphaModel):
def __init__(self, algorithm):

symbol = algorithm.AddEquity("SPY", Resolution.Daily).Symbol
symbolsIBS = dict()

# Warm up history
history = algorithm.History(symbol, 1, Resolution.Daily).loc[symbol]
for idx, row in history.iterrows():
c = row.close
h = row.high
l = row.low
o = row.open
hilo = h - l

if o * hilo != 0:
symbolsIBS[symbol] = (c - l)/hilo

self.Update(idx, symbolsIBS)

def Update(self, algorithm, slice):
if not (algorithm.UtcTime.hour == 16 and algorithm.UtcTime.minute == 0 and algorithm.UtcTime.second == 0):
return []

insights = []
for symbol in slice.Keys:
if symbol.SecurityType != SecurityType.Future:
continue
insights.append(Insight.Price(symbol, timedelta(minutes=59), InsightDirection.Up))

return insights

unfortunatelly this code fails with the following error:


During the algorithm initialization, the following exception has occurred: AttributeError : 'Timestamp' object has no attribute 'UtcTime'
at Initialize in main.py:line 39
:: self.SetAlpha(MyAlphaModel(self))
at __init__ in main.py:line 79
at Update in main.py:line 82
:: if not (algorithm.UtcTime.hour == 16 and algorithm.UtcTime.minute == 0 and algorithm.UtcTime.second == 0):
AttributeError : 'Timestamp' object has no attribute 'UtcTime'

any hint on how to write such custom AlphaModel?