Single-Period optimization
There are two functions for running the optimization, optimize.portfolio()
and optimize.portfolio.rebalancing()
. This exercise will focus on single period optimization and the next exercise will use optimize.portfolio.rebalancing()
for optimization with periodic rebalancing. optimize.portfolio()
supports single-period optimization. Key arguments include R
for the asset returns, portfolio
for the portfolio specification object, and optimize_method
to specify the optimization method used to solve the problem. In many cases, it is useful to specify trace = TRUE
to store additional information for each iteration/trial of the optimization.
The following optimization methods are supported:
DEoptim
: Differential evolutionrandom
: Random portfoliosGenSA
: Generalized Simulated Annealingpso
: Particle swarm optimizationROI
: R Optimization Infrastructure for linear and quadratic programming solvers
The optimization method you choose should be based on the type of problem you are solving. For example, a problem that can be formulated as a quadratic programming problem should be solved using a quadratic programming solver, whereas a non-convex problem should be solved using a global solver such as DEoptim.
In this exercise, we will define the portfolio optimization problem to maximize mean return and minimize portfolio standard deviation with a standard deviation risk budget where the minimum percentage risk is 5% and the maximum percentage risk is 10%, subject to full investment and long only constraints. The risk budget objective requires a global solver so we will solve the problem using random portfolios. The set of random portfolios, rp
, is generated using 500 permutations for this exercise.
This exercise is part of the course
Intermediate Portfolio Analysis in R
Exercise instructions
The portfolio specification has already been created and is named port_spec
. Also in your workspace are the returns, asset_returns
.
- Run a single-period optimization with
trace
set toTRUE
using"random"
as the optimization method. Assign the optimization output to a variable namedopt
. - Print the output of the optimization.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Run a single period optimization using random portfolios as the optimization method
opt <- optimize.portfolio(R = ___, portfolio = ___, optimize_method = ___, rp = rp, trace = TRUE)
# Print the output of the single-period optimization