Hello,
I have written a strategy to backtest in zipline, and every time I ran the backtest, and error is showed with the line:
IndexError: index 0 is out of bounds for axis 0 with size 0
I have load custom data for BTCUSD in the following way:
data = OrderedDict()
ticker = "BTCUSD"
data["BTC_USD"] = pd.read_csv("C:/Users/Nicolas/Documents/{}.csv".format(ticker), index_col = 0, parse_dates = True )
data["BTC_USD"] = data["BTC_USD"].resample("D").mean()
data["BTC_USD"] = data["BTC_USD"].fillna(method='ffill')
data["BTC_USD"] = data["BTC_USD"][["open","high","low","close","volume"]]
panel = pd.Panel(data)
panel.minor_axis = ["open","high","low","close","Volume"]
panel.major_axis = panel.major_axis.tz_localize(pytz.utc)
After a bit of research(and ask in github too), I suspect that there is an issue with the SPY data that Zipline collect to calculate the sharpe ratio of the strategy(returns of the Benchmarking are calculated).
The source of the error is the followin:
IndexError Traceback (most recent call last) in () 72 capital_base = 100000, 73 handle_data = handle_data, ---> 74 data = panel)
c:\users\nicolas\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) 396 metrics_set=metrics_set, 397 local_namespace=False, --> 398 environ=environ, 399 )
c:\users\nicolas\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) 173 ) 174 else: --> 175 env = TradingEnvironment(environ=environ) 176 choose_loader = None 177
c:\users\nicolas\lib\site-packages\zipline\finance\trading.py in init(self, load, bm_symbol, exchange_tz, trading_calendar, asset_db_path, future_chain_predicates, environ) 97 trading_calendar.day, 98 trading_calendar.schedule.index, ---> 99 self.bm_symbol, 100 ) 101
c:\users\nicolas\lib\site-packages\zipline\data\loader.py in load_market_data(trading_day, trading_days, bm_symbol, environ) 154 last_date, 155 now, --> 156 environ, 157 ) 158
c:\users\nicolas\lib\site-packages\zipline\data\loader.py in ensure_treasury_data(symbol, first_date, last_date, now, environ) 262 first_date = max(first_date, loader_module.earliest_possible_date()) 263 --> 264 data = _load_cached_data(filename, first_date, last_date, now, 'treasury',environ) 265 if data is not None: 266 return data
c:\users\nicolas\lib\site-packages\zipline\data\loader.py in _load_cached_data(filename, first_date, last_date, now, resource_name, environ) 308 data = from_csv(path) 309 data.index = data.index.to_datetime().tz_localize('UTC') --> 310 if has_data_for_dates(data, first_date, last_date): 311 return data 312
c:\users\nicolas\lib\site-packages\zipline\data\loader.py in has_data_for_dates(series_or_df, first_date, last_date) 84 if not isinstance(dts, pd.DatetimeIndex): 85 raise TypeError("Expected a DatetimeIndex, but got %s." % type(dts)) ---> 86 first, last = dts[[0, -1]] 87 return (first <= first_date) and (last >= last_date) 88
c:\users\nicolas\lib\site-packages\pandas\tseries\base.py in getitem(self, key) 173 attribs['freq'] = freq 174 --> 175 result = getitem(key) 176 if result.ndim > 1: 177 return result
IndexError: index 0 is out of bounds for axis 0 with size 0
I don't know specifically what the problem is. I look at the source code of zipline data , and loader but don't find any clue to solve the issue.
Thanks in advance for your help. Nicolás