I've been trying to use the new pyfolio analysis capability with a zipline-run backtest within a research notebook, but I can't figure out how to pass the zipline results to pyfolio.
I'm running my algo in zipline the way it's shown in the zipline tutorial:
algo_obj = TradingAlgorithm(
initialize=initialize,
handle_data=handle_data
)
algo_obj._analyze = analyze
perf_manual = algo_obj.run(data.transpose(2,1,0))
... then I'm attempting to pass the result data to pyfolio:
import pyfolio as pf
import pytz
pf.create_full_tear_sheet(perf_manual.returns.tz_localize(pytz.utc))
which results in this error:
KeyError Traceback (most recent call last)
<ipython-input-87-723363adf35d> in <module>()
1 import pyfolio as pf
2 import pytz
----> 3 pf.create_full_tear_sheet(perf_manual.returns.tz_localize(pytz.utc))
[...] (let me know if you need the intermediate trace)
/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(['2010-01-04 21:00:00+00:00', '2010-01-05 21:00:00+00:00',\n '2010-01-06 21:00:00+00:00', '2010-01-07 21:00:00+00:00',\n '2010-01-08 21:00:00+00:00', '2010-01-11 21:00:00+00:00',\n '2010-01-12 21:00:00+00:00', '2010-01-13 21:00:00+00:00',\n '2010-01-14 21:00:00+00:00', '2010-01-15 21:00:00+00:00', \n ...\n '2013-12-17 21:00:00+00:00', '2013-12-18 21:00:00+00:00',\n '2013-12-19 21:00:00+00:00', '2013-12-20 21:00:00+00:00',\n '2013-12-23 21:00:00+00:00', '2013-12-24 18:00:00+00:00',\n '2013-12-26 21:00:00+00:00', '2013-12-27 21:00:00+00:00',\n '2013-12-30 21:00:00+00:00', '2013-12-31 21:00:00+00:00'],\n dtype='datetime64[ns]', length=1006, freq=None, tz='UTC')] are in the [index]"
If I try the same thing without ".tz_localize(pytz.utc)" on the returns data I get the dreaded:
TypeError: Cannot compare tz-naive and tz-aware timestamps
I also tried switching to "minute" frequency but that didn't make any difference. Am I passing the results incorrectly? Any pointers?