Pyalgotrade ライブラリの list 関数を使用して、Python で確率的オシレーターを作成しようとしています。
私のコードは以下の通りです:
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
import numpy
import talib
class MyStrategy(strategy.BacktestingStrategy):
def __init__(self, feed, instrument):
strategy.BacktestingStrategy.__init__(self, feed)
self.__instrument = instrument
def onBars(self, bars):
barDs = self.getFeed().getDataSeries("002389.SZ")
self.__stoch = indicator.STOCH(barDs, 20, 3, 3)
bar = bars[self.__instrument]
self.info("%0.2f, %0.2f" % (bar.getClose(), self.__stoch[-1]))
# Downdload then Load the yahoo feed from the CSV file
yahoofinance.download_daily_bars('002389.SZ', 2013, '002389.csv')
feed = yahoofeed.Feed()
feed.addBarsFromCSV("002389.SZ", "002389.csv")
# Evaluate the strategy with the feed's bars.
myStrategy = MyStrategy(feed, "002389.SZ")
myStrategy.run()
そして、次のようなエラーが発生しました。
File "/Users/johnhenry/Desktop/simple_strategy.py", line 46, in onBars
self.info("%0.2f, %0.2f" % (bar.getClose(), self.__stoch[-1]))
TypeError: float argument required, not numpy.ndarray
確率論的:
pyalgotrade.talibext.indicator.STOCH(barDs、カウント、fastk_period=-2147483648、slowk_period=-2147483648、slowk_matype=0、slowd_period=-2147483648、slowd_matype=0)