from pyalgotrade import strategy
from pyalgotrade.feed import csvfeed
from pyalgotrade.technical import ma
from pyalgotrade.bar import Frequency
class MyStrategy(strategy.BacktestingStrategy):
def __init__(self, feed, instrument):
strategy.BacktestingStrategy.__init__(self, feed, 1000)
# We want a 15 period SMA over the closing prices.
self.__instrument = instrument
self.__sma = ma.SMA(feed[instrument].getDataSeries(instrument), 15)
def onBars(self, bars):
bar = bars[self.__instrument]
print "%s: %s %s" % (bar.getDateTime(), self.__sma[-1])
# Load the yahoo feed from the CSV file
feed = csvfeed.Feed("Date","%Y-%m-%d %H:%M")
feed.addValuesFromCSV("test.csv")
# Evaluate the strategy with the feed's bars.
rules = MyStrategy(feed, "Open")
rules.run()
次のエラーが表示されます。
Traceback (most recent call last):
File "algotrade.py", line 21, in <module>
rules = MyStrategy(feed, "Open")
File "algotrade.py", line 11, in __init__
self.__sma = ma.SMA(feed[instrument].getDataSeries(instrument), 15)
AttributeError: 'SequenceDataSeries' object has no attribute 'getDataSeries'
コードの問題を理解できず、pyalgotrade のチュートリアルは役に立ちません。