Imposing weight constraints
Investors are often constrained by the maximum values allowed for the portfolio weights. These constraints can actually be an advantage. The advantage of a maximum weight constraint is that the subsequent portfolio will be less concentrated in certain assets. There is a disadvantage to this, though. The disadvantage is that the same target return may no longer be possible or will be obtained at the expense of higher volatility.
Remember from the previous exercise that the function portfolio.optim()
allows you to set weight constraints within the
reshigh
argument. reshigh
requires a vector of maximum weights for each asset.
In this exercise, you will create three portfolios with different maximum weight constraints. For this exercise, it is important to know the output of the portfolio.optim()
function. This function creates a list containing four components: (i) $pw
: the portfolio weights, (ii) $px
: the returns of the overall portfolio, (iii) $pm
: the expected return portfolio, (iv) $ps
: the standard deviation of the portfolio returns.
This exercise is part of the course
Introduction to Portfolio Analysis in R
Exercise instructions
- Create three vectors of maximum weights for each asset (column) in
returns
using therep()
function. The first vector will contain maximum weights of 100%, the second 10%, and the third 5%. Call thesemax_weights1
,max_weights2
,max_weights3
, respectively. - Create an optimum portfolio with maximum weights of 100% called
opt1
. - Create an optimum portfolio with maximum weights of 10% called
opt2
. - Create an optimum portfolio with maximum weights of 5% called
opt3
. - Calculate how many assets have a weight that is greater than 1% for each portfolio. Access weights by using
$pw
after the portfolio name. - Print the volatilities (standard deviations
$ps
) of the three portfolios you created.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create vectors of maximum weights
max_weights1 <- rep(1, ncol(returns))
max_weights2 <- ___
max_weights3 <- ___
# Create an optimum portfolio with max weights of 100%
opt1 <- portfolio.optim(___, reshigh = ___)
# Create an optimum portfolio with max weights of 10%
# Create an optimum portfolio with max weights of 5%
# Calculate how many assets have a weight that is greater than 1% for each portfolio
sum(opt1$pw > .01)
sum(___$pw > .01)
sum(___$pw > .01)
# Print portfolio volatilites
opt1$ps
___$__
___$__