我试图使用Pyalgotrade库中的list函数在python中编写一个终极振荡器。
我的代码如下:
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 import talibext
import numpy
import talib
class MyStrategy(strategy.BacktestingStrategy):
def __init__(self, feed, instrument):
strategy.BacktestingStrategy.__init__(self, feed)
self.__instrument = instrument
barDs = self.getFeed().getDataSeries("002389.SZ")
self.__ultosc = indicator.ULTOSC(barDs, 36)
bar = bars[self.__instrument]
self.info("%0.2f, %0.2f" % (bar.getClose(), self.__ultosc[-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/untitled.py", line 23, in onBars
self.__ultosc = indicator.ULTOSC(barDs, 36)
NameError: global name 'indicator' is not defined这个函数可以在http://gbeced.github.io/pyalgotrade/docs/v0.15/html/talib.html上找到
终极振荡器:
pyalgotrade.talibext.indicator.ULTOSC(barDs,计数,时间周期1=-2147483648,时间周期2=-2147483648,时间周期3=-2147483648)
发布于 2014-04-10 06:19:55
您没有导入indicator,也没有通过它定义的模块引用它。改变这一点:
self.__ultosc = indicator.ULTOSC(barDs, 36)转入:
self.__ultosc = talibext.indicator.ULTOSC(barDs, 36)应该没问题的。
https://stackoverflow.com/questions/22979974
复制相似问题