Originally posted by: Bellilein
Hi,
I'm trying to do the same. I don't know how to get the cardinality constrained efficient frontier (CCEF) like in the attached picture, which is plotted by the same data. I would really appreciate it if you could help me with that! Thanks in advance!
numx=4;
sigma=[1 0.118368 0.143822 0.252213 0 0 0 0;
0.118368 1 0.164589 0.099763 0 0 0 0;
0.143822 0.164589 1 0.083122 0 0 0 0;
0.252213 0.099763 0.083122 1 0 0 0 0;
];
K = 2;
mu=[0.004798
0.000659
0.003174
0.001377];
l=0.1*ones(1,numx);
u=ones(1,numx);
rhomin=0.0025;
rhomax=0.0045;
anzPlots=100;
rhovec=0:(anzPlots-1);
rhovec=rhomin*ones(1,anzPlots)+rhovec*(rhomax-rhomin)/(anzPlots-1);
rvvec=zeros(1,anzPlots);
i=1;
exitflag=1;
while i<anzPlots && exitflag==1
rho=rhovec(i);
Aineq=[ -eye(numx),diag(l);
eye(numx),-diag(u)
];
bineq=[0;0;0;0;0;0;0;0
];
Aeq=[mu',zeros(1,numx);
ones(1,numx),zeros(1,numx);
zeros(1,numx),ones(1,numx);
];
beq=[rho;
1;
K;
];
lb=[0; 0; 0; 0; 0; 0; 0; 0];
ub=[1;1;1;1;1;1;1;1];
ctype= 'CCCCBBBB'
[x, fval, exitflag, output] = cplexmiqp (2*sigma,zeros(1,2*numx),Aineq,bineq,Aeq,beq,[],[],[],lb,ub,ctype);
fprintf ('\nSolution status = %s \n', output.cplexstatusstring);
fprintf ('Solution value = %f \n', fval);
disp ('Values Wallieus =');
disp (x');
disp (rho);
rvvec(i)=sqrt(fval);
i=i+1;
end
plot(rvvec(1:i-1),rhovec(1:i-1))
#CPLEXOptimizers#DecisionOptimization