首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NameError:在Pyalgotrade中未使用Pyalgotrade定义全局名称“指示器”

NameError:在Pyalgotrade中未使用Pyalgotrade定义全局名称“指示器”
EN

Stack Overflow用户
提问于 2014-04-10 06:15:19
回答 1查看 828关注 0票数 0

我试图使用Pyalgotrade库中的list函数在python中编写一个终极振荡器。

我的代码如下:

代码语言:javascript
复制
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()

我犯了这样的错误:

代码语言:javascript
复制
  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)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-10 06:19:55

您没有导入indicator,也没有通过它定义的模块引用它。改变这一点:

代码语言:javascript
复制
self.__ultosc = indicator.ULTOSC(barDs, 36)

转入:

代码语言:javascript
复制
self.__ultosc = talibext.indicator.ULTOSC(barDs, 36)

应该没问题的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22979974

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档