The global minimum variance portfolio - Part Two
Now you want to construct the global minimum variance portfolio under the condition that short sales are not allowed. The Markowitz portfolio optimization problem for the minimum variance portfolio with no short sales restrictions can be described as follows:
$$\underset{x}{\text{min}} \ \sigma^2_{p,x} = x'\sum x \text {, subject to}$$ $$x'\mathbf{1} = 1$$ $$x_i \geq 0,$$
with \(x\) the vector of portfolio weights, \(\sigma^2_{p,x}\) and \(\mu_{p,x}\) the portfolio variance and expected return respectively, \(\mu\) the vector of expected returns and \(\Sigma\) the covariance matrix of the returns.
As seen in the lectures, the portfolio optimization problem with inequality constraints can be set up as a quadratic programming problem. Quadratic programming problems are of the form: $$\underset{x}{\text{min}} \ \frac{1}{2}x'Dx - d'x \text{, subject to}$$ $$A'_{neq} x \geq b_{neq} \text{, for } m \text{ inequality constraints, and }$$ $$A'_{eq} x = b_{neq} \text{, for } l \text{ equality constraints,}$$ where \(D\) is a \(n \times n\) matrix, \(x\) and \(d\) are \(n \times 1\) vectors, \(A'_{neq}\) is an \(m \times n\) matrix, \(b_{neq}\) is an \(m \times 1\) vector, \(A'_{eq}\) is an \(l \times n\) matrix, and \(b_{eq}\) is an \(l \times 1\) vector.
Quadratic programming problems can be solved with the R package quadprog
and the solve.QP()
function. In the next exercise you will discover a more easy way to do this with the help of globalMin.portfolio()
.
This exercise is part of the course
Intro to Computational Finance with R
Exercise instructions
- The restriction matrices are already set up. Make sure to study their output.
- Use these restriction matrices and the global minimum variance portfolio equality constraint to minimize the portfolio variance via
solve.QP()
. Assign the result toquad_prog
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# All data and CER parameters are preloaded in your workspace. Type ls() in the console to see them.
# set restriction matrices
D_matrix <- 2 * cov_mat_month
D_matrix
d_vector <- rep(0, 4)
d_vector
A_matrix <- cbind(rep(1, 4), diag(4))
A_matrix
b_vector <- c(1, rep(0, 4))
b_vector
# use solve.QP to minimize portfolio variance
quad_prog <-
quad_prog