Cannot debug the optimizer

Hi All,
I have written the following code
% Optimize EMBI Global Diversified BM
clear all;
clc;
[~,~,raw] = xlsread('U:\Matlab\SolverError.xlsx');
countryArray = raw(2:end,3:3);
isinArray =raw(2:end,1:1);
qtdPerformance = raw(2:end,17:17);
isinWeight = raw(2:end,13:13);
countryFilter = unique(countryArray);
A = zeros(size(isinArray));
v(1:120) = -1; %%min number of securities
A = diag(v);
pad = zeros(120,size(isinArray,1)-120); %%Atleast first 120 securities have non-zero value
A = horzcat(A,pad);
a = zeros(size(A),1);
c = cell2mat(qtdPerformance);
for i = 0:size(countryFilter)-1
evalStmt = sprintf('x%s = double(strcmp(countryArray,countryFilter(%s)));',num2str(i+1),num2str(i+1));
evalStmt2 = sprintf('A = vertcat(A,x%s'');',num2str(i+1));
countryWeight = sum(cell2mat(isinWeight(strcmp(countryArray,countryFilter(i+1))))) ;
if countryWeight > 0.035
targetWeight = countryWeight + 0.05;
else
targetWeight = countryWeight + 0.03;
end
evalStmt3 = sprintf('a(%s) = targetWeight;',num2str(i+120+1));
%%disp(evalStmt);
eval(evalStmt);
%%disp(evalStmt2);
eval(evalStmt2);
%%disp(evalStmt3);
eval(evalStmt3);
end %%end for loop
disp(evalStmt);
A = vertcat(A,ones(1,size(isinArray)));
a(size(A,1))=1; %%sum of all countries should be 100 percent
lb = zeros(size(A,1),1);
ub = 0.02 * ones(size(A,1),1);
[xsol,fval,flag,output,lagMult] = linprog(c,A,a,[],[],lb,ub);
to optimize the weights of instruments in a portfolio. I get the following error after 37 iterations
Exiting: One or more of the residuals, duality gap, or total relative error has grown 100000 times greater than its minimum value so far: the dual appears to be infeasible and the primal unbounded since the primal objective < -1e+10 and the dual objective < 1e+6.
The linear program I am trying to solve is
I have a list of securities sorted by performance. I want to use this list to create an optimal portfolio.
sum of all weights < = 100% each security between 0 and 2% Atleast first 120 securities have non-zero value Atleast first 120 securities should have non zero weights Securities belonging to one country are restricted by upper limit and positive numbers.
Can someone please help me out and let me know how should I go about debugging this ?
Regards, Abhishek

3 comentarios

Matt J
Matt J el 19 de Feb. de 2013
Editada: Matt J el 19 de Feb. de 2013
Please use the "{} Code" toolbar icon to make your code readable
Abhishek BANERJEE
Abhishek BANERJEE el 19 de Feb. de 2013
Hi Matt, I just used the code toolbar. Can you please check now ?
Abhishek BANERJEE
Abhishek BANERJEE el 19 de Feb. de 2013
I think the answer partly lies in this link I posted before ... http://www.mathworks.nl/matlabcentral/answers/63929#comment_130849

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Portfolio Optimization and Asset Allocation en Centro de ayuda y File Exchange.

Preguntada:

el 19 de Feb. de 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by