Hey all, I've cannibalized the following code to suit my desire to test the alpha surrounding the SMI factor, but I am unsure of how exactly to analyze the look-back period of the custom factor or of the individual metrics themselves.
class SMI(CustomFactor):
inputs = [USEquityPricing.close, USEquityPricing.high, USEquityPricing.low]
def compute(self, today, assets, out, close, high, low):
maxi = talib.MAX(high, timeperiod = 8)
mini = talib.MIN(low, timeperiod = 8)
center = (maxi+mini*.5)
c = (close[-1] - center)
H1 = talib.EMA(c, timeperiod = 3)
H2 = talib.EMA(H1, timeperiod = 3)
D = talib.EMA((maxi-mini), timeperiod = 8)
D1 = talib.EMA(D, timeperiod = 3)
D2 = .5*talib.EMA(D1, timeperiod = 3)
SMI = (H2/D2)
SMI_signal = talib.EMA(SMI, timperiod = 3)
What I'd like to do is to follow the general guidelines posted here: https://www.youtube.com/watch?v=dDFewKqNDfU
with the initial look-back period to be 8 days, followed by two, 3-day EMA smoothing periods for each D and H, and then an 8-day EMA smoothing period of the SMI as a signal. All that being said, if the data set were to start on say day 1, there shouldn't be any signal until day 19 (7 days until the first H, 2 days until the first H1, 2 days until the first H2, repeat the process for D so no new days there, then lastly 8 days until the first SMI signal).
I'm not confident my current code is doing this however, rather I think each time period acts independently and is pulling data that way, i.e. instead of starting on day 1 or current day -19, I'm just starting on current day -8. That would cause the whole code to be incorrect. And on that note, is there a way I could make this code have a look-back period of 100+ days and just pull the most recent SMI and SMI signal? The ways this algebra works the more data available in the look-back, the higher the resolution, i.e. 100 days of data >>> 19 days of data.
Thanks in advance! Let me know if you need any additional info.