pyfolio
pyfolio copied to clipboard
IndexError: single positional indexer is out-of-bounds
Problem Description
Trying out Pyfolio to visualize my backtests and draw them from the output pickle files.
The algorythm I run works if I use purely matplotlib to visualize, but with Pyfolio (tracedback through Pandas) I receive the following error:
IndexError: single positional indexer is out-of-bounds
import pandas as pd
results = pd.read_pickle('ollo2.pickle')
returns, positions, transactions = pf.utils.extract_rets_pos_txn_from_zipline(results)
pf.create_full_tear_sheet(returns, positions=positions, transactions=transactions,
live_start_date='2009-10-22', round_trips=True)
Please provide the full traceback:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-29-b1b1e5451798> in <module>
1 pf.create_full_tear_sheet(returns, positions=positions, transactions=transactions,
----> 2 live_start_date='2009-10-22', round_trips=True)
~/voinv/lib/python3.6/site-packages/pyfolio/tears.py in create_full_tear_sheet(returns, positions, transactions, market_data, benchmark_rets, slippage, live_start_date, sector_mappings, bayesian, round_trips, estimate_intraday, hide_positions, cone_std, bootstrap, unadjusted_returns, style_factor_panel, sectors, caps, shares_held, volumes, percentile, turnover_denom, set_context, factor_returns, factor_loadings, pos_in_dollars, header_rows, factor_partitions)
209 turnover_denom=turnover_denom,
210 header_rows=header_rows,
--> 211 set_context=set_context)
212
213 create_interesting_times_tear_sheet(returns,
~/voinv/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)
~/voinv/lib/python3.6/site-packages/pyfolio/tears.py in create_returns_tear_sheet(returns, positions, transactions, live_start_date, cone_std, benchmark_rets, bootstrap, turnover_denom, header_rows, return_fig)
500 bootstrap=bootstrap,
501 live_start_date=live_start_date,
--> 502 header_rows=header_rows)
503
504 plotting.show_worst_drawdown_periods(returns)
~/voinv/lib/python3.6/site-packages/pyfolio/plotting.py in show_perf_stats(returns, factor_returns, positions, transactions, turnover_denom, live_start_date, bootstrap, header_rows)
620 positions=positions_is,
621 transactions=transactions_is,
--> 622 turnover_denom=turnover_denom)
623
624 perf_stats_oos = perf_func(
~/voinv/lib/python3.6/site-packages/pyfolio/timeseries.py in perf_stats(returns, factor_returns, positions, transactions, turnover_denom)
731 stats['Daily turnover'] = get_turnover(positions,
732 transactions,
--> 733 turnover_denom).mean()
734 if factor_returns is not None:
735 for stat_func in FACTOR_STAT_FUNCS:
~/voinv/lib/python3.6/site-packages/pyfolio/txn.py in get_turnover(positions, transactions, denominator)
191 # Since the first value of pd.rolling returns NaN, we
192 # set our "day 0" AGB to 0.
--> 193 denom.iloc[0] = AGB.iloc[0] / 0
194 elif denominator == 'portfolio_value':
195 denom = positions.sum(axis=1)
~/voinv/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):
~/voinv/lib/python3.6/site-packages/pandas/core/indexing.py in _getitem_axis(self, key, axis)
1828
1829 # validate the location
-> 1830 self._is_valid_integer(key, axis)
1831
1832 return self._get_loc(key, axis=axis)
~/voinv/lib/python3.6/site-packages/pandas/core/indexing.py in _is_valid_integer(self, key, axis)
1711 l = len(ax)
1712 if key >= l or key < -l:
-> 1713 raise IndexError("single positional indexer is out-of-bounds")
1714 return True
1715
IndexError: single positional indexer is out-of-bounds
Please provide any additional information below:
I can't figure this one out, I've been trying a few days now.
I would greatly appreciate any input or direction on this matter.
@CapitalZe have you found the solution? I had the same issue
@CapitalZe have you found the solution? I had the same issue
Same
Likewise
In my case, the live_start_date
was out of the range of the date I had in my dataset. Try another date.