Hey guys, I'm trying to normalize ATR/Price on a 0-1 Scale on a given time frame but I seem to be having a little bit of an issue and keep getting 'NaN' in return. Anyone know why??
Code to focus on:
class ATrComp(CustomFactor):
inputs = [USEquityPricing.close,USEquityPricing.high,USEquityPricing.low]
window_length = 200
def compute(self, today, assets, out, close, high, low):
hml = high - low
hmpc = np.abs(high - np.roll(close, 1, axis=0))
lmpc = np.abs(low - np.roll(close, 1, axis=0))
tr = np.maximum(hml, np.maximum(hmpc, lmpc))
atr = np.mean(tr[1:21], axis=0) #skip the first one as it will be NaN
apr = atr*100 / close[-1]
aprcomp = (apr[1] - np.min(apr[2:101], axis=0))/(np.max(apr[2:101], axis=0) - np.min(apr[2:101], axis=0))
out[:] = aprcomp
And the backtest is attached.
Thank you!!!