错误与Pyalgotrade

时间:2016-07-26 11:35:07

标签: python pyalgotrade

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教程对我没用。

1 个答案:

答案 0 :(得分:0)

问题是您使用的是常规Feed类而不是BarFeed。试试这个:https://github.com/gbeced/pyalgotrade/blob/master/pyalgotrade/barfeed/csvfeed.py#L190