0

I would like to find the minimum variance portfolio for 3 risky assets where the sum of the weights of all assets = 2 and weight of asset1 is set at +1 (i.e the problem would be to minimise the portfolio vol by adjusting only the weights for asset asset 2 and 3 subject to them not being more than 1 and >=0. I have found the below snippet of code that minimise the risk for a 3 asset portfolio, but I am unsure about how to incorporate the weight constraints. Any help / suggestions are welcome.

 covmat <- matrix(c(3.235343e-02, -3.378191e-03, -1.544574e-05, -3.378191e-03, 8.769166e-03, 1.951734e-06, -1.544574e-05, 1.951734e-06, 2.186799e-06),3,3) mat <- rbind(cbind(2*covmat,rep(1, 3)), c(rep(1, 3), 0)) vec <- c(rep(0, 3),1) smat <- solve(mat)%*%vec smat[1:3,1] 

Thank you,

1 Answer 1

1

R has a QP (quadratic programming) solver that is designed for these type of problems:

library(quadprog) covmat <- matrix(c(3.235343e-02, -3.378191e-03, -1.544574e-05, -3.378191e-03, 8.769166e-03, 1.951734e-06, -1.544574e-05, 1.951734e-06, 2.186799e-06),3,3) # linear constraint matrix A <- rbind(c(1,1,1),diag(3)) # rhs b <- c(2,1,0,0) # solve QP model solve.QP(covmat,dvec=rep(0,3),Amat=t(A),bvec=b,meq=2)$solution 

Output:

[1] 1.0000000 0.3835757 0.6164243 
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much Erwin this is exactely what I was after. I shall look at QP in more details. I really appreciate the time you spent on this.
The above was for a minimum variance problem. i.e all the returns are assumed to be zero in dvec. Now I would like also to solve for a mean variance problem with the same weights constraints (i.e asset a = 1 and asset b & c are left to fluctuate without other constraints other than their weights >=0 and weights a+b+c equal 2) but where the returns of asset a, b & c are respectively (0, 0.1,0.03) . Do i just change the dvec =rep(0,3) with dvec=c(0,0.1,0.03) ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.