Я получаю эту ошибку, когда запускаю следующий код:
from zipline import run_algorithm
from zipline.api import symbol, order_target_percent
import pyfolio as pf
import pytz
import pandas as pd
from datetime import datetime
def initialize(context):
context.stock = symbol('AAPL')
context.index_average_window = 200
def handle_data(context, data):
equities_hist = data.history(context.stock, "close", context.index_average_window, "1d")
if equities_hist[-1] > equities_hist.mean():
order_target_percent(context.stock, 1)
else:
order_target_percent(context.stock, 0)
def analyze(context, perf):
returns, positions, transactions = pf.utils.extract_rets_pos_txn_from_zipline(perf)
pf.create_simple_tear_sheet(returns, bechmark_rets=none)
start_date = datetime(2011,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=100000,
data_frequency='daily',
bundle='quandl'
)
JSONDecodeError Traceback (most recent call last)
<ipython-input-7-8d5e302eff01> in <module>()
10 capital_base=100000,
11 data_frequency='daily',
---> 12 bundle='quandl'
13 )
E:\Anaconda\envs\z35\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 )
E:\Anaconda\envs\z35\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 =\
E:\Anaconda\envs\z35\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
E:\Anaconda\envs\z35\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(
E:\Anaconda\envs\z35\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):
E:\Anaconda\envs\z35\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)
E:\Anaconda\envs\z35\lib\site-packages\requests\models.py in json(self, **kwargs)
895 # used.
896 pass
--> 897 return complexjson.loads(self.text, **kwargs)
898
899 @property
E:\Anaconda\envs\z35\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
E:\Anaconda\envs\z35\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):
E:\Anaconda\envs\z35\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)