Нестандартный фактор, массив нулевого размера - PullRequest
0 голосов
/ 24 мая 2018

имея эту проблему прямо сейчас с пользовательским фактором, в журнале постоянно говорится, что у меня ошибка и что мой размер массива равен 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.
...