plotPerformanceVsParams {portfolioBacktest} | R Documentation |
Plot performance of portfolio function vs choice of parameters
Description
Portfolio functions usually contain some parameters that can be tuned.
After generating multiple versions of a portfolio function with randomly chosen parameters
with the function genRandomFuns
and doing the backtesting, this function
can be used to plot the performance vs choice of parameters.
Usage
plotPerformanceVsParams(
bt_all_portfolios,
params_subset = NULL,
name_performance = "Sharpe ratio",
summary_fun = median
)
Arguments
bt_all_portfolios |
Backtest results as produced by the function |
params_subset |
List of named parameters with a subset of the values to be considered. By default all the possible values will be considered. |
name_performance |
String with the name of the performance measure to be used. |
summary_fun |
Summary function to be employed (e.g., median or mean). Defult is median. |
Author(s)
Daniel P. Palomar and Rui Zhou
See Also
Examples
library(portfolioBacktest)
# define GMVP with parameters "delay", "lookback", and "regularize"
GMVP_portfolio_fun <- function(dataset, ...) {
prices <- tail(lag(dataset$adjusted, delay), lookback)
X <- diff(log(prices))[-1]
Sigma <- cov(X)
if (regularize)
Sigma <- Sigma + 0.01*diag(ncol(Sigma))
# design GMVP
w <- solve(Sigma, rep(1, ncol(Sigma)))
return(w/sum(w))
}
# generate the functions with random parameters
portfolio_list <- genRandomFuns(portfolio_fun = GMVP_portfolio_fun,
params_grid = list(lookback = c(100, 120, 140, 160),
delay = c(0, 5, 10, 15, 20),
regularize = c(FALSE, TRUE)),
name = "GMVP",
N_funs = 40)
# backtest portfolios
bt <- portfolioBacktest(portfolio_list, dataset10)
# plot
plotPerformanceVsParams(bt)
plotPerformanceVsParams(bt, params_subset = list(regularize = TRUE))
plotPerformanceVsParams(bt, params_subset = list(delay = 5))
plotPerformanceVsParams(bt, params_subset = list(delay = 5, regularize = TRUE))
[Package portfolioBacktest version 0.4.1 Index]