在PyAlgoTrade中下载Yahoo Finance示例数据时出错
我正在尝试按照PyAlgoTrade网站上的介绍,使用给定的代码从雅虎财经下载数据。但是我总是遇到错误。
这是网站链接: http://gbeced.github.io/pyalgotrade/docs/v0.15/html/tutorial.html
... 说了这么多,测试我们的策略首先需要一些数据。我们来用2000年的甲骨文公司(Oracle)的股票价格,下面这个命令可以下载这些数据:
python -c "from pyalgotrade.tools import yahoofinance; yahoofinance.download_daily_bars('orcl', 2000, 'orcl-2000.csv')"
运行这个命令后,我得到了下面这样的错误
>>> python -c "from pyalgotrade.tools import yahoofinance; yahoofinance.download_daily_bars('orcl', 2000, 'orcl-2000.csv')"
SyntaxError: invalid syntax
1 个回答
1
>>> python -c "from pyalgotrade.tools import yahoofinance; yahoofinance.download_daily_bars('orcl', 2000, 'orcl-2000.csv')"
SyntaxError: invalid syntax
你应该在 命令行窗口 输入这个,而不是在 Python 里面。 在命令行中:
dsm@winter:~/coding$ python -c "from pyalgotrade.tools import yahoofinance; yahoofinance.download_daily_bars('orcl', 2000, 'orcl-2000.csv')"
dsm@winter:~/coding$ wc orcl-2000.csv
253 254 12694 orcl-2000.csv
python -c
这部分的意思是“启动 Python,并执行下面的字符串”。
另外,你也可以在 Python 里面 这样做:
>>> from pyalgotrade.tools import yahoofinance
>>> yahoofinance.download_daily_bars('orcl', 2000, 'orcl-2000.csv')