optimize.portfolio.rebalancing {PortfolioAnalytics} | R Documentation |
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", "CVXR"),
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 |
constraints |
default NULL, a list of constraint 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 |
rp |
a set of random portfolios passed into the function to prevent recalculation |
rebalance_on |
character string of period to rebalance on. See
|
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. |
portfolio |
an object of type "portfolio" specifying the constraints and objectives for the optimization |
objectives |
default NULL, a list of objective objects |
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.
If both training_period
and rolling_window
are NULL
,
then training_period
is set to a default value of 36.
If training_period
is NULL
and a rolling_window
is
specified, then training_period
is set to the value of
rolling_window
.
The user should be aware of the following behavior when both
training_period
and rolling_window
are specified and have
different values
training_period < rolling_window
:For example, if you have
rolling_window=60
,training_period=50
, and the periodicity of the data is the same as the rebalance frequency (i.e. monthly data withrebalance_on="months")
then the returns data used in the optimization at each iteration are as follows:1: R[1:50,]
2: R[1:51,]
...
11: R[1:60,]
12: R[1:61,]
13: R[2:62,]
...
This results in a growing window for several optimizations initially while the endpoint iterator (i.e.
[50, 51, ...]
) is less than the rolling window width.training_period > rolling_window
:The data used in the initial optimization is
R[(training_period - rolling_window):training_period,]
. This results in some of the data being "thrown away", i.e. periods 1 to(training_period - rolling_window - 1)
are not used in the optimization.
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.
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.
Author(s)
Kris Boudt, Peter Carl, Brian G. Peterson
See Also
portfolio.spec
optimize.portfolio
Examples
## 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)