Dear Zipline Maintainers,
Before I tell you about my issue, let me describe my environment:
Python packages:
alembic==1.0.11
Now that you know a little about me, let me tell you about the issue I am
having:
from zipline.api import symbol, order, record
def initialize(context):
pass
def handle_data(context, data):
order(symbol('AAPL'), 10)
record(AAPL=data.current(symbol('AAPL'), 'price'))
zipline run --bundle quandl -f buyapple.py --start 2018-1-1 --end 2018-1-1 --output outapple.pickleWhat did you expect to happen?
I expected the backtest to run
What happened instead?
I got the following error:
$ zipline run --bundle quandl -f buyapple.py --start 2018-01-01 --end 2019-01-01 --output output_apple.pickle
[2019-06-27 01:53:19.343551] INFO: Loader: Cache at /Users/richardwuebker/.zipline/data/SPY_benchmark.csv does not have data from 2018-01-02 00:00:00+00:00 to 2018-12-31 00:00:00+00:00.
[2019-06-27 01:53:19.344034] INFO: Loader: Downloading benchmark data for 'SPY' from 2017-12-29 00:00:00+00:00 to 2018-12-31 00:00:00+00:00
Traceback (most recent call last):
File "/Users/richardwuebker/.pyenv/versions/3.5.4/bin/zipline", line 11, in <module>
load_entry_point('zipline==1.3.0', 'console_scripts', 'zipline')()
File "/Users/richardwuebker/.pyenv/versions/3.5.4/lib/python3.5/site-packages/click/core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "/Users/richardwuebker/.pyenv/versions/3.5.4/lib/python3.5/site-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/Users/richardwuebker/.pyenv/versions/3.5.4/lib/python3.5/site-packages/click/core.py", line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/richardwuebker/.pyenv/versions/3.5.4/lib/python3.5/site-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/richardwuebker/.pyenv/versions/3.5.4/lib/python3.5/site-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/Users/richardwuebker/.pyenv/versions/3.5.4/lib/python3.5/site-packages/zipline/__main__.py", line 107, in _
return f(*args, **kwargs)
File "/Users/richardwuebker/.pyenv/versions/3.5.4/lib/python3.5/site-packages/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/Users/richardwuebker/.pyenv/versions/3.5.4/lib/python3.5/site-packages/zipline/__main__.py", line 276, in run
blotter=blotter,
File "/Users/richardwuebker/.pyenv/versions/3.5.4/lib/python3.5/site-packages/zipline/utils/run_algo.py", line 159, in _run
trading_days=trading_calendar.schedule[start:end].index,
File "/Users/richardwuebker/.pyenv/versions/3.5.4/lib/python3.5/site-packages/zipline/finance/trading.py", line 103, in __init__
self.bm_symbol,
File "/Users/richardwuebker/.pyenv/versions/3.5.4/lib/python3.5/site-packages/zipline/data/loader.py", line 149, in load_market_data
environ,
File "/Users/richardwuebker/.pyenv/versions/3.5.4/lib/python3.5/site-packages/zipline/data/loader.py", line 216, in ensure_benchmark_data
data = get_benchmark_returns(symbol)
File "/Users/richardwuebker/.pyenv/versions/3.5.4/lib/python3.5/site-packages/zipline/data/benchmarks.py", line 35, in get_benchmark_returns
data = r.json()
File "/Users/richardwuebker/.pyenv/versions/3.5.4/lib/python3.5/site-packages/requests/models.py", line 897, in json
return complexjson.loads(self.text, **kwargs)
File "/Users/richardwuebker/.pyenv/versions/3.5.4/lib/python3.5/json/__init__.py", line 319, in loads
return _default_decoder.decode(s)
File "/Users/richardwuebker/.pyenv/versions/3.5.4/lib/python3.5/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/Users/richardwuebker/.pyenv/versions/3.5.4/lib/python3.5/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Here is how you can reproduce this issue on your machine:
I've upgraded my operating system, removed my python, brew installed python, brew installed pyenv, created a new envrionment in a directory with 3.5.4, replaced my quandl api key, ingested the quandl data again and retried. I also tried with a jupyter notebook with no luck
...
...
Sincerely,
Rick
It is because IEX deprecated the old API for downloading benchmark data.
You can try the several workarounds here #2480
I am having the same issue. @rwuebker have you found a working solution? Thanks
@arslanakhtar61 no I haven't. Please let me know if you think of something. Thanks!
So here is what I did, go to [(https://iexcloud.io/)], create a free account, get an API token, and modify the following file:
~/anaconda3/envs/env_zipline/lib/python3.5/site-packages/zipline/data/benchmarks.py
do:
import os
on top of the file
IEX_TOKEN=os.environ["IEX_PUBLIC_TOKEN"]
r = requests.get(
#'https://api.iextrading.com/1.0/stock/{}/chart/5y'.format(symbol),
'https://cloud.iexapis.com/stable/stock/{}/chart/5y?token={}'.format(symbol, IEX_TOKEN)
)
Also define IEX_PUBLIC_TOKEN as and environment variable in your bashrc and copy your token key there.
This can get you going for the time being.
getting same error too.
also meet it , have any answers ?
This stackoverflow answer works for me.
$ zipline run -f buyapple.py –-start 2000-1-1 –-end 2014-1-1 --output buyapple_out.pickle
The error was due to the follows related to Forbidden while running. It could be limited to access
[2019-11-28 01:01:25.502826] INFO: Loader: Downloading benchmark data for 'SPY' from 1999-12-31 00:00:00+00:00 to 2013-12-31 00:00:00+00:00
s: <class 'str'> Forbidden
Added print('s: ', type(s), s) to trace it.
$ cat /PATH-TO/lib/python3.6/json/decoder.py
def decode(self, s, _w=WHITESPACE.match):
"""Return the Python representation of ``s`` (a ``str`` instance
containing a JSON document).
"""
print('s: ', type(s), s)
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
end = _w(s, end).end()
if end != len(s):
raise JSONDecodeError("Extra data", s, end)
return obj
I'm having this problem as well. @jasonsears solution worked for me: https://github.com/jasonsears/zipline/commit/88ebb3426e547b80a40954068dcbbf1afd80cd24
Get same error anyone has a working solution?
On my repo (get benchmark returns) I have a method to do it manually, I also. provide the data from 1993 to 2020 of SPY daily data. It works, but its a bit limited in the sense that you cant use the api.
Hi all, I'm going to close this in favor of the consolidated issue for the benchmark downloading problems: https://github.com/quantopian/zipline/issues/2627.
https://github.com/quantopian/zipline/pull/2642 should help now, if you're using master, but it isn't released on PyPI yet.
Feel free to ping there or to reopen this if you think there's information in this issue that's not captured in the other one.
Most helpful comment
So here is what I did, go to [(https://iexcloud.io/)], create a free account, get an API token, and modify the following file:
~/anaconda3/envs/env_zipline/lib/python3.5/site-packages/zipline/data/benchmarks.py
do:
import oson top of the file
IEX_TOKEN=os.environ["IEX_PUBLIC_TOKEN"] r = requests.get( #'https://api.iextrading.com/1.0/stock/{}/chart/5y'.format(symbol), 'https://cloud.iexapis.com/stable/stock/{}/chart/5y?token={}'.format(symbol, IEX_TOKEN) )Also define IEX_PUBLIC_TOKEN as and environment variable in your bashrc and copy your token key there.
This can get you going for the time being.