0
Python의 Python 라이브러리에서리스트 함수를 사용하여 파이썬에서 Ultimate Oscillator를 작성하려고합니다.NameError : 파이썬에서 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)
당신은indicator
을 수입하지 않을 않으며, 당신이에 정의되어 모듈을 통해 그것을 참조하는 변경
상단의 가져 오기에'pyalgotrade.talibext import indicator'를 추가하고 원래 버전을 다시 실행 해 볼 수 있습니까? (즉,'self .__ ultosc = indicator.ULTOSC (barDs, 36)') –
기존 질문에 계속 추가하기보다는 새로운 질문을하십시오. –
, Pyalgotrade를 사용할 때 Python에서 TypeError라는 새로운 질문을 추가했습니다. – qifengwu