Skip to main content

PortfolioAnalyzer

PortfolioAnalyzer(
    data: vectorbtpro.data.base.Data,
    s1: str,
    s2: str,
    vbt: vectorbtpro.portfolio.base.Portfolio,
    model_output: pandas.core.frame.DataFrame | numpy.ndarray = None,
    window: int = None,
    minp: int = None,
)
A class representing a portfolio analyzer: Analyzes post-simulation backtest and inherites from vbt.Portfolio. Method generated by attrs for class PortfolioAnalyzer.

Class variables

  • data: vectorbtpro.data.base.Data: Data object.
  • s1: str: First symbol.
  • s2: str: Second symbol.
  • vbt: vectorbtpro.portfolio.base.Portfolio: VectorBT PRO Portfolio object.
  • model_output: pandas.core.frame.DataFrame | numpy.ndarray: Model output used in the strategy. Defaults to None.
  • window: int: Rolling window used in the model. Defaults to None.
  • minp: int: Minimum number of observations required in the model. Defaults to None.

Instance variables

  • freq: pandas._libs.tslibs.timedeltas.Timedelta: Get the frequency of the data.
  • column_wrapper: List[str]: Get the column wrapper for the portfolio. If MultiIndex (where group_by is False), Get the first level only.
  • categories: pandas.core.frame.DataFrame | None: Retrieve asset categories.
  • drawdowns_readable: Get the drawdowns of the portfolio.
  • pfo: vectorbtpro.portfolio.pfopt.base.PortfolioOptimizer: Pick allocations from an already filled array.
  • pfo_allocations: pandas.core.frame.DataFrame: Get the portfolio allocations.
  • latest_allocation: pandas.core.frame.DataFrame: Get the latest allocation of the portfolio.
  • current_holdings: Get the current holdings of the portfolio.
  • pfo_describe: pandas.core.frame.DataFrame: Get descriptive statistics of portfolio allocations.
  • average_allocation: Get the average allocation of the portfolio.
  • allocation_records_readable: Get readable allocation records.
  • latest_allocation_records: Get the latest allocation records.

Methods

get_signals

get_signals(
    self,
    sim_start: str | float | int | complex | bool | object | numpy.generic | Sequence[str | float | int | complex | bool | object | numpy.generic] | Sequence[Sequence[Any]] | vectorbtpro._typing.SupportsArrayT | numpy.ndarray = None,
    sim_end: str | float | int | complex | bool | object | numpy.generic | Sequence[str | float | int | complex | bool | object | numpy.generic] | Sequence[Sequence[Any]] | vectorbtpro._typing.SupportsArrayT | numpy.ndarray = None,
    group_by: bool = False,
) ‑> systematica.signals.base.Signals
Return signals for long and short entries and exits. Compute boolean signals indicating the occurrence of long entry orders, long exit orders, short entry orders, and short exit orders. Signals are computed per group if grouping is enabled. Pass group_by=False to disable grouping. Parameters:
NameTypeDefaultDescription
sim_startArrayLikeNoneStart index of the simulation range.
sim_endArrayLikeNoneEnd index of the simulation range.
group_byboolFalseGrouping specification.
Returns:
TypeDescription
Signalssystematica Signals namedtuple class.

get_market_returns

get_market_returns(
    self,
) ‑> pandas.core.frame.DataFrame
Calculate market returns without NaNs. Returns:
TypeDescription
pd.DataFrameDataFrame of market returns.

get_rolling_metrics

get_rolling_metrics(
    self,
    metrics: str | List[str],
    window: int = None,
    minp: int = None,
    to_numpy: bool = False,
    validate_metrics: bool = True,
    **kwargs,
) ‑> pandas.core.frame.DataFrame | numpy.ndarray
Get rolling metrics. Parameters:
NameTypeDefaultDescription
metricsstr--Metric to compute
windowintNoneRolling window length. The default is None.
minpintNoneMininum periods. The default is None.
to_numpyboolFalseOutput numpy array if True. The default is False.
validate_metricsboolTrueValidate metrics if True. The default is True.
kwargstp.Kwargs--Additional key-word arguments passed to MetricRegistry.run_rolling_metric.
Raises:
TypeDescription
ValueErrorif parameter window is to be specified..
Returns:
TypeDescription
pd.DataFrame | tp.ArrayRolling metrics.

all_stats

all_stats(
    self,
    start: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    end: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    portfolio: Dict[str, Any] = None,
    drawdowns: Dict[str, Any] = None,
) ‑> pandas.core.series.Series
Get all statistics of the portfolio. Parameters:
NameTypeDefaultDescription
startstrNoneThe start date. Defaults to None.
endstrNoneThe end date. Defaults to None.
portfoliotp.KwargsNoneAddtional arguments for vbt.stats. Defaults to None.
drawdownstp.KwargsNoneAddtional arguments for vbt.drawdowns.stats. Defaults to None.
Returns:
TypeDescription
pd.SeriesAll portfolio, returns, orders, trades and drawdowns statistics.

plot_rolling_metrics

plot_rolling_metrics(
    self,
    metrics: str | List[str],
    window: int,
    minp: int = None,
    validate_metrics: bool = True,
    **layout_kwargs,
) ‑> vectorbtpro.utils.figure.FigureWidget
Plot rolling metrics. Parameters:
NameTypeDefaultDescription
metricsstr--Metric to compute
windowintNoneRolling window length. The default is None.
minpintNoneMininum periods. The default is None.
validate_metricsboolTrueValidate metrics if True. The default is True.
layout_kwargstp.Kwargs--Additional layout keyword arguments passed to vbt.FigureWidget.plot.
Returns:
TypeDescription
vbt.FigureWidgetFigure widget of the rolling metric.

plot_equity_curve

plot_equity_curve(
    self,
    start: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    end: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    bm_returns: bool = False,
    **layout_kwargs,
) ‑> vectorbtpro.utils.figure.FigureWidget
Plot the equity curve of the portfolio. Parameters:
NameTypeDefaultDescription
startstrNoneThe start date. Defaults to None.
endstrNoneThe end date. Defaults to None.
bm_returnsboolFalseWhether to include benchmark returns. Defaults to False.
layout_kwargstp.Kwargs--Additional layout keyword arguments.
Returns:
TypeDescription
vbt.FigureWidgetFigure widget of the equity curve.

plot_performance_pnl

plot_performance_pnl(
    self,
    symbol: str,
    start: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    end: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    group_by=False,
    pct_scale=False,
    marker_size_range=(7, 14),
    opacity_range=(0.75, 0.9),
    closed_trace_kwargs=None,
    closed_profit_trace_kwargs=None,
    closed_loss_trace_kwargs=None,
    open_trace_kwargs=None,
    hline_shape_kwargs=None,
    add_trace_kwargs=None,
    xref='x',
    yref='y',
    fig=None,
    **layout_kwargs,
) ‑> vectorbtpro.utils.figure.FigureWidget
Plot the performance PnL of the portfolio. Parameters:
NameTypeDefaultDescription
symbolstr--Symbol to plot.
startstrNoneThe start date. Defaults to None.
endstrNoneThe end date. Defaults to None.
group_byboolFalseWhether to group by. Defaults to False.
pct_scaleboolFalseWhether to scale by percentage. Defaults to False.
marker_size_rangetuple“(7,`14)` Range of marker sizes. Defaults to (7, 14).
opacity_rangetuple“(0.75,`0.9)` Range of opacity. Defaults to (0.75, 0.9).
closed_trace_kwargsdictNoneKeyword arguments for closed trace.
closed_profit_trace_kwargsdictNoneKeyword arguments for closed profit trace.
closed_loss_trace_kwargsdictNoneKeyword arguments for closed loss trace.
open_trace_kwargsdictNoneKeyword arguments for open trace.
hline_shape_kwargsdictNoneKeyword arguments for horizontal line shape.
add_trace_kwargsdictNoneKeyword arguments for adding trace.
xrefstrxX reference. Defaults to x.
yrefstryY reference. Defaults to y.
figvbt.FigureWidgetNoneExisting figure widget.
layout_kwargstp.Kwargs--Additional layout keyword arguments.
Returns:
TypeDescription
vbt.FigureWidgetFigure widget of the performance PnL.

plot_running_edge_ratio

plot_running_edge_ratio(
    self,
    start: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    end: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    volatility: bool = None,
    entry_price_open: bool = False,
    exit_price_close: bool = False,
    max_duration: int = None,
    incl_shorter: bool = False,
    group_by: str = None,
    jitted: bool = None,
    xref: str = 'x',
    yref: str = 'y',
    hline_shape_kwargs: Dict[str, Any] = None,
    **kwargs,
) ‑> vectorbtpro.utils.figure.FigureWidget
Plot the running edge ratio of the portfolio. Parameters:
NameTypeDefaultDescription
startstrNoneThe start date. Defaults to None.
endstrNoneThe end date. Defaults to None.
volatilityfloatNoneVolatility value.
entry_price_openboolFalseWhether to use entry price open. Defaults to False.
exit_price_closeboolFalseWhether to use exit price close. Defaults to False.
max_durationintNoneMaximum duration.
incl_shorterboolFalseWhether to include shorter durations. Defaults to False.
group_bystrNoneGroup by value.
jittedboolNoneWhether to use jitted mode. Defaults to None.
xrefstrxX reference. Defaults to x.
yrefstryY reference. Defaults to y.
hline_shape_kwargsdictNoneKeyword arguments for horizontal line shape.
kwargstp.Kwargs--Additional keyword arguments.
Returns:
TypeDescription
vbt.FigureWidgetFigure widget of the running edge ratio.

plot_performance_reset

plot_performance_reset(
    self,
    start: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    end: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    by: str = 'Y',
    add_close: bool = True,
) ‑> vectorbtpro.utils.figure.FigureWidget
Plot the performance reset of the portfolio. Parameters:
NameTypeDefaultDescription
startstrNoneThe start date. Defaults to None.
endstrNoneThe end date. Defaults to None.
bystrYReset by value. Defaults to Y.
add_closeboolTrueWhether to add close prices. Defaults to True.
Returns:
TypeDescription
vbt.FigureWidgetFigure widget of the performance reset.

plot_performance_rebase

plot_performance_rebase(
    self,
    start: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    end: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    add_close: bool = True,
) ‑> vectorbtpro.utils.figure.FigureWidget
Plot the performance rebase of the portfolio. Parameters:
NameTypeDefaultDescription
startstrNoneThe start date. Defaults to None.
endstrNoneThe end date. Defaults to None.
add_closeboolTrueWhether to add close prices. Defaults to True.
Returns:
TypeDescription
vbt.FigureWidgetFigure widget of the performance rebase.

plot_performance_matrix

plot_performance_matrix(
    self,
    start: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    end: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    **plot_kwargs,
) ‑> vectorbtpro.utils.figure.FigureWidget
Plot the performance matrix of the portfolio. Parameters:
NameTypeDefaultDescription
startstrNoneThe start date. Defaults to None.
endstrNoneThe end date. Defaults to None.
plot_kwargstp.Kwargs--Additional plot keyword arguments.
Returns:
TypeDescription
vbt.FigureWidgetFigure widget of the performance matrix.

plot_drawdown_and_underwater

plot_drawdown_and_underwater(
    self,
    start: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    end: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    **plot_kwargs,
) ‑> vectorbtpro.utils.figure.FigureWidget
Plot the drawdowns of the portfolio. Parameters:
NameTypeDefaultDescription
startstrNoneThe start date. Defaults to None.
endstrNoneThe end date. Defaults to None.
plot_kwargstp.Kwargs--Additional plot keyword arguments.
Returns:
TypeDescription
vbt.FigureWidgetFigure widget of the drawdowns.

plot_allocation_report

plot_allocation_report(
    self,
    start: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    end: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    column: Hashable = None,
    dropna: str = 'head',
    line_shape: str = 'hv',
    plot_rb_dates: bool = None,
    trace_kwargs: Dict[str, Any] | Sequence[Dict[str, Any] | None| None = None,
    add_shape_kwargs: Dict[str, Any] | None = None,
    add_trace_kwargs: Dict[str, Any] | None = None,
    fig: plotly.basedatatypes.BaseFigure = None,
    group_by_category: bool = False,
    **layout_kwargs,
) ‑> vectorbtpro.utils.figure.FigureWidget
Plot the allocations of the portfolio. Parameters:
NameTypeDefaultDescription
startstrNoneThe start date. Defaults to None.
endstrNoneThe end date. Defaults to None.
columntp.LabelNoneColumn to plot.
dropnastrheadDrop NaN values. Defaults to head.
line_shapestrhvLine shape. Defaults to hv.
plot_rb_datesboolNoneWhether to plot rebalancing dates.
trace_kwargsdictNoneKeyword arguments for trace.
add_shape_kwargsdictNoneKeyword arguments for adding shape.
add_trace_kwargsdictNoneKeyword arguments for adding trace.
figvbt.FigureWidgetNoneExisting figure widget.
group_by_categoryboolFalseWhether to group by category. Defaults to False.
layout_kwargstp.Kwargs--Additional layout keyword arguments.
Returns:
TypeDescription
vbt.FigureWidgetFigure widget of the allocations.

plot_pie_allocation

plot_pie_allocation(
    self,
    rp_kwargs: Dict[str, Any] | None = None,
    trace_kwargs: Dict[str, Any] | Sequence[Dict[str, Any] | None| None = None,
    add_trace_kwargs: Dict[str, Any] | None = None,
    make_figure_kwargs: Dict[str, Any] | None = None,
    fig: ForwardRef('plotly.basedatatypes.BaseFigure'| None = None,
    **layout_kwargs,
) ‑> vectorbtpro.utils.figure.FigureWidget
Plot the pie chart of the latest allocation. Parameters:
NameTypeDefaultDescription
rp_kwargsdictNoneKeyword arguments for radial plot.
trace_kwargsdictNoneKeyword arguments for trace.
add_trace_kwargsdictNoneKeyword arguments for adding trace.
make_figure_kwargsdictNoneKeyword arguments for making the figure.
figvbt.FigureWidgetNoneExisting figure widget.
layout_kwargstp.Kwargs--Additional layout keyword arguments.
Returns:
TypeDescription
vbt.FigureWidgetFigure widget of the pie chart.

plot_average_allocation

plot_average_allocation(
    self,
    rp_kwargs: Dict[str, Any] | None = None,
    trace_kwargs: Dict[str, Any] | Sequence[Dict[str, Any] | None| None = None,
    add_trace_kwargs: Dict[str, Any] | None = None,
    make_figure_kwargs: Dict[str, Any] | None = None,
    fig: ForwardRef('plotly.basedatatypes.BaseFigure'| None = None,
    **layout_kwargs,
) ‑> vectorbtpro.utils.figure.FigureWidget
Plot the pie chart of the average allocation. Parameters:
NameTypeDefaultDescription
rp_kwargsdictNoneKeyword arguments for radial plot.
trace_kwargsdictNoneKeyword arguments for trace.
add_trace_kwargsdictNoneKeyword arguments for adding trace.
make_figure_kwargsdictNoneKeyword arguments for making the figure.
figvbt.FigureWidgetNoneExisting figure widget.
layout_kwargstp.Kwargs--Additional layout keyword arguments.
Returns:
TypeDescription
vbt.FigureWidgetFigure widget of the pie chart.

plot_cash_report

plot_cash_report(
    self,
    start: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    end: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    **plot_kwargs,
) ‑> vectorbtpro.utils.figure.FigureWidget
Plot the cash balance of the portfolio. Parameters:
NameTypeDefaultDescription
startstrNoneThe start date. Defaults to None.
endstrNoneThe end date. Defaults to None.
plot_kwargstp.Kwargs--Additional plot keyword arguments.
Returns:
TypeDescription
vbt.FigureWidgetFigure widget of the cash balance.

plot_expanding_excursions

plot_expanding_excursions(
    self,
    start: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    end: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    **plot_kwargs,
) ‑> vectorbtpro.utils.figure.FigureWidget
Plot the expanding excursions of the portfolio. Parameters:
NameTypeDefaultDescription
startstrNoneThe start date. Defaults to None.
endstrNoneThe end date. Defaults to None.
plot_kwargstp.Kwargs--Additional plot keyword arguments.
Returns:
TypeDescription
vbt.FigureWidgetFigure widget of the expanding excursions.

plot_excursions

plot_excursions(
    self,
    start: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    end: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    **plot_kwargs,
) ‑> vectorbtpro.utils.figure.FigureWidget
Plot the excursions of the portfolio. Parameters:
NameTypeDefaultDescription
startstrNoneThe start date. Defaults to None.
endstrNoneThe end date. Defaults to None.
plot_kwargstp.Kwargs--Additional plot keyword arguments.
Returns:
TypeDescription
vbt.FigureWidgetFigure widget of the excursions.

plot_trades_by_symbol

plot_trades_by_symbol(
    self,
    symbol: str,
    start: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    end: str | pandas._libs.tslibs.timestamps.Timestamp = None,
) ‑> vectorbtpro.utils.figure.FigureWidget
Plot the trades of the portfolio by symbol. Parameters:
NameTypeDefaultDescription
symbolstr--Symbol to plot.
startstrNoneThe start date. Defaults to None.
endstrNoneThe end date. Defaults to None.
Returns:
TypeDescription
vbt.FigureWidgetFigure widget of the trades by symbol.

plot_all_trades

plot_all_trades(
    self,
    start: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    end: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    **layout_kwargs,
) ‑> vectorbtpro.utils.figure.FigureWidget
Plot all trades of the portfolio. Parameters:
NameTypeDefaultDescription
startstrNoneThe start date. Defaults to None.
endstrNoneThe end date. Defaults to None.
layout_kwargstp.Kwargs--Additional layout keyword arguments.
Returns:
TypeDescription
vbt.FigureWidgetFigure widget of all trades.

plot_dashboard

plot_dashboard(
    self,
    start: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    end: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    **layout_kwargs,
) ‑> vectorbtpro.utils.figure.FigureWidget
Plot the dashboard of the portfolio. Parameters:
NameTypeDefaultDescription
startstrNoneThe start date. Defaults to None.
endpd.TimestampNoneThe end date. Defaults to None.
showlegendboolFalseShow legend. Defaults to False.
layout_kwargstp.Kwargs--Additional layout keyword arguments.
Returns:
TypeDescription
vbt.FigureWidgetFigure widget of the dashboard.