Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Research Key Error when Analyzing Algo with Backtest ID

I ran a backtest in the algorithm section of the website, and later attempted to analyze the algorithim in a cloned portfolio tearsheet notebook in Research (did not change the tearsheet code), and get the below errors :

--------------------------------------------------------------------------  
KeyError                                  Traceback (most recent call last)  
<ipython-input-37-7264850edbb9> in <module>()  
----> 1 analyze_single_algo( df_rets=algo_rets, algo_live_date='2007-06-01', cone_std=1.0 )

<ipython-input-35-649129654a06> in analyze_single_algo(df_rets, algo_live_date, cone_std)  
     91     plt.title("Rolling Portfolio Beta to SP500",fontsize=16)  
     92     plt.ylabel('beta', fontsize=14)  
---> 93     rb_1 = rolling_beta(df_rets, benchmark_rets, rolling_window=rolling_beta_window*2)  
     94     rb_1.plot(color='steelblue', lw=3, alpha=0.6, ax=ax)  
     95     rb_2 = rolling_beta(df_rets, benchmark_rets, rolling_window=rolling_beta_window*3)

<ipython-input-31-400c1759a9ed> in rolling_beta(ser, benchmark_rets, rolling_window)  
    251 def rolling_beta(ser, benchmark_rets, rolling_window=63):  
    252     results = [ calc_alpha_beta( ser[beg:end], benchmark_rets, return_beta_only=True, normalize=True)  
--> 253                for beg,end in zip(ser.index[0:-rolling_window],ser.index[rolling_window:]) ]  
    254  
    255     return pd.Series(index=ser.index[rolling_window:], data=results)

<ipython-input-31-400c1759a9ed> in calc_alpha_beta(df_rets, benchmark_rets, startDate, endDate, return_beta_only, inputs_are_returns, normalize, remove_zeros)  
    225             ret_index = df_rets.index  
    226  
--> 227         beta, alpha = sp.stats.linregress(benchmark_rets.loc[ret_index].values,  
    228                                           df_rets.values)[:2]  
    229 

/usr/local/lib/python2.7/dist-packages/pandas/core/indexing.pyc in __getitem__(self, key)
   1178             return self._getitem_tuple(key)  
   1179         else:  
-> 1180             return self._getitem_axis(key, axis=0)  
   1181  
   1182     def _getitem_axis(self, key, axis=0):

/usr/local/lib/python2.7/dist-packages/pandas/core/indexing.pyc in _getitem_axis(self, key, axis)
   1312                     raise ValueError('Cannot index with multidimensional key')  
   1313  
-> 1314                 return self._getitem_iterable(key, axis=axis)  
   1315  
   1316             # nested tuple slicing

/usr/local/lib/python2.7/dist-packages/pandas/core/indexing.pyc in _getitem_iterable(self, key, axis)
    922     def _getitem_iterable(self, key, axis=0):  
    923         if self._should_validate_iterable(axis):  
--> 924             self._has_valid_type(key, axis)  
    925  
    926         labels = self.obj._get_axis(axis)

/usr/local/lib/python2.7/dist-packages/pandas/core/indexing.pyc in _has_valid_type(self, key, axis)
   1260  
   1261                 raise KeyError("None of [%s] are in the [%s]" %  
-> 1262                                (key, self.obj._get_axis_name(axis)))  
   1263  
   1264             return True

KeyError: "None of [DatetimeIndex(['2015-06-12', '2015-06-15', '2015-06-16', '2015-06-17',\n               '2015-06-18', '2015-06-19', '2015-06-22', '2015-06-23',\n               '2015-06-24', '2015-06-25', \n               ...\n               '2015-11-27', '2015-11-30', '2015-12-01', '2015-12-02',\n               '2015-12-03', '2015-12-04', '2015-12-07', '2015-12-08',\n               '2015-12-09', '2015-12-10'],\n              dtype='datetime64[ns]', length=127, freq=None, tz='UTC')] are in the [index]"  

Could someone provide guidance on how to debug?

Thanks!
Adam