Hi Andrew,
Thanks for taking a look at this. I am getting the same error after adding your code. Here is the code,
import matplotlib.pyplot as pyplot
import pyfolio as pf
: My Returns data
returns_data = local_csv('Returns-2015.csv',date_column='Date',use_date_column_as_index=True, timezone='UTC')
len(returns_data)
returns_data.ix[:,'Daily Return']
returnSeries = returns_data.ix[:,'Daily Return']
type(returnSeries)
returnSeries.index = returnSeries.index.normalize()
pf.tears.create_returns_tear_sheet(returnSeries)
Here is the full traceback,
KeyError Traceback (most recent call last)
in ()
11 #type(returnSeries)
12 returnSeries.index = returnSeries.index.normalize()
---> 13 pf.tears.create_returns_tear_sheet(returnSeries)
/usr/local/lib/python2.7/dist-packages/pyfolio/plotting.pyc in call_w_context(args, **kwargs)
44 if set_context:
45 with context():
---> 46 return func(args, **kwargs)
47 else:
48 return func(*args, **kwargs)
/usr/local/lib/python2.7/dist-packages/pyfolio/tears.pyc in create_returns_tear_sheet(returns, live_start_date, cone_std, benchmark_rets, return_fig)
290
291 plotting.plot_rolling_beta(
--> 292 returns, benchmark_rets, ax=ax_rolling_beta)
293
294 plotting.plot_rolling_sharpe(
/usr/local/lib/python2.7/dist-packages/pyfolio/plotting.pyc in plot_rolling_beta(returns, factor_returns, legend_loc, ax, **kwargs)
680 ax.set_ylabel('Beta')
681 rb_1 = timeseries.rolling_beta(
--> 682 returns, factor_returns, rolling_window=APPROX_BDAYS_PER_MONTH * 6)
683 rb_1.plot(color='steelblue', lw=3, alpha=0.6, ax=ax, **kwargs)
684 rb_2 = timeseries.rolling_beta(
/usr/local/lib/python2.7/dist-packages/pyfolio/timeseries.pyc in rolling_beta(returns, factor_returns, rolling_window)
648 out.loc[end] = calc_alpha_beta(
649 returns.loc[beg:end],
--> 650 factor_returns.loc[beg:end])[1]
651
652 return out
/usr/local/lib/python2.7/dist-packages/pyfolio/timeseries.pyc in calc_alpha_beta(returns, factor_returns)
710
711 ret_index = returns.index
--> 712 beta, alpha = sp.stats.linregress(factor_returns.loc[ret_index].values,
713 returns.values)[:2]
714
/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-01', '2015-07-01', '2015-08-01', '2015-09-01',\n '2015-12-01', '2015-01-13', '2015-01-14', '2015-01-15',\n '2015-01-16', '2015-01-19', \n ...\n '2015-06-18', '2015-06-19', '2015-06-22', '2015-06-23',\n '2015-06-24', '2015-06-25', '2015-06-26', '2015-06-29',\n '2015-06-30', '2015-01-07'],\n dtype='datetime64[ns]', name=u'Date', length=127, freq=None, tz='UTC')] are in the [index]"