Add objectives
Objectives are added to the portfolio object with the add.objective()
function. Each objective added is a separate object and stored in the objectives
slot in the portfolio specification object. In this way, the objectives are modular and one can easily add, remove, or modify the objective objects. The name
argument must be a valid R function. Several functions are available in the PerformanceAnalytics
package, but user defined functions can also be used as objective functions. The required arguments for add.objective()
are the portfolio
the objective is added to, the objective type
, the objective name
, and named arguments passed via ...
to the constructor of the objective type. Arguments for the objective function are specified as a named list to arguments
.
Basic objective types:
return
: This objective type seeks to maximize the objective.risk
: This objective type seeks to minimize the objective.risk_budget
: This objective type seeks to minimize risk concentration or penalize contribution to risk that exceeds the minimum or maximum allowable percentage contribution to risk.
In addition to the objective types listed above, PortfolioAnalytics
also supports quadratic utility and weight concentration objective types. If you are interested in the other constraint types, look at the help files for the constraint constructors. The help files include a description of the constraint type as well as example code.
This exercise is part of the course
Intermediate Portfolio Analysis in R
Exercise instructions
- Add a return objective to the portfolio specification object
port_spec
you created in a previous exercise. - Add a risk objective to minimize portfolio standard deviation to
port_spec
. - Add a risk budget objective where risk is defined as component standard deviation to
port_spec
. Set the minimum percentage risk to 5% and maximum percentage risk to 10%. - Print the
port_spec
object.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Add a return objective to maximize mean return
port_spec <- add.objective(portfolio = ___, type = ___, name = ___)
# Add a risk objective to minimize portfolio standard deviation
port_spec <- add.objective(portfolio = ___, type = ___, name = ___)
# Add a risk budget objective
port_spec <- add.objective(portfolio = ___, type = ___, name = ___, min_prisk = ___, max_prisk = ___)
# Print the portfolio specification object