Runs n_simulations independent portfolio backtests, each time drawing
a random subset of stocks from stock_list. For every simulation a full
backtest is executed via runPortfolioBacktest(), and an individual plot
can optionally be saved. After all simulations finish, the function
averages the cumulative return series across simulations and can save a
summary plot of those averaged returns.
runMultipleBacktests(
n_simulations,
portfolio_size,
seed = NULL,
return_portfolio,
stock_list,
buildPortfolios = buildPortfolios,
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",
save_avg_plot = TRUE,
avg_plot_path = "./",
avg_plot_name = "avg_backtest",
avg_plot_main = NULL,
avgPlotType = "both",
colorSet = NULL,
ltySet = NULL,
lwdSet = NULL
)A named list with four elements:
resultsA list of length n_simulations. Each element
contains the returns component returned by
runPortfolioBacktest() for that simulation.
selected_stocks_allA list of length n_simulations.
Each element is a character vector of the tickers chosen for that
simulation.
avg_algorithm_returnsAn xts object containing the
element-wise average of all simulations' algorithm return series.
avg_cumulative_returnAn xts object containing the
element-wise average of all simulations' cumulative return series.
Integer. Number of independent backtest simulations to run.
Integer. Number of stocks to randomly sample from
stock_list for each simulation.
Integer. Random seed passed to set.seed() before the
simulation loop for reproducibility.
An xts matrix of asset returns. Column names must
match the assets in stock_list.
Character vector. Universe of stock tickers from which
portfolio_size tickers are drawn at random in each simulation.
A function that accepts a character vector of
selected stock tickers and returns a named list of
portfolio.spec objects, one per strategy. The names of the list
elements are used as strategy labels in plot legends and all other
outputs. Typically built with buildPortfolios and can be customized.
An xts single-column object of benchmark returns.
Character string passed to optimize.portfolio.rebalancing().
See endpoints for valid names.
Positive integer. Length of the rolling estimation window in periods.
Character string specifying the solver. Default "CVXR".
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).
Logical. Whether to save the plot to a PNG file. Default TRUE.
Character string. Full file path for the each simulation output.
Required when save_plot = TRUE.
Plot name for each simulation output. Default "backtest"
Plot title for each simulation PNG output.
"cumRet", "drawdown", or the default is "both"
Logical. Whether to save the the average cumulative
returns plot to a PNG file. Default TRUE.
Character string. Full file path for the average simulation output.
Required when save_avg_plot = TRUE.
Plot name for average simulation output. Default "avg_backtest".
Plot title for the average simulation PNG output.
"cumRet", "drawdown", or the default is "both"
Optional character vector of colors passed to backtest.plot().
Optional integer vector of line types passed to backtest.plot().
Optional integer vector of line width passed to backtest.plot().