Back to Community
the label [label] is not in the [index]

Hello All,

I am trying to get started with Zipline. I am running it offline. I had some success trying some of the basic algorithms (such as mavg related) to run a backtest. However, whatever I do I cannot go back more than about a year ago. I tried with various data sources ("quantopian-quandl", "quandl", Yahoo, reading from CSV). The result is always the same and for some reason I cannot go back more than about one year ago.

I am also adding the actual code and output to pastebin as this forum messes up the formatting:
https://pastebin.com/jHUxM04q ###

$ python ZiplineDebug.py Traceback (most recent call last):
File "/home/username/anaconda3/envs/zipline/lib/python3.4/site-packages/pandas/core/indexing.py", line 1395, in has_valid_type
error()
File "/home/username/anaconda3/envs/zipline/lib/python3.4/site-packages/pandas/core/indexing.py", line 1390, in error
(key, self.obj.
get_axis_name(axis)))
KeyError: 'the label [2016-09-16 00:00:00+00:00] is not in the [index]'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "ZiplineDebug.py", line 29, in
environ=os.environ)
File "/home/username/anaconda3/envs/zipline/lib/python3.4/site-packages/zipline/utils/run_algo.py", line 360, in run_algorithm
environ=environ,
File "/home/username/anaconda3/envs/zipline/lib/python3.4/site-packages/zipline/utils/run_algo.py", line 179, in run
overwrite_sim_params=False,
File "/home/username/anaconda3/envs/zipline/lib/python3.4/site-packages/zipline/algorithm.py", line 709, in run
for perf in self.get_generator():
File "/home/username/anaconda3/envs/zipline/lib/python3.4/site-packages/zipline/gens/tradesimulation.py", line 230, in transform
handle_benchmark(normalize_date(dt))
File "/home/username/anaconda3/envs/zipline/lib/python3.4/site-packages/zipline/gens/tradesimulation.py", line 190, in handle_benchmark
benchmark_source.get_value(date)
File "/home/username/anaconda3/envs/zipline/lib/python3.4/site-packages/zipline/sources/benchmark_source.py", line 75, in get_value
return self._precalculated_series.loc[dt]
File "/home/username/anaconda3/envs/zipline/lib/python3.4/site-packages/pandas/core/indexing.py", line 1296, in _
getitem__
return self.getitem_axis(key, axis=0)
File "/home/username/anaconda3/envs/zipline/lib/python3.4/site-packages/pandas/core/indexing.py", line 1466, in getitem_axis
self._has_valid_type(key, axis)
File "/home/username/anaconda3/envs/zipline/lib/python3.4/site-packages/pandas/core/indexing.py", line 1403, in _has
valid
type
error()
File "/home/username/anaconda3/envs/zipline/lib/python3.4/site-packages/pandas/core/indexing.py", line 1390, in error
(key, self.obj._get_axis_name(axis)))
KeyError: 'the label [2016-09-16 00:00:00+00:00] is not in the [index]'
(zipline) [email protected]:~/projects/zipline$

(zipline) [email protected]:~/projects/zipline$ cat ZiplineDebug.py from zipline.api import symbol
from zipline import run_algorithm

import pandas as pd
import os
from datetime import datetime
import pytz

def initialize(context):

context.asset = symbol('AAPL')

pass

def handle_data(context, data):
pass

tz = pytz.timezone("US/Mountain")
start = datetime(2016, 9, 16, tzinfo=tz)
end = datetime(2017, 9, 2, tzinfo=tz)

perfData = run_algorithm(start=start,
end=end,
bundle="quantopian-quandl",
initialize=initialize,
capital_base=40000.00,
handle_data=handle_data,
environ=os.environ)

(zipline) [email protected]:~/projects/zipline$

However if I modify the data to the 17th of September 2017 I get:
(zipline) [email protected]:~/projects/zipline$ grep start ZiplineDebug.py start = datetime(2016, 9, 17, tzinfo=tz)
perfData = run_algorithm(start=start,
(zipline) [email protected]:~/projects/zipline$ python ZiplineDebug.py (zipline) [email protected]:~/projects/zipline$

I am not expecting any output as I changed all the functions to just "pass", while trying to debug this. So basically one day difference makes the script give an error or run successfully. This is also one year ago from today, so that likely has significance.

Please also note I am not even passing in any "symbol" anywhere. I had specific symbols before, but found the error is the same whether I have a symbol /asset or not.

What is going on with this? Anybody?

Thanks!

J

(zipline) [email protected]:~$ conda list |egrep "python|zipline|pandas"

packages in environment at /home/username/anaconda3/envs/zipline:

pandas 0.18.1 np111py34_0
pandas-datareader 0.2.1 py34_0
python 3.4.5 0
python-dateutil 2.6.1 py34_0
zipline 1.1.1 np111py34_0 Quantopian
(zipline) [email protected]:~$

3 responses

Have the same issue although no dates seems to work for me.

Try posting here https://github.com/quantopian/zipline/issues/1776 hopefully the devs. can assist.

Thanks Rohan, I am glad to have had at least the one response! I am not sure our problems are quite the same, if no dates work for you.

I will try posting to github.