Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
KeyError when running pyfolio bayesian tear sheet with my own returns dataframe

Hello
my df looks like this:
In [32]: returns.head()
Out[32]:
mthly
2011-04-29 0.054898
2011-05-31 -0.026618
2011-06-30 -0.012393
2011-07-29 -0.006620
2011-08-31 0.105223

In [33]: returns.info()

DatetimeIndex: 77 entries, 2011-04-29 to 2017-12-29
Data columns (total 1 columns):
mthly 77 non-null float64
dtypes: float64(1)
memory usage: 1.2 KB

full traceback:

In[34]: out_of_sample = returns.index[-10]

In [22]: %time pf.create_bayesian_tear_sheet(returns.mthly, live_start_date=out_
...: of_sample)
Running T model
100%|██████████████████████████████████████| 2500/2500 [00:10<00:00, 231.26it/s]
100%|█████████████████████████████████████| 2000/2000 [00:01<00:00, 1487.30it/s]

Finished T model (required 20.45 seconds).

Running BEST model
100%|██████████████████████████████████████| 2500/2500 [00:14<00:00, 173.76it/s]

Finished BEST model (required 22.42 seconds).

Finished plotting Bayesian cone (required 0.26 seconds).

Finished plotting BEST results (required 1.44 seconds).

Finished computing Bayesian predictions (required 0.20 seconds).

Finished plotting Bayesian VaRs estimate (required 0.08 seconds).

Running alpha beta model

KeyError Traceback (most recent call last)
in ()

/usr/local/lib/python3.6/site-packages/pyfolio/plotting.py in call_w_context(*args, **kwargs) 50 if set_context:
51 with plotting_context(), axes_style():
---> 52 return func(*args, **kwargs)
53 else:
54 return func(*args, **kwargs)

/usr/local/lib/python3.6/site-packages/pyfolio/tears.py in create_bayesian_tear_sheet(returns, benchmark_rets, live_start_date, samples, return_fig, stoch_vol) 1180 # Run alpha beta model
1181 print("\nRunning alpha beta model")
-> 1182 benchmark_rets = benchmark_rets.loc[df_train.index]
1183 trace_alpha_beta = bayesian.run_model('alpha_beta', df_train,
1184 bmark=benchmark_rets,

/usr/local/lib/python3.6/site-packages/pandas/core/indexing.py in getitem(self, key) 1371
1372 maybe_callable = com._apply_if_callable(key, self.obj)
-> 1373 return self._getitem_axis(maybe_callable, axis=axis)
1374
1375 def _is_scalar_access(self, key):

/usr/local/lib/python3.6/site-packages/pandas/core/indexing.py in _getitem_axis(self, key, axis) 1614 raise ValueError('Cannot index with multidimensional key')
1615
-> 1616 return self._getitem_iterable(key, axis=axis)
1617
1618 # nested tuple slicing

/usr/local/lib/python3.6/site-packages/pandas/core/indexing.py in _getitem_iterable(self, key, axis) 1113
1114 if self._should_validate_iterable(axis):
-> 1115 self._has_valid_type(key, axis)
1116
1117 labels = self.obj._get_axis(axis)

/usr/local/lib/python3.6/site-packages/pandas/core/indexing.py in _has_valid_type(self, key, axis) 1470 raise KeyError(
1471 u"None of [{key}] are in the [{axis}]".format(
-> 1472 key=key, axis=self.obj._get_axis_name(axis)))
1473 else:
1474

KeyError: "None of [DatetimeIndex(['2011-04-29', '2011-05-31', '2011-06-30', '2011-07-29',\n '2011-08-31', '2011-09-30', '2011-10-31', '2011-12-30',\n '2012-01-31', '2012-02-29', '2012-03-30', '2012-04-30',\n '2012-05-31', '2012-06-29', '2012-07-31', '2012-08-31',\n '2012-10-31', '2012-11-30', '2012-12-31', '2013-01-31',\n '2013-02-28', '2013-03-29', '2013-04-30', '2013-05-31',\n '2013-06-28', '2013-07-31', '2013-08-30', '2013-10-31',\n '2013-11-29', '2013-12-31', '2014-01-31', '2014-02-28',\n '2014-03-31', '2014-04-30', '2014-05-30', '2014-06-30',\n '2014-07-31', '2014-08-29', '2014-09-30', '2014-10-31',\n '2014-11-28', '2014-12-31', '2015-01-30', '2015-02-27',\n '2015-03-31', '2015-04-30', '2015-05-29', '2015-06-30',\n '2015-07-31', '2015-08-31', '2015-09-30', '2015-10-30',\n '2015-11-30', '2016-01-29', '2016-02-29', '2016-03-31',\n '2016-04-29', '2016-05-31', '2016-06-30', '2016-07-29',\n '2016-08-31', '2016-09-30', '2016-10-31', '2016-11-30',\n '2016-12-30', '2017-01-31', '2017-02-28'],\n dtype='datetime64[ns]', freq=None)] are in the [index]"

Can you please tell me what i am doing wrong? Thanks for your help.