首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ImportError使用PyAlgoTrade教程中的交易策略

ImportError使用PyAlgoTrade教程中的交易策略
EN

Stack Overflow用户
提问于 2014-03-31 15:45:33
回答 1查看 1.7K关注 0票数 1

当我在Pyalgotrade中运行一个简单的python书面交易策略时,我遇到了一个导入错误。

代码语言:javascript
复制
from pyalgotrade.tools import yahoofinance
yahoofinance.download_daily_bars('orcl', 2000, 'orcl-2000.csv')

from pyalgotrade import strategy
from pyalgotrade.barfeed import yahoofeed
from pyalgotrade.technical import ma


class MyStrategy(strategy.BacktestingStrategy):
    def __init__(self, feed, instrument):
        strategy.BacktestingStrategy.__init__(self, feed)
        # We want a 15 period SMA over the closing prices.
        self.__sma = ma.SMA(feed[instrument].getCloseDataSeries(), 15)
        self.__instrument = instrument

    def onBars(self, bars):
        bar = bars[self.__instrument]
        self.info("%s %s" % (bar.getClose(), self.__sma[-1]))

# 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()

错误如下所示。

代码语言:javascript
复制
>>>Traceback (most recent call last):
   File "/Users/johnhenry/Desktop/pyalgotrade2.py", line 1, in <module>
    from pyalgotrade import strategy
   File "/Users/johnhenry/Desktop/pyalgotrade.py", line 1, in <module>
    from pyalgotrade import strategy
   ImportError: cannot import name strategy

我确信我有一个名为pyalgotrade的图书馆。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-31 15:58:42

你把你自己的程序命名为pyalgotrade.py

代码语言:javascript
复制
File "/Users/johnhenry/Desktop/pyalgotrade.py"

所以Python认为这就是你的意思。将程序重命名为其他文件,删除可能拥有的任何pyalgotrade.pycpyalgotrade.pyo文件,并重新启动解释器。

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

https://stackoverflow.com/questions/22766101

复制
相关文章

相似问题

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