Question

I am trying to follow the introduction in PyAlgoTrade website to download the data from yahoo finance using the given code. But I always got an error.

Here is the website: http://gbeced.github.io/pyalgotrade/docs/v0.15/html/tutorial.html

... Having said all that, the first thing that we’ll need to test our strategies is some data. Let’s use Oracle’s stock prices for year 2000, which we’ll download with the following command:

python -c "from pyalgotrade.tools import yahoofinance; yahoofinance.download_daily_bars('orcl', 2000, 'orcl-2000.csv')"

After running this command, I got the error like below

>>> python -c "from pyalgotrade.tools import yahoofinance; yahoofinance.download_daily_bars('orcl', 2000, 'orcl-2000.csv')"
SyntaxError: invalid syntax
Was it helpful?

Solution

>>> python -c "from pyalgotrade.tools import yahoofinance; yahoofinance.download_daily_bars('orcl', 2000, 'orcl-2000.csv')"
SyntaxError: invalid syntax

You should be entering this at the shell console, not from within Python. At the shell:

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

The python -c part means "start up Python, and feed it the following string to execute".

Alternatively, you could do it within Python:

>>> from pyalgotrade.tools import yahoofinance
>>> yahoofinance.download_daily_bars('orcl', 2000, 'orcl-2000.csv')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top