2014-03-31 62 views
1

我在Pyalgotrade中運行簡單的python書面交易策略時出現導入錯誤。使用PyAlgoTrade中的交易策略導入錯誤

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

而且錯誤顯示如下。

>>>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。

回答

0

你命名你自己程序pyalgotrade.py

File "/Users/johnhenry/Desktop/pyalgotrade.py" 

所以Python認爲這就是你指的是一個。將程序重命名爲其他內容,刪除您可能擁有的任何pyalgotrade.pycpyalgotrade.pyo文件,然後重新啓動解釋器。