having this issue right now with a custom factor, it keeps saying in the log that I have an error and that my array size is 0 (after backtesting a little, I know this is where that error lies). If you need more information, please feel free to ask.
The purpose of this code is to create a normalized Average True Range divided by Price on a 0-1 Scale, the source I'm using to code is quantopian.
The exact error is :
ValueError: zero-size array to reduction operation fmin which has no identity
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.amin(apr[-2:-101], axis=0))/(np.amax(apr[-2:-101], axis=0) - np.amin(apr[-2:-101], axis=0))
out[:] = aprcomp
Here's a different version of the code:
class ATrp(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[-21:], axis=0) #skip the first one as it will be NaN
apr = atr*100 / close[-1]
out[:] = apr
class ATrComp(CustomFactor):
inputs = [USEquityPricing.close,USEquityPricing.high,USEquityPricing.low]
window_length = 200
def compute(self, today, assets, out, close, high, low):
apr = ATrp()
aprcomp = (apr[-1] - np.amin(apr[-2:-101], axis=0))/(np.amax(apr[-2:-101], axis=0) - np.amin(apr[-2:-101], axis=0))
out[:] = aprcomp
This time my error is:
TypeError: zipline.pipeline.term.__getitem__() expected a value of
type zipline.assets._assets.Asset for argument 'key', but got int instead.