Pyalgotrad错误

2024-09-27 18:00:24 发布

您现在位置:Python中文网/ 问答频道 /正文

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()

我得到以下错误:

^{pr2}$

我无法解决我的代码问题,pyalgotrade的教程对我没有帮助。在


Tags: thefromimportselfdeffeedbarpyalgotrade

热门问题