Using Matlab quadprog to solve markowitz model

7k Views Asked by At

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 enter image description here

2

There are 2 best solutions below

2
On BEST ANSWER

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)
0
On

I know this answer is about 9 years late but according to quadprog documentation, this is what you need to do if you want to have no short selling (all weights >=0) otherwise, just remove lb and ub from the following code:

H = sigma
f = zeros(n,1)
Aeq = [ones(1,n); r']
beq = [1 r_target]
lb = zeros(n,1)
ub = ones(n,1)

w=quadprog(H , f , [] , [] , Aeq , beq , lb ,ub)