0

现在使用自定义因素遇到此问题,它一直在日志中说我有一个错误并且我的数组大小为 0(经过一点回溯测试,我知道这是错误所在)。如果您需要更多信息,请随时询问。

这段代码的目的是创建一个标准化的平均真实范围除以 0-1 比例的价格,我用来编码的源是 quantopian。

确切的错误是:

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

这是代码的不同版本:

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

这次我的错误是:

TypeError: zipline.pipeline.term.__getitem__() expected a value of
  type zipline.assets._assets.Asset for argument 'key', but got int instead.
4

0 回答 0