Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zipline Jsondecoder error #2669

Closed
301resa opened this issue Mar 14, 2020 · 7 comments
Closed

Zipline Jsondecoder error #2669

301resa opened this issue Mar 14, 2020 · 7 comments

Comments

@301resa
Copy link

301resa commented Mar 14, 2020

Dear Zipline Maintainers,

Before I tell you about my issue, let me describe my environment:

Environment

  • Operating System: (Windows Version or $ uname --all)
  • Python Version: 3.5.6
  • Python Bitness: 64
  • How did you install Zipline: (pip, conda, or `other (please explain)
    Installed as a new environment with python3.5.6 in anaconda then run
    conda install -c quantopian zipline
  • Python packages: $ pip freeze or $ conda list

alembic == 0.7.7
asn1crypto == 0.24.0
bcolz == 0.12.1
blas == 1
bleach == 3.1.0
blosc == 1.16.3
bottleneck == 1.2.1
bzip2 == 1.0.8
ca-certificates == 2020.1.1
certifi == 2018.8.24
cffi == 1.11.5
chardet == 3.0.4
click == 7
colorama == 0.4.3
contextlib2 == 0.6.0.post1
cryptography == 2.3.1
cycler == 0.10.0
cyordereddict == 0.2.2
cython == 0.28.5
decorator == 4.4.2
defusedxml == 0.6.0
empyrical == 0.5.0
entrypoints == 0.2.3
future == 0.16.0
hdf5 == 1.10.2
icc_rt == 2019.0.0
idna == 2.7
intel-openmp == 2019.4
intervaltree == 2.1.0
ipykernel == 4.10.0
ipython == 5.8.0
ipython_genutils== 0.2.0
jinja2 == 2.11.1
json5 == 0.9.1
jsonschema == 2.6.0
jupyter_client == 5.3.3
jupyter_core == 4.5.0
kiwisolver == 1.1.0
libiconv == 1.15
libsodium == 1.0.16
libxml2 == 2.9.9
libxslt == 1.1.33
logbook == 0.12.5
lru-dict == 1.1.4
lxml == 4.2.5
lz4-c == 1.8.1.2
lzo == 2.1
m2w64-gcc-libgfortran == 5.3.0
m2w64-gcc-libs == 5.3.0
m2w64-gcc-libs-core == 5.3.0
m2w64-gmp == 6.1.0
m2w64-libwinpthread-git== 5.0.0.4634.69
mako == 1.1.2
markupsafe == 1
matplotlib == 3.0.3
mistune == 0.8.3
mkl == 2018.0.3
msys2-conda-epoch == 20160418
multipledispatch == 0.6.0
nbconvert == 5.5.0
nbformat == 5.0.4
networkx == 1.11
notebook == 5.6.0
numexpr == 2.6.1
numpy == 1.14.2
openssl == 1.0.2u
pandas == 0.22.0
pandas-datareader == 0.8.1
pandoc == 2.2.3.2
pandocfilters == 1.4.2
patsy == 0.5.0
pickleshare == 0.7.4
pip == 20.0.2
prometheus_client == 0.7.1
prompt_toolkit == 1.0.15
pycparser == 2.19
pygments == 2.5.2
pyjson == 1.3.0
pyopenssl == 18.0.0
pyparsing == 2.4.6
pypiwin32 == 223
pysocks == 1.6.8
pytables == 3.4.4
python == 3.5.6
python-dateutil == 2.8.1
python-jsonrpc-server == 0.3.4
pytz == 2019.3
pywin32 == 227
pywinpty == 0.5.4
pyzmq == 17.1.2
requests == 2.20.1
requests-file == 1.4.3
scipy == 1.1.0
send2trash == 1.5.0
setuptools == 40.2.0
simplegeneric == 0.8.1
six == 1.11.0
snappy == 1.1.7
sortedcontainers == 1.4.4
sqlalchemy == 1.2.11
statsmodels == 0.9.0
terminado == 0.8.1
testpath == 0.4.4
toolz == 0.10.0
tornado == 5.1.1
trading-calendars == 1.11.1
traitlets == 4.3.2
ujson == 1.35
urllib3 == 1.23
vc == 14.1
vs2015_runtime == 14.16.27012
wcwidth == 0.1.8
webencodings == 0.5.1
wheel == 0.31.1
win_inet_pton == 1.0.1
win_unicode_console == 0.5
wincertstore == 0.2
winpty == 0.4.3
xmltodict == 0.12.0
xz == 5.2.4
zeromq == 4.2.5
zipline == 1.3.0
zlib == 1.2.11
zstd == 1.3.7

Now that you know a little about me, let me tell you about the issue I am
having: *** Error : JSONDecodeError: Expecting value: line 1 column 1 (char 0)***
code from Trading Evolved book

Description of Issue

Error : JSONDecodeError: Expecting value: line 1 column 1 (char 0)

C:\Anaconda3\envs\zipenv\lib\json\decoder.py in raw_decode(self, s, idx)
355 obj, end = self.scan_once(s, idx)
356 except StopIteration as err:
--> 357 raise JSONDecodeError("Expecting value", s, err.value) from None
358 return obj, end

from zipline import run_algorithm
from zipline.api import order_target_percent, symbol
from datetime import datetime

import pytz
import matplotlib.pyplot as plt

def initialize(context):
    context.stock=symbol("AAPL")
    context.index_average_windows=100

def handle_data(context,data):
    equities_hist=data.history(context.stock,"close",context.index_average_windows,"id")
    
    if equities_hist[-1] > equities_hist.mean():
        stock_weight=1.0
    else:
        stock_weight = 0.0
    order_target_percent(context.stock, stock_weight)
def analyze(context, perf):
    fig= plt.figure(figsize=(12,8))
    ax=fig.add_subplot(311)
    ax.set_title("Strategy results")
    ax.semilogy(perf['portfolio_value'], linestyle='-',label='Equity Curve', linewidth=3.0)
    ax.legend()
    ax.grid=False
    ax = fig.add_subplot(312)
    ax.plt(perf["gross_leverage"],label="Exposure",linestyle="-",linewidth=1.0)
    ax.legend()
    ax.grid=False 
start_date=datetime(2010, 1, 1, tzinfo=pytz.UTC)
end_date=datetime(2020, 1, 1, tzinfo=pytz.UTC)
results= run_algorithm(start=start_date,end=end_date,initialize=initialize,analyze=analyze,handle_data=handle_data,capital_base=10000,data_frequency="daily")

I get this error:


JSONDecodeError Traceback (most recent call last)
in ()
----> 1 results= run_algorithm(start=start_date,end=end_date,initialize=initialize,analyze=analyze,handle_data=handle_data,capital_base=10000,data_frequency="daily")

C:\Anaconda3\envs\zipenv\lib\site-packages\zipline\utils\run_algo.py in run_algorithm(start, end, initialize, capital_base, handle_data, before_trading_start, analyze, data_frequency, data, bundle, bundle_timestamp, trading_calendar, metrics_set, default_extension, extensions, strict_extensions, environ, blotter)
428 local_namespace=False,
429 environ=environ,
--> 430 blotter=blotter,
431 )

C:\Anaconda3\envs\zipenv\lib\site-packages\zipline\utils\run_algo.py in _run(handle_data, initialize, before_trading_start, analyze, algofile, algotext, defines, data_frequency, capital_base, data, bundle, bundle_timestamp, start, end, output, trading_calendar, print_algo, metrics_set, local_namespace, environ, blotter)
157 trading_calendar=trading_calendar,
158 trading_day=trading_calendar.day,
--> 159 trading_days=trading_calendar.schedule[start:end].index,
160 )
161 first_trading_day =\

C:\Anaconda3\envs\zipenv\lib\site-packages\zipline\finance\trading.py in init(self, load, bm_symbol, exchange_tz, trading_calendar, trading_day, trading_days, asset_db_path, future_chain_predicates, environ)
101 trading_day,
102 trading_days,
--> 103 self.bm_symbol,
104 )
105

C:\Anaconda3\envs\zipenv\lib\site-packages\zipline\data\loader.py in load_market_data(trading_day, trading_days, bm_symbol, environ)
147 # date so that we can compute returns for the first date.
148 trading_day,
--> 149 environ,
150 )
151 tc = ensure_treasury_data(

C:\Anaconda3\envs\zipenv\lib\site-packages\zipline\data\loader.py in ensure_benchmark_data(symbol, first_date, last_date, now, trading_day, environ)
214
215 try:
--> 216 data = get_benchmark_returns(symbol)
217 data.to_csv(get_data_filepath(filename, environ))
218 except (OSError, IOError, HTTPError):

C:\Anaconda3\envs\zipenv\lib\site-packages\zipline\data\benchmarks.py in get_benchmark_returns(symbol)
33 'https://api.iextrading.com/1.0/stock/{}/chart/5y'.format(symbol)
34 )
---> 35 data = r.json()
36
37 df = pd.DataFrame(data)

C:\Anaconda3\envs\zipenv\lib\site-packages\requests\models.py in json(self, **kwargs)
895 # used.
896 pass
--> 897 return complexjson.loads(self.text, **kwargs)
898
899 @Property

C:\Anaconda3\envs\zipenv\lib\json_init_.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
317 parse_int is None and parse_float is None and
318 parse_constant is None and object_pairs_hook is None and not kw):
--> 319 return _default_decoder.decode(s)
320 if cls is None:
321 cls = JSONDecoder

C:\Anaconda3\envs\zipenv\lib\json\decoder.py in decode(self, s, _w)
337
338 """
--> 339 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
340 end = _w(s, end).end()
341 if end != len(s):

C:\Anaconda3\envs\zipenv\lib\json\decoder.py in raw_decode(self, s, idx)
355 obj, end = self.scan_once(s, idx)
356 except StopIteration as err:
--> 357 raise JSONDecodeError("Expecting value", s, err.value) from None
358 return obj, end

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

  • What did you expect to happen?
  • What happened instead?

Here is how you can reproduce this issue on your machine:

Reproduction Steps

  1. Code is provided in the issue

What steps have you taken to resolve this already?

I installed a number of json libs hoping it will take care of that error

...

Sincerely,
$ Reza

@301resa
Copy link
Author

301resa commented Mar 14, 2020

i tried on two machines and error exists

@lober-io
Copy link

I can confirm this, I have the same error in a similar setup.

Bests,
Fabian

@301resa
Copy link
Author

301resa commented Mar 19, 2020

so pitty zipline is such a powerful yet painful library.

@billmoling
Copy link

check this #2480 , it is related a SPY benchmark API download.

@301resa
Copy link
Author

301resa commented Apr 10, 2020

check this #2480 , it is related a SPY benchmark API download.

thank you for sharing the answer, I did the changed to the benchmark but no luck! didn't work!

@billmoling
Copy link

check this #2480 , it is related a SPY benchmark API download.

thank you for sharing the answer, I did the changed to the benchmark but no luck! didn't work!

what change you have made?

@richafrank
Copy link
Member

Hi all, I'm going to close this in favor of the consolidated issue for the benchmark downloading problems: #2627.

#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants