stefan-jansen / pyfolio-reloaded

Portfolio and risk analytics in Python
https://pyfolio.ml4trading.io/
Apache License 2.0
348 stars 109 forks source link

Full Tear Sheet: IndexError: index 11 is out of bounds for axis 0 with size 11 #31

Open quantSystemDev opened 1 year ago

quantSystemDev commented 1 year ago

Problem Description

IndexError: index 11 is out of bounds for axis 0 with size 11

I'm following the example located here: https://pyfolio.ml4trading.io/notebooks/zipline_algo_example.html#Full-tear-sheet-example

everything works fine up until the the "full tear sheet" example
The performance table and the drawdown table work ok, but then there is an IndexError followed by an AttributeError

Please provide any additional information below:

IndexError Traceback (most recent call last) File ~\anaconda3\envs\zip38\lib\site-packages\pandas\plotting_matplotlib\tools.py:386, in handle_shared_axes(axarr, nplots, naxes, nrows, ncols, sharex, sharey) 382 for ax in axarr: 383 # only the last row of subplots should get x labels -> all 384 # other off layout handles the case that the subplot is 385 # the last in the column, because below is no subplot/gap. --> 386 if not layout[row_num(ax) + 1, col_num(ax)]: 387 continue

IndexError: index 11 is out of bounds for axis 0 with size 11

During handling of the above exception, another exception occurred:

AttributeError Traceback (most recent call last) Cell In[13], line 1 ----> 1 pf.create_full_tear_sheet(returns, positions=positions, transactions=transactions, 2 live_start_date='2009-10-22', round_trips=True)

File ~\anaconda3\envs\zip38\lib\site-packages\pyfolio\tears.py:199, in create_full_tear_sheet(returns, positions, transactions, market_data, benchmark_rets, slippage, live_start_date, sector_mappings, round_trips, estimate_intraday, hide_positions, cone_std, bootstrap, unadjusted_returns, turnover_denom, set_context, factor_returns, factor_loadings, pos_in_dollars, header_rows, factor_partitions) 191 returns = txn.adjust_returns_for_slippage( 192 returns, positions, transactions, slippage 193 ) 195 positions = utils.check_intraday( 196 estimate_intraday, returns, positions, transactions 197 ) --> 199 create_returns_tear_sheet( 200 returns, 201 positions=positions, 202 transactions=transactions, 203 live_start_date=live_start_date, 204 cone_std=cone_std, 205 benchmark_rets=benchmark_rets, 206 bootstrap=bootstrap, 207 turnover_denom=turnover_denom, 208 header_rows=header_rows, 209 set_context=set_context, 210 ) 212 create_interesting_times_tear_sheet( 213 returns, benchmark_rets=benchmark_rets, set_context=set_context 214 ) 216 if positions is not None:

File ~\anaconda3\envs\zip38\lib\site-packages\pyfolio\plotting.py:50, in customize..call_w_context(*args, kwargs) 48 if set_context: 49 with plotting_context(), axes_style(): ---> 50 return func(*args, *kwargs) 51 else: 52 return func(args, kwargs)

File ~\anaconda3\envs\zip38\lib\site-packages\pyfolio\tears.py:583, in create_returns_tear_sheet(returns, positions, transactions, live_start_date, cone_std, benchmark_rets, bootstrap, turnover_denom, header_rows, return_fig) 580 ax_return_quantiles = plt.subplot(gs[i, :]) 581 i += 1 --> 583 plotting.plot_rolling_returns( 584 returns, 585 factor_returns=benchmark_rets, 586 live_start_date=live_start_date, 587 cone_std=cone_std, 588 ax=ax_rolling_returns, 589 ) 590 ax_rolling_returns.set_title("Cumulative returns") 592 plotting.plot_rolling_returns( 593 returns, 594 factor_returns=benchmark_rets, (...) 599 ax=ax_rolling_returns_vol_match, 600 )

File ~\anaconda3\envs\zip38\lib\site-packages\pyfolio\plotting.py:837, in plot_rolling_returns(returns, factor_returns, live_start_date, logy, cone_std, legend_loc, volatility_match, cone_function, ax, kwargs) 834 is_cum_returns = cum_rets 835 oos_cum_returns = pd.Series([]) --> 837 is_cum_returns.plot( 838 lw=3, color="forestgreen", alpha=0.6, label="Backtest", ax=ax, kwargs 839 ) 841 if len(oos_cum_returns) > 0: 842 oos_cum_returns.plot( 843 lw=4, color="red", alpha=0.6, label="Live", ax=ax, **kwargs 844 )

File ~\anaconda3\envs\zip38\lib\site-packages\pandas\plotting_core.py:955, in PlotAccessor.call(self, *args, kwargs) 952 label_name = label_kw or data.columns 953 data.columns = label_name --> 955 return plot_backend.plot(data, kind=kind, kwargs)

File ~\anaconda3\envs\zip38\lib\site-packages\pandas\plotting_matplotlib__init__.py:61, in plot(data, kind, kwargs) 59 kwargs["ax"] = getattr(ax, "left_ax", ax) 60 plot_obj = PLOT_CLASSES[kind](data, kwargs) ---> 61 plot_obj.generate() 62 plot_obj.draw() 63 return plot_obj.result

File ~\anaconda3\envs\zip38\lib\site-packages\pandas\plotting_matplotlib\core.py:283, in MPLPlot.generate(self) 281 self._add_table() 282 self._make_legend() --> 283 self._adorn_subplots() 285 for ax in self.axes: 286 self._post_plot_logic_common(ax, self.data)

File ~\anaconda3\envs\zip38\lib\site-packages\pandas\plotting_matplotlib\core.py:485, in MPLPlot._adorn_subplots(self) 483 all_axes = self._get_subplots() 484 nrows, ncols = self._get_axes_layout() --> 485 handle_shared_axes( 486 axarr=all_axes, 487 nplots=len(all_axes), 488 naxes=nrows * ncols, 489 nrows=nrows, 490 ncols=ncols, 491 sharex=self.sharex, 492 sharey=self.sharey, 493 ) 495 for ax in self.axes: 496 if self.yticks is not None:

File ~\anaconda3\envs\zip38\lib\site-packages\pandas\plotting_matplotlib\tools.py:395, in handle_shared_axes(axarr, nplots, naxes, nrows, ncols, sharex, sharey) 391 except IndexError: 392 # if gridspec is used, ax.rowNum and ax.colNum may different 393 # from layout shape. in this case, use last_row logic 394 for ax in axarr: --> 395 if ax.is_last_row(): 396 continue 397 if sharex or _has_externally_shared_axis(ax, "x"):

AttributeError: 'Axes' object has no attribute 'is_last_row'

Versions