runPortfolioBacktest: Run Portfolio Backtest and Plot

View source: R/runPortfolioBacktest.R

runPortfolioBacktestR Documentation

Run Portfolio Backtest and Plot

Description

Perform a backtest for a list of portfolio specifications. Portfolio objectives, constraints, rolling window, and rebalancing frequency can be customized using the same conventions as used in PortfolioAnalytics.

Usage

runPortfolioBacktest(
  return_portfolio,
  portfolio_list,
  portfolio_names,
  market_return = NULL,
  rebalance_on = NULL,
  rolling_window = NULL,
  optimize_method = "CVXR",
  moment_list = NULL,
  save_plot = TRUE,
  plot_path = "./",
  plot_name = "backtest",
  plot_main = NULL,
  plotType = "both",
  colorSet = NULL,
  ltySet = NULL,
  lwdSet = NULL
)

Arguments

return_portfolio

An xts matrix of asset returns. Column names must match the assets in each portfolio.spec object.

portfolio_list

A list of portfolio.spec objects built with PortfolioAnalytics.

portfolio_names

Character vector of names corresponding to each portfolio in portfolio_list.

market_return

An xts single-column object of benchmark returns.

rebalance_on

Character string passed to optimize.portfolio.rebalancing(). See endpoints for valid names.

rolling_window

Positive integer. Length of the rolling estimation window in periods.

optimize_method

Character string specifying the solver. Default "CVXR".

moment_list

If different moment functions are passed into multiple GMV portfolios, please define each moment function via this parameter. For the portfolio that do not require moment function, please pass NULL. Example: list('custom.covRob.Rocke', NULL, NULL).

save_plot

Logical. Whether to save the plot to a PNG file. Default TRUE.

plot_path

Character string. Full file path for the PNG output. Required when save_plot = TRUE.

plot_name

Plot name for the PNG output. Default "backtest".

plot_main

Plot title for the PNG output.

plotType

"cumRet", "drawdown", or the default is "both"

colorSet

Optional character vector of colors passed to backtest.plot().

ltySet

Optional integer vector of line types passed to backtest.plot().

lwdSet

Optional integer vector of line width passed to backtest.plot().

Value

A list:

returns

An xts matrix of period returns with one column per portfolio plus a "Market" column.

cumRet

An xts matrix of cumulative returns.

plot

The plot object returned by backtest.plot().

Examples

args(runPortfolioBacktest)

PCRA documentation built on July 15, 2026, 9:06 a.m.