Pyalgotrade 라이브러리의 목록 기능을 사용하여 Python에서 Stochcastic Oscillator를 작성하려고합니다.
내 코드는 다음과 같습니다.
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, count, fastk_period = -2147483648, slowk_period = -2147483648, slowk_matype = 0, slowd_period = -2147483648, slowd_matype = 0)
하나 bar.getClose()
또는 self.__stoch[-1]
을 반환 numpy.ndarray
모두 반환해야한다 반면 float
들.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다