Refine constraints and objectives
Here we hypothesize that refining constraints and/or objectives will improve performance. Let us add a risk budget objective to set a minimum and maximum percentage contribution to risk for each asset. We will be building on the portfolio specification we created. This is a more complex optimization problem and will require a global solver so we will use random portfolios as the optimization method.
This exercise is part of the course
Intermediate Portfolio Analysis in R
Exercise instructions
- Add a risk budget objective
risk_budget
toport_spec
where risk is defined as standard deviation. Set the minimum percentage risk to 5% and the maximum percentage risk to 10%. - Run the optimization with quarterly rebalancing. Set the training period and rolling window to use 5 years of data. Assign the results to a variable named
opt_rebal_rb
. - Chart the weights.
- Chart the component percentage contribution to risk.
- Compute the portfolio returns using
Return.portfolio()
. Assign the returns to a variable namedreturns_rb
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Add a risk budge objective
port_spec <- add.objective(portfolio = ___,
type = ___,
name = ___,
min_prisk = ___,
max_prisk = ___)
# Run the optimization
opt_rebal_rb <- optimize.portfolio.rebalancing(R = ___,
portfolio = ___,
optimize_method = "random", rp = rp,
trace = TRUE,
rebalance_on = ___,
training_period = ___,
rolling_window = ___)
# Chart the weights
# Chart the percentage contribution to risk
chart.RiskBudget(___, match.col = "StdDev", risk.type = ___)
# Compute the portfolio returns
returns_rb <- Return.portfolio(R = ___, weights = ___)
colnames(returns_rb) <- "risk_budget"