quantlab.runs.backtest_report.backtest_report_figure#
- quantlab.runs.backtest_report.backtest_report_figure(account, *, metrics=None, benchmark=None)[source]#
Return the Performance chart of a run’s
report.htmlas a plotly figure.Equity, drawdown and compounded monthly returns on a shared time axis, the in-sample range shaded, the deepest drawdown marked and the notes below; with a benchmark, its NAV, drawdown and monthly returns beside the portfolio’s. The excess over the benchmark is not drawn here:
report.htmldraws it on its own tab, apart from the drawdowns, because the drawdown of the relative NAV is a different quantity from either NAV’s drawdown. The arguments mean what they mean forwrite_backtest_report, whose Performance tab is this chart without the notes (the page lists them in its own section).- Returns:
- plotly.graph_objects.Figure
The figure, not yet shown or written.
Examples
>>> import pandas as pd, xarray as xr >>> from quantlab.runs.run_metrics import AccountRecord >>> bars = pd.bdate_range("2024-01-01", periods=5) >>> on_bars = dict(dims="timestamp", coords={"timestamp": bars}) >>> account = AccountRecord( ... value=xr.DataArray([100.0, 104.0, 98.0, 103.0, 110.0], **on_bars), ... returns=xr.DataArray([0.0, 0.04, -0.0577, 0.051, 0.068], **on_bars), ... orders=xr.Dataset(), ... rebalances=xr.Dataset({"scheduled": ("timestamp", [False] * 5), ... "decided": ("timestamp", [False] * 5)}, coords={"timestamp": bars}), ... init_cash=100.0, bar_interval="1D", year_freq=pd.Timedelta(days=252), ... ) >>> figure = backtest_report_figure(account) >>> sorted(trace.name for trace in figure.data) ['deepest_drawdown_end', 'deepest_drawdown_valley', 'drawdown', 'equity', 'monthly_return']