Mean Variance optimization with FMINCON

  • Follow


Hi All, 
I have just started with Matlab, and struggle with the following problem -
 optimization of 3-assets portfolio:

ExpRet = [0.1  0.2  0.15];
ExpCov = [0.005  -0.010  0.004;  -0.010  0.040  -0.002;  0.004  -0.002  0.023];

%My goal is to minimize the function for portfolio variance (saved in Weights.m):
function [Weights] = f(w,ExpCov)
Weights = w'*ExpCov*w
%I believe my problem lies in the objective function

%Given:
ExpRet = [0.1  0.2  0.15];
ExpCov = [0.005  -0.010  0.004;  -0.010  0.040  -0.002;  0.004  -0.002  0.023];
TargetReturn=0.15;
X0=zeros(3,1);
Aeq = [ExpRet;ones(1,3)];
Beq = [TargetReturn;1];
LB = zeros(3,1); 
UB = ones(3,1); 

[OptimalWeights, OptimalVariance] = fmincon(@Weights,X0,[],[],Aeq,Beq,LB,UB);

I would be extremely grateful for your insight. 
0
Reply ADam 1/25/2010 10:27:05 PM

ADam Skoczynski wrote:
> Hi All, I have just started with Matlab, and struggle with the following 
> problem -
> optimization of 3-assets portfolio:
> 
> ExpRet = [0.1  0.2  0.15];
> ExpCov = [0.005  -0.010  0.004;  -0.010  0.040  -0.002;  0.004  -0.002  
> 0.023];
> 
> %My goal is to minimize the function for portfolio variance (saved in 
> Weights.m):
> function [Weights] = f(w,ExpCov)
> Weights = w'*ExpCov*w
> %I believe my problem lies in the objective function
> 
> %Given:
> ExpRet = [0.1  0.2  0.15];
> ExpCov = [0.005  -0.010  0.004;  -0.010  0.040  -0.002;  0.004  -0.002  
> 0.023];
> TargetReturn=0.15;
> X0=zeros(3,1);
> Aeq = [ExpRet;ones(1,3)];
> Beq = [TargetReturn;1];
> LB = zeros(3,1); UB = ones(3,1);
> [OptimalWeights, OptimalVariance] = 
> fmincon(@Weights,X0,[],[],Aeq,Beq,LB,UB);
> 
> I would be extremely grateful for your insight.
There are several answers to your question.
1. You are correct in believing you did not write the objective function 
correctly. Take a look at the documentation, or at least an example 
where it is done correctly.
http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/brhkghv-3.html
http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/brn4nh7.html
To pass the ExpCov parameters, see
http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/brhkghv-7.html
1a. Short answer:
Weights = @(w)w'*ExpCov*w;
Pass this form of the function without an @ sign (I mean the syntax is 
fmincon(Weights,X0,...))
2. You should probably use quadprog instead of fmincon:
http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/brhkghv-18.html#brhkghv-19

Good luck,

Alan Weiss
MATLAB mathematical toolbox documentation
0
Reply Alan 1/26/2010 12:55:31 PM


1 Replies
1353 Views

(page loaded in 0.028 seconds)

Similiar Articles:













7/23/2012 4:15:29 AM


Reply: