Learn R Programming

PortfolioAnalytics (version 1.0.3636)

optimize.portfolio.rebalancing: Portfolio Optimization with Rebalancing Periods

Description

Portfolio optimization with support for rebalancing periods for out-of-sample testing (i.e. backtesting)

Usage

optimize.portfolio.rebalancing_v1(R, constraints, optimize_method = c("DEoptim", "random", "ROI"), search_size = 20000, trace = FALSE, ..., rp = NULL, rebalance_on = NULL, training_period = NULL, rolling_window = NULL)
optimize.portfolio.rebalancing(R, portfolio = NULL, constraints = NULL, objectives = NULL, optimize_method = c("DEoptim", "random", "ROI"), search_size = 20000, trace = FALSE, ..., rp = NULL, rebalance_on = NULL, training_period = NULL, rolling_window = NULL)

Arguments

R
an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns
portfolio
an object of type "portfolio" specifying the constraints and objectives for the optimization
constraints
default NULL, a list of constraint objects
objectives
default NULL, a list of objective objects
optimize_method
one of "DEoptim", "random", "pso", "GenSA", or "ROI"
search_size
integer, how many portfolios to test, default 20,000
trace
TRUE/FALSE if TRUE will attempt to return additional information on the path or portfolios searched
...
any other passthru parameters to optimize.portfolio
rp
a set of random portfolios passed into the function to prevent recalculation
rebalance_on
character string of period to rebalance on. See endpoints for valid names.
training_period
an integer of the number of periods to use as a training data in the front of the returns data
rolling_window
an integer of the width (i.e. number of periods) of the rolling window, the default of NULL will run the optimization using the data from inception.

Value

a list containing the following elements
  • portfolio: The portfolio object.
  • R: The asset returns.
  • call: The function call.
  • elapsed_time: The amount of time that elapses while the optimization is run.
  • opt_rebalancing: A list of optimize.portfolio objects computed at each rebalancing period.

Details

Run portfolio optimization with periodic rebalancing at specified time periods. Running the portfolio optimization with periodic rebalancing can help refine the constraints and objectives by evaluating the out of sample performance of the portfolio based on historical data

This function is a essentially a wrapper around optimize.portfolio and thus the discussion in the Details section of the optimize.portfolio help file is valid here as well.

This function is massively parallel and requires the 'foreach' package. It is suggested to register a parallel backend.

See Also

portfolio.spec optimize.portfolio

Examples

Run this code
## Not run: 
# data(edhec)
# R <- edhec[,1:4]
# funds <- colnames(R)
# 
# portf <- portfolio.spec(funds)
# portf <- add.constraint(portf, type="full_investment")
# portf <- add.constraint(portf, type="long_only")
# portf <- add.objective(portf, type="risk", name="StdDev")
# 
# # Quarterly rebalancing with 5 year training period
# bt.opt1 <- optimize.portfolio.rebalancing(R, portf,
# optimize_method="ROI",
# rebalance_on="quarters",
# training_period=60)
# 
# # Monthly rebalancing with 5 year training period and 4 year rolling window
# bt.opt2 <- optimize.portfolio.rebalancing(R, portf,
# optimize_method="ROI",
# rebalance_on="months",
# training_period=60,
# rolling_window=48)
# ## End(Not run)

Run the code above in your browser using DataLab