Wednesday, November 9, 2011

Sharpe Ratio optimization with Matlab 2007a

Blank
Never versions of Matlab has this feature built in but for the people still on the old version may help. 

 

[w,fval] = fmincon(@(w) -w'*r/sqrt(w'*c*w),ones(N,1)/,-eye(N),zeros(N,1),ones(1,N),1);

 

objective term: -w'*r/sqrt(w'*c*w)   is the formulation of Sharpe Ratio, where r is the excess return vector, c is the covariance matrix,and w is the security weights we're optimizing. Since it's a minimization algorithm we have to negate it.

 

N is the dimension of the problem where c and r dimensions need to match.

initial value: ones(3,1)/3 to start the search

long only constraint:   Aw ≤ b   where A=-eye(3), b=zeros(3,1) which becomes w ≥ 0

budget constraint: Aw=b  where A=[1 1 ... 1], b=1 which becomes ∑wi = 1

 

the outputs are the weights and the optimal function value at these weights.

 

 

 

No comments: