Description Usage Arguments Details Value Note Author(s) See Also
This function aims to provide a wrapper for constrained optimization of portfolios that specify constraints and objectives.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | optimize.portfolio_v1(R, constraints,
optimize_method = c("DEoptim", "random", "ROI", "ROI_old", "pso", "GenSA"),
search_size = 20000, trace = FALSE, ..., rp = NULL,
momentFUN = "set.portfolio.moments_v1")
optimize.portfolio_v2(R, portfolio = NULL,
constraints = NULL, objectives = NULL,
optimize_method = c("DEoptim", "random", "ROI", "pso", "GenSA"),
search_size = 20000, trace = FALSE, ..., rp = NULL,
momentFUN = "set.portfolio.moments", message = FALSE)
optimize.portfolio(R, portfolio = NULL,
constraints = NULL, objectives = NULL,
optimize_method = c("DEoptim", "random", "ROI", "pso", "GenSA"),
search_size = 20000, trace = FALSE, ..., rp = NULL,
momentFUN = "set.portfolio.moments", message = FALSE)
|
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. An object of class 'v1_constraint' can be passed in here. |
objectives |
default=NULL, a list of objective objects. |
optimize_method |
one of "DEoptim", "random", "ROI", "pso", "GenSA". A solver for ROI can also be specified and will be solved using ROI. See Details. |
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 |
rp |
matrix of random portfolio weights, default NULL, mostly for automated use by rebalancing optimization or repeated tests on same portfolios |
momentFUN |
the name of a function to call to set
portfolio moments, default
|
message |
TRUE/FALSE. The default is message=FALSE. Display messages if TRUE. |
This function currently supports DEoptim, random portfolios, pso, GenSA, and ROI as back ends. Additional back end contributions for Rmetrics, ghyp, etc. would be welcome.
When using random portfolios, search_size is precisely that, how many portfolios to test. You need to make sure to set your feasible weights in generatesequence to make sure you have search_size unique portfolios to test, typically by manipulating the 'by' parameter to select something smaller than .01 (I often use .002, as .001 seems like overkill)
When using DE, search_size is decomposed into two other parameters which it interacts with, NP and itermax.
NP, the number of members in each population, is set to cap at 2000 in DEoptim, and by default is the number of parameters (assets/weights) * 10.
itermax, if not passed in dots, defaults to the number of parameters (assets/weights) * 50.
When using GenSA and want to set verbose=TRUE
,
instead use trace
.
If optimize_method="ROI"
is specified, a default
solver will be selected based on the optimization
problem. The glpk
solver is the default solver for
LP and MILP optimization problems. The quadprog
solver is the default solver for QP optimization
problems. For example, optimize_method =
"quadprog"
can be specified and the optimization problem
will be solved via ROI using the quadprog solver.
The extension to ROI solves a limited type of convex optimization problems:
Maxmimize portfolio return subject leverage, box, group, position limit, target mean return, and/or factor exposure constraints on weights.
Minimize portfolio variance subject to leverage, box, group, turnover, and/or factor exposure constraints (otherwise known as global minimum variance portfolio).
Minimize portfolio variance subject to leverage, box, group, and/or factor exposure constraints and a desired portfolio return.
Maximize quadratic utility
subject to leverage, box, group, target mean return,
turnover, and/or factor exposure constraints and risk
aversion parameter. (The risk aversion parameter is
passed into optimize.portfolio
as an added
argument to the portfolio
object).
Maximize
portfolio mean return per unit standard deviation (i.e.
the Sharpe Ratio) can be done by specifying
maxSR=TRUE
in optimize.portfolio
. If both
mean and StdDev are specified as objective names, the
default action is to maximize quadratic utility,
therefore maxSR=TRUE
must be specified to maximize
Sharpe Ratio.
Minimize portfolio ES/ETL/CVaR optimization subject to leverage, box, group, position limit, target mean return, and/or factor exposure constraints and target portfolio return.
Maximize
portfolio mean return per unit ES/ETL/CVaR (i.e. the
STARR Ratio) can be done by specifying
maxSTARR=TRUE
in optimize.portfolio
. If
both mean and ES/ETL/CVaR are specified as objective
names, the default action is to maximize mean return per
unit ES/ETL/CVaR.
These problems also support a weight_concentration objective where concentration of weights as measured by HHI is added as a penalty term to the quadratic objective.
Because these convex optimization problem are
standardized, there is no need for a penalty term. The
multiplier
argument in add.objective
passed into the complete constraint object are ingnored
by the ROI solver.
a list containing the following elements
weights
: The optimal set weights.
objective_measures
: A list containing the
value of each objective corresponding to the optimal
weights.
opt_values
: A list containing
the value of each objective corresponding to the optimal
weights.
out
: The output of the solver.
call
: The function call.
portfolio
: The portfolio object.
R
: The asset returns.
data
summary:
The first row and last row of R
.
elapsed_time:
The amount of time that
elapses while the optimization is run.
end_t:
The date and time the optimization
completed.
When Trace=TRUE is specified, the following elements will be returned in addition to the elements above. The output depends on the optimization method and is specific to each solver. Refer to the documentation of the desired solver for more information.
optimize_method="random"
random_portfolios
: A matrix of the random
portfolios.
random_portfolio_objective_results
: A list
of the following elements for each random portfolio.
out
: The output value of the
solver corresponding to the random portfolio weights.
weights
: The weights of the random
portfolio.
objective_measures
: A list of
each objective measure corresponding to the random
portfolio weights.
optimize_method="DEoptim"
DEoutput:
A list (of length 2) containing
the following elements:
optim
member
DEoptim_objective_results
: A list
containing the following elements for each intermediate
population.
out
: The output of
the solver.
weights
: Population weights.
init_weights
: Initial population weights.
objective_measures
: A list of each
objective measure corresponding to the weights
optimize_method="pso"
PSOoutput
: A list containing the following
elements:
par
value
counts
convergence
message
stats
optimize_method="GenSA"
GenSAoutput:
A list containing the
following elements:
value
par
trace.mat
counts
An object of class v1_constraint
can be passed in
for the constraints
argument. The
v1_constraint
object was used in the previous 'v1'
specification to specify the constraints and objectives
for the optimization problem, see
constraint
. We will attempt to detect if
the object passed into the constraints argument is a
v1_constraint
object and update to the 'v2'
specification by adding the constraints and objectives to
the portfolio
object.
Kris Boudt, Peter Carl, Brian G. Peterson, Ross Bennett
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.