I managed to get the following snippet of code to work in the research environment but have been hitting a wall in the IDE.
pxTLT = np.log(data.history(context.tlt, 'price', 100, '1d'))
weeklyTLT = pxTLT.resample('1M', closed='right', label='right').last().ffill()
pxSPY = np.log(data.history(context.spy, 'price', 100, '1d'))
weeklySPY = pxSPY.resample('1M', closed='right', label='right').last().ffill()
px = (weeklySPY[symbols('SPY')] - weeklyTLT[symbols('TLT')]).dropna()
fastMA = px.rolling(window = 20).mean().dropna()
slowMA = px.rolling(window = 50).mean().dropna()
osc = (fastMA - slowMA)/ slowMA
signal = np.mean(osc[-3:], axis=0)
lag = np.mean(osc[-6: -4], axis=0)
I have been getting nan values for the signal and lag variables and not sure where the error might be coming from.
Key difference between this snippet of code and the notebook is the use of np.mean() instead of df.rolling().mean() as there were issues with comparing values of the rolling mean.
Appreciate any help on this issue.