0
我試圖在Pyal中使用Pyalgotrade庫中的列表函數編寫Ultimate Oscillator。NameError:在Python中使用Pyalgotrade並未定義全局名稱'indicator'
我的代碼如下:
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,count,timeperiod1 = -2147483648,t imeperiod2 = -2147483648,timeperiod3 = -2147483648)
您可以嘗試在頂部導入並再次運行原始版本(也就是'self .__ ultosc = indicator.ULTOSC(barDs,36)'),從'pyalgotrade.talibext導入指示符'中添加' –
最好問一個新的問題,而不是繼續添加到現有的問題。 –
,當使用Pyalgotrade時,我在Python中添加了一個名爲TypeError的新問題。 – qifengwu