1

我正在使用 pyalgotrade 编写交易算法。我得到了上面的错误,似乎无法修复它。我正在尝试使用“SLOW STOCHASTIC”,非常感谢您对解决此错误和让慢速随机指标起作用的任何帮助:

错误:

C:\Users\...\Desktop>python bobo.py
Traceback (most recent call last):
  File "bobo.py", line 114, in <module>
    main()
  File "bobo.py", line 110, in main
    run_strategy(10,inst,2,14,5,2,3)
  File "bobo.py", line 102, in run_strategy
    myStrategy = MyStrategy(feed, inst, smaPeriod,emaPeriod,rsiPeriod,fastk_period,slowk_period,slowd_period)
  File "bobo.py", line 26, in __init__
    self.__stoch = indicator.STOCH(self.__prices,fastk_period,slowk_period,slowd_period)
  File "C:\Users\...\Anaconda2\lib\site-packages\pyalgotrade\talibext\indicator.py", line 803, in STOCH
    ret = call_talib_with_hlc(barDs, count, talib.STOCH, fastk_period, slowk_period, slowk_matype, slowd_period, slowd_matype)
  File "C:\Users\...\Anaconda2\lib\site-packages\pyalgotrade\talibext\indicator.py", line 93, in call_talib_with_hlc
    high = bar_ds_high_to_numpy(barDs, count)
  File "C:\Users\...\Anaconda2\lib\site-packages\pyalgotrade\talibext\indicator.py", line 45, in bar_ds_high_to_numpy
    return value_ds_to_numpy(barDs.getHighDataSeries(), count)
AttributeError: 'SequenceDataSeries' object has no attribute 'getHighDataSeries'

代码:

from pyalgotrade.tools import yahoofinance
from pyalgotrade import strategy
from pyalgotrade.barfeed import yahoofeed
from pyalgotrade.technical import stoch
from pyalgotrade import dataseries
from pyalgotrade.technical import ma
from pyalgotrade import technical
from pyalgotrade.technical import highlow
from pyalgotrade import bar
from pyalgotrade.talibext import indicator
from pyalgotrade.technical import rsi
import numpy
import talib


class MyStrategy(strategy.BacktestingStrategy):
    def __init__(self, feed,instrument,smaPeriod,emaPeriod,rsiPeriod,fastk_period,slowk_period,slowd_period):
        strategy.BacktestingStrategy.__init__(self, feed, 1000)      #change portfolio amount
        self.__position = None
        self.__instrument = instrument
        self.setUseAdjustedValues(True)
        self.__prices = feed[instrument].getPriceDataSeries()
        self.__sma = ma.SMA(self.__prices, smaPeriod)
        self.__ema = ma.EMA(self.__prices, emaPeriod)
        self.__rsi = rsi.RSI(self.__prices, rsiPeriod)
        self.__stoch = indicator.STOCH(self.__prices,fastk_period,slowk_period,slowd_period)

现在我收到错误:

Traceback (most recent call last):
  File "bobo.py", line 103, in <module>
    main()
  File "bobo.py", line 99, in main
    run_strategy(inst,10,250,14,5,5,5)
  File "bobo.py", line 90, in run_strategy
    myStrategy = MyStrategy(feed, inst, smaPeriod,emaPeriod,rsiPeriod,fastk_period,slowk_period,slowd_period)
  File "bobo.py", line 28, in __init__
    self.__stoch = indicator.STOCH(feed[instrument],fastk_period,slowk_period,slowd_period)
  File "C:\Users\JDOG\Anaconda2\lib\site-packages\pyalgotrade\talibext\indicator.py", line 803, in STOCH
    ret = call_talib_with_hlc(barDs, count, talib.STOCH, fastk_period, slowk_period, slowk_matype, slowd_period, slowd_matype)
  File "C:\Users\JDOG\Anaconda2\lib\site-packages\pyalgotrade\talibext\indicator.py", line 105, in call_talib_with_hlc
    return talibFunc(high, low, close, *args, **kwargs)
  File "talib/func.pyx", line 9388, in talib.func.STOCH (talib\func.c:87125)
Exception: inputs are all NaN
4

1 回答 1

0

尝试这个:

self.__stoch = indicator.STOCH(feed[instrument],fastk_period,slowk_period,slowd_period)

随机震荡指标期待一个柱状数据系列,而不是常规数据系列。

于 2016-07-04T19:04:10.747 回答