Portfolio Optimisation using a mean/ mean absolute deviation model (linear program)
Hey everybody,
I am new to Matlab. I have recently used quadprog for the standard mean-variance model to optimise a portfolio.
I want to try several models and am currently trying to model the linear program -> mean / mean absolute deviation.
Mathematically speaking :
[URL=http://www.pic-upload.de/view-20298258/Screen-Shot-2013-08-05-at-01.05.47.png.html][IMG]http://www10.pic-upload.de/thumb/05.08.13/3hz1okoiiv24.png[/IMG][/URL]
in case that didn’t work :
http://www.pic-upload.de/view-20298258/Screen-Shot-2013-08-05-at-01.05.47.png.html
S = 872 observations I have for 9 stocks.
delta is the target return.
% This script will calculate and plot the efficient frontier for a
% mean – mean absolute deviation model in the Konno context.
% Take sample ‘Sample’ and calculate the mad -> transpose PeriodMAD
% and store variable in the workspace
PeriodMAD = mad(Sample);
PeriodMAD = PeriodMAD’;
assignin(‘base’,’PeriodMAD’,PeriodMAD);
% get number of Assets ( i am using 9 stocks)
nAssets = numel(PeriodMAD);
% Set the first targetreturn
targetreturn = 0.000001;
% Not sure if that is right -> allow none of the MAD values to lower than
% 0
nonnegativityMAD = zeros(nAssets, 1);
% Conformity with the linproq notation
f = PeriodMAD;
% Set some restrictions -> as shown in the graphic I have provided. NOt
% sure if I set them up correctly to be honest.
% PeriodDeviations includes nothing more than Observation at time(i) –
% mean of the asset (PeriodDeviations -> (9,1) vector)
% PeriodReturns -> ln returns for the observations 782 -> vector (9,1)
Aeq = [ PeriodDeviations
-PeriodDeviations
-PeriodMAD
-PeriodReturns ];
Beq = [ PeriodMAD
-PeriodMAD
nonnegativityMAD
-targetreturn];
% Set lower and upper boundaries for the weights -> 0<= x <= 1
lb = zeros(nAssets,1);
ub = ones(nAssets, 1);
% Copied that line from the quadprog example given on the internet
% changed interior-point-convex to interior-point
options = optimset(‘Algorithm’,’interior-point’);
options = optimset(options,’Display’,’iter’,’TolFun’,1e-10);
for i=1:100000;
x = linprog ( f,[],[],Aeq,Beq,lb,ub,[], options );
% Not sure if that is correct. Store respective mean in Output(1,i)
% do the same for the portfolio MAD -> is that correct?
% This is a modified "Sharpe- Ratio" or Konno Ratio. the quotient of
% the former two variables
% Finally store the weights x in Output as well -> 9 variables
% therefore Output(5,i) to Output(13,i)
Output(1,i) = x’ * PeriodReturns;
Output(2,i) = x’ * PeriodMAD;
Output(3,i) = (Output(1,i)/Output(2,i));
Output(5,i) = x(1,1);
Output(6,i) = x(2,1);
Output(7,i) = x(3,1);
Output(8,i) = x(4,1);
Output(9,i) = x(5,1);
Output(10,i) = x(6,1);
Output(11,i) = x(7,1);
Output(12,i) = x(8,1);
Output(13,i) = x(9,1);
% now increment targetreturn -> repeat the entire process as long as
% linprog finds a solutions (converges to a solution) otherwise
% stop/break
targetreturn = targetreturn + 0.000001;
if(exitflag == 1)
continue
else
break
end
end
% Find highest KonnoRatio – Quotient of Returns/Risk stored as
% maxKonnoRatio then find position in Output
maxKonnoRatio = max(Output(3,:));
[row col] = find(maxKonnoRatio == Output(3,:));
% finally create and display an array that contains all the information
% for the optimal allocation.
OptimalAll = [ Output(1,col)
Output(2,col)
Output(3,col)
0
Output(5,col)
Output(6,col)
Output(7,col)
Output(8,col)
Output(9,col) ]
% and hopefully draw the efficient frontier
plot(Output(2,i),Output(1,i))
I am stuck. I have modified so much stuff already and I keep getting error messages. currently this is the most recent one :
EDU>> MAD
Error using linprog (line 231)
The number of rows in Aeq must be the same as the number of elements of beq.
Error in MAD (line 37)
x = linprog ( f,[],[],Aeq,Beq,lb,ub,[], options );
EDU>> MAD
Error: File: MAD.m Line: 108 Column: 32
Unbalanced or unexpected parenthesis or bracket.
EDU>>
if you could please help me.
Am I at least close to a proper solution ?
Btw. : I will annualise those daily data observations – as soon as I can solve the basic problem.
I would be very grateful for some advice and/or help.
Thank you so much!
DanielHey everybody,
I am new to Matlab. I have recently used quadprog for the standard mean-variance model to optimise a portfolio.
I want to try several models and am currently trying to model the linear program -> mean / mean absolute deviation.
Mathematically speaking :
[URL=http://www.pic-upload.de/view-20298258/Screen-Shot-2013-08-05-at-01.05.47.png.html][IMG]http://www10.pic-upload.de/thumb/05.08.13/3hz1okoiiv24.png[/IMG][/URL]
in case that didn’t work :
http://www.pic-upload.de/view-20298258/Screen-Shot-2013-08-05-at-01.05.47.png.html
S = 872 observations I have for 9 stocks.
delta is the target return.
% This script will calculate and plot the efficient frontier for a
% mean – mean absolute deviation model in the Konno context.
% Take sample ‘Sample’ and calculate the mad -> transpose PeriodMAD
% and store variable in the workspace
PeriodMAD = mad(Sample);
PeriodMAD = PeriodMAD’;
assignin(‘base’,’PeriodMAD’,PeriodMAD);
% get number of Assets ( i am using 9 stocks)
nAssets = numel(PeriodMAD);
% Set the first targetreturn
targetreturn = 0.000001;
% Not sure if that is right -> allow none of the MAD values to lower than
% 0
nonnegativityMAD = zeros(nAssets, 1);
% Conformity with the linproq notation
f = PeriodMAD;
% Set some restrictions -> as shown in the graphic I have provided. NOt
% sure if I set them up correctly to be honest.
% PeriodDeviations includes nothing more than Observation at time(i) –
% mean of the asset (PeriodDeviations -> (9,1) vector)
% PeriodReturns -> ln returns for the observations 782 -> vector (9,1)
Aeq = [ PeriodDeviations
-PeriodDeviations
-PeriodMAD
-PeriodReturns ];
Beq = [ PeriodMAD
-PeriodMAD
nonnegativityMAD
-targetreturn];
% Set lower and upper boundaries for the weights -> 0<= x <= 1
lb = zeros(nAssets,1);
ub = ones(nAssets, 1);
% Copied that line from the quadprog example given on the internet
% changed interior-point-convex to interior-point
options = optimset(‘Algorithm’,’interior-point’);
options = optimset(options,’Display’,’iter’,’TolFun’,1e-10);
for i=1:100000;
x = linprog ( f,[],[],Aeq,Beq,lb,ub,[], options );
% Not sure if that is correct. Store respective mean in Output(1,i)
% do the same for the portfolio MAD -> is that correct?
% This is a modified "Sharpe- Ratio" or Konno Ratio. the quotient of
% the former two variables
% Finally store the weights x in Output as well -> 9 variables
% therefore Output(5,i) to Output(13,i)
Output(1,i) = x’ * PeriodReturns;
Output(2,i) = x’ * PeriodMAD;
Output(3,i) = (Output(1,i)/Output(2,i));
Output(5,i) = x(1,1);
Output(6,i) = x(2,1);
Output(7,i) = x(3,1);
Output(8,i) = x(4,1);
Output(9,i) = x(5,1);
Output(10,i) = x(6,1);
Output(11,i) = x(7,1);
Output(12,i) = x(8,1);
Output(13,i) = x(9,1);
% now increment targetreturn -> repeat the entire process as long as
% linprog finds a solutions (converges to a solution) otherwise
% stop/break
targetreturn = targetreturn + 0.000001;
if(exitflag == 1)
continue
else
break
end
end
% Find highest KonnoRatio – Quotient of Returns/Risk stored as
% maxKonnoRatio then find position in Output
maxKonnoRatio = max(Output(3,:));
[row col] = find(maxKonnoRatio == Output(3,:));
% finally create and display an array that contains all the information
% for the optimal allocation.
OptimalAll = [ Output(1,col)
Output(2,col)
Output(3,col)
0
Output(5,col)
Output(6,col)
Output(7,col)
Output(8,col)
Output(9,col) ]
% and hopefully draw the efficient frontier
plot(Output(2,i),Output(1,i))
I am stuck. I have modified so much stuff already and I keep getting error messages. currently this is the most recent one :
EDU>> MAD
Error using linprog (line 231)
The number of rows in Aeq must be the same as the number of elements of beq.
Error in MAD (line 37)
x = linprog ( f,[],[],Aeq,Beq,lb,ub,[], options );
EDU>> MAD
Error: File: MAD.m Line: 108 Column: 32
Unbalanced or unexpected parenthesis or bracket.
EDU>>
if you could please help me.
Am I at least close to a proper solution ?
Btw. : I will annualise those daily data observations – as soon as I can solve the basic problem.
I would be very grateful for some advice and/or help.
Thank you so much!
Daniel Hey everybody,
I am new to Matlab. I have recently used quadprog for the standard mean-variance model to optimise a portfolio.
I want to try several models and am currently trying to model the linear program -> mean / mean absolute deviation.
Mathematically speaking :
[URL=http://www.pic-upload.de/view-20298258/Screen-Shot-2013-08-05-at-01.05.47.png.html][IMG]http://www10.pic-upload.de/thumb/05.08.13/3hz1okoiiv24.png[/IMG][/URL]
in case that didn’t work :
http://www.pic-upload.de/view-20298258/Screen-Shot-2013-08-05-at-01.05.47.png.html
S = 872 observations I have for 9 stocks.
delta is the target return.
% This script will calculate and plot the efficient frontier for a
% mean – mean absolute deviation model in the Konno context.
% Take sample ‘Sample’ and calculate the mad -> transpose PeriodMAD
% and store variable in the workspace
PeriodMAD = mad(Sample);
PeriodMAD = PeriodMAD’;
assignin(‘base’,’PeriodMAD’,PeriodMAD);
% get number of Assets ( i am using 9 stocks)
nAssets = numel(PeriodMAD);
% Set the first targetreturn
targetreturn = 0.000001;
% Not sure if that is right -> allow none of the MAD values to lower than
% 0
nonnegativityMAD = zeros(nAssets, 1);
% Conformity with the linproq notation
f = PeriodMAD;
% Set some restrictions -> as shown in the graphic I have provided. NOt
% sure if I set them up correctly to be honest.
% PeriodDeviations includes nothing more than Observation at time(i) –
% mean of the asset (PeriodDeviations -> (9,1) vector)
% PeriodReturns -> ln returns for the observations 782 -> vector (9,1)
Aeq = [ PeriodDeviations
-PeriodDeviations
-PeriodMAD
-PeriodReturns ];
Beq = [ PeriodMAD
-PeriodMAD
nonnegativityMAD
-targetreturn];
% Set lower and upper boundaries for the weights -> 0<= x <= 1
lb = zeros(nAssets,1);
ub = ones(nAssets, 1);
% Copied that line from the quadprog example given on the internet
% changed interior-point-convex to interior-point
options = optimset(‘Algorithm’,’interior-point’);
options = optimset(options,’Display’,’iter’,’TolFun’,1e-10);
for i=1:100000;
x = linprog ( f,[],[],Aeq,Beq,lb,ub,[], options );
% Not sure if that is correct. Store respective mean in Output(1,i)
% do the same for the portfolio MAD -> is that correct?
% This is a modified "Sharpe- Ratio" or Konno Ratio. the quotient of
% the former two variables
% Finally store the weights x in Output as well -> 9 variables
% therefore Output(5,i) to Output(13,i)
Output(1,i) = x’ * PeriodReturns;
Output(2,i) = x’ * PeriodMAD;
Output(3,i) = (Output(1,i)/Output(2,i));
Output(5,i) = x(1,1);
Output(6,i) = x(2,1);
Output(7,i) = x(3,1);
Output(8,i) = x(4,1);
Output(9,i) = x(5,1);
Output(10,i) = x(6,1);
Output(11,i) = x(7,1);
Output(12,i) = x(8,1);
Output(13,i) = x(9,1);
% now increment targetreturn -> repeat the entire process as long as
% linprog finds a solutions (converges to a solution) otherwise
% stop/break
targetreturn = targetreturn + 0.000001;
if(exitflag == 1)
continue
else
break
end
end
% Find highest KonnoRatio – Quotient of Returns/Risk stored as
% maxKonnoRatio then find position in Output
maxKonnoRatio = max(Output(3,:));
[row col] = find(maxKonnoRatio == Output(3,:));
% finally create and display an array that contains all the information
% for the optimal allocation.
OptimalAll = [ Output(1,col)
Output(2,col)
Output(3,col)
0
Output(5,col)
Output(6,col)
Output(7,col)
Output(8,col)
Output(9,col) ]
% and hopefully draw the efficient frontier
plot(Output(2,i),Output(1,i))
I am stuck. I have modified so much stuff already and I keep getting error messages. currently this is the most recent one :
EDU>> MAD
Error using linprog (line 231)
The number of rows in Aeq must be the same as the number of elements of beq.
Error in MAD (line 37)
x = linprog ( f,[],[],Aeq,Beq,lb,ub,[], options );
EDU>> MAD
Error: File: MAD.m Line: 108 Column: 32
Unbalanced or unexpected parenthesis or bracket.
EDU>>
if you could please help me.
Am I at least close to a proper solution ?
Btw. : I will annualise those daily data observations – as soon as I can solve the basic problem.
I would be very grateful for some advice and/or help.
Thank you so much!
Daniel optimisation, portfolio, mad, linear, finance MATLAB Answers — New Questions