# Using Matlab quadprog to solve markowitz model

I have the markowitz model shown below and I need to use the quadprog function to solve it (i.e get the values for w_i values). However I am a bit new to mat lab and not sure which definition of quadprog to use. Could someone help me with this ? thanks

-

You need an n * n covariance matrix sigma and a vector of expected returns r.

Your objective is to minimize 1/2 * w' * sigma * w subject to r' * w > r_target and ones(1,n) * w = 1. Therefore, following the documentation on the Mathworks website you should call quadprog with

H = sigma
f = zeros(n,1)
A = r'
b = r_target
Aeq = ones(1,n)
beq = 1


That is,

w = quadprog(H,f,A,b,Aeq,beq)

-
Thanks so much also what else I need to add to prevent short selling ? (all weights >= 0) –  Cemre Feb 22 '12 at 18:33
The easiest way is to include the argument lb initialized to all zeros (look at the documentation I linked to). –  Chris Taylor Feb 22 '12 at 18:42