Skip to main content

PortfolioAnalyzer

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

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: Returns:

get_market_returns

Calculate market returns without NaNs. Returns:

get_pf_metrics

Get performance metrics from a backtested portfolio. Parameters: Returns:

get_rolling_metrics

Get rolling metrics. Parameters: Raises: Returns:

all_stats

Get all statistics of the portfolio. Parameters: Returns:

plot_rolling_metrics

Plot rolling metrics. Parameters: Returns:

plot_equity_curve

Plot the equity curve of the portfolio. Parameters: Returns:

plot_performance_pnl

Plot the performance PnL of the portfolio. Parameters: Returns:

plot_running_edge_ratio

Plot the running edge ratio of the portfolio. Parameters: Returns:

plot_performance_reset

Plot the performance reset of the portfolio. Parameters: Returns:

plot_performance_rebase

Plot the performance rebase of the portfolio. Parameters: Returns:

plot_performance_matrix

Plot the performance matrix of the portfolio. Parameters: Returns:

plot_drawdown_and_underwater

Plot the drawdowns of the portfolio. Parameters: Returns:

plot_allocation_report

Plot the allocations of the portfolio. Parameters: Returns:

plot_pie_allocation

Plot the pie chart of the latest allocation. Parameters: Returns:

plot_average_allocation

Plot the pie chart of the average allocation. Parameters: Returns:

plot_cash_report

Plot the cash balance of the portfolio. Parameters: Returns:

plot_excursions

Plot trade excursions for a portfolio. This function visualizes Maximum Adverse Excursion (MAE) and Maximum Favorable Excursion (MFE) for each trade in the portfolio. Parameters: Returns:

plot_trades_by_symbol

Plot the trades of the portfolio by symbol. Parameters: Returns:

plot_all_trades

Plot all trades of the portfolio. Parameters: Returns:

plot_dashboard

Plot the dashboard of the portfolio. Parameters: Returns: