I installed Zipline and Jupyter using Docker: https://github.com/quantopian/zipline/blob/master/Dockerfile
I am now trying to run the following Zipline code under Jupyter
%%zipline --bundle quantopian-quantl --start 2008-1-1 --end 2012-1-1 -o strat.pickle
from zipline.api import symbol, order, record
def initialize(context):
pass
def handle_data(context, data):
order(symbol('AAPL'), 10)
record(AAPL=data[symbol('AAPL')].price)
The error message I am getting is:
**JSONDecodeError: Expecting value: line 1 column 1 (char 0)**
Here is the picture of the error:
Again, this takes place when I try to run the program.
What could the problem be? Any help, hints or advice is ~greatly~ appreciated!
TIA
Addendum: I have also tried this as well: https://docs.google.com/document/d/1mvZO_JDirbJNXJfM0bTS9uMipHE5cfSGFj0sUpJIcsw/edit?usp=sharing
I know this question is sort of solved, but I tried what they are offering on the github issues and it did not help me, so I desided to show how I fixed my problem. Maybe it will help you.
The problem is in the benchmark.py file (and several others) of zipline where it tries to get data from iex and fails because their function changed.
I will show you what I did in order to get the sample code running:
(I assume you already have zipline installed and runnig ther apple buying sample code)
1.benchmark.py: look into your zipline folder in your computer (what you have downloaded or pip/conda installed). Open benchmark.py (find it first) and edit it, change the whole code there to this:
this code was taken from the answer of shlomikushchi github page about the issue. Here shlomikushchi switched the data source from iex to pandas, yahoo.
2.Next, open the file: loaders.py , also somewhere in zipline:
there is a row there in which they call the function: (look for this in the code)
data = get_benchmark_returns(symbol
change it to :
3.open trading.py , also somewhere in the zipline folder, after this line:
enter those lines:
now it should work when you run the code in here:
https://www.zipline.io/beginner-tutorial.html
step 3 should be:
Another solution -- mentioned on the Github issue -- is to sign-up for a free API token from IEX, and insert it into your zipline module's
benchmark.py
file. Change the request.get line to this:r= requests.get( "https://cloud.iexapis.com/stable/stock/{}/chart/5y?chartCloseOnly=True&token={}".format(symbol, IEX_API_KEY) )
Needs to be a string, so surround your key with " " quotation marks