私はしばらくの間グーグルで検索してきましたが、まだ解決策を見つけることができず、正直なところ問題を特定することさえできません.
Python と Pyalgotrade のインストールは正しく、インポートの成功によって確認されました。
それにもかかわらず、チュートリアルでサンプル コードを実行することができず、常にスローされます。
AttributeError: MyStrategy instance has no attribute 'info'
コード例は次のとおりです。
from pyalgotrade import strategy
from pyalgotrade.barfeed import yahoofeed
class MyStrategy(strategy.BacktestingStrategy):
def __init__(self, feed, instrument):
strategy.BacktestingStrategy.__init__(self, feed)
self.__instrument = instrument
def onBars(self, bars):
bar = bars[self.__instrument]
self.info(bar.getClose())
# Load the yahoo feed from the CSV file
feed = yahoofeed.Feed()
feed.addBarsFromCSV("orcl", "orcl-2000.csv")
# Evaluate the strategy with the feed's bars.
myStrategy = MyStrategy(feed, "orcl")
myStrategy.run()
そして iPython Notebook の出力:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-1-f786d1b471f7> in <module>()
18 # Evaluate the strategy with the feed's bars.
19 myStrategy = MyStrategy(feed, "orcl")
---> 20 myStrategy.run()
/usr/local/lib/python2.7/site-packages/pyalgotrade/strategy/__init__.pyc in run(self)
398 self.onStart()
399
--> 400 self.__dispatcher.run()
401
402 if self.__feed.getCurrentBars() != None:
/usr/local/lib/python2.7/site-packages/pyalgotrade/observer.pyc in run(self)
139 subject.start()
140
--> 141 while not self.__stopped and self.__dispatch():
142 pass
143 finally:
/usr/local/lib/python2.7/site-packages/pyalgotrade/observer.pyc in __dispatch(self)
131 nextDateTime = subject.peekDateTime()
132 if nextDateTime == None or nextDateTime == smallestDateTime:
--> 133 subject.dispatch()
134 return ret
135
/usr/local/lib/python2.7/site-packages/pyalgotrade/feed/__init__.pyc in dispatch(self)
95 dateTime, values = self.getNextValuesAndUpdateDS()
96 if dateTime != None:
---> 97 self.__event.emit(dateTime, values)
98
99 def getKeys(self):
/usr/local/lib/python2.7/site-packages/pyalgotrade/observer.pyc in emit(self, *parameters)
51 self.__emitting = True
52 for handler in self.__handlers:
---> 53 handler(*parameters)
54 self.__emitting = False
55 self.__applyChanges()
/usr/local/lib/python2.7/site-packages/pyalgotrade/strategy/__init__.pyc in __onBars(self, dateTime, bars)
386
387 # 1: Let the strategy process current bars and place orders.
--> 388 self.onBars(bars)
389
390 # 2: Place the necessary orders for positions marked to exit on session close.
<ipython-input-1-f786d1b471f7> in onBars(self, bars)
10 def onBars(self, bars):
11 bar = bars[self.__instrument]
---> 12 self.info(bar.getClose())
13
14 # Load the yahoo feed from the CSV file
AttributeError: MyStrategy instance has no attribute 'info'
問題が何であるかについて、誰かが少なくともヒントを持っていますか?