Solver stopped prematurely. fmincon stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 3.000000e+03.
21 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ylenia Placella
le 1 Déc 2020
Commenté : Ylenia Placella
le 7 Déc 2020
%constraints c, ceq
% size(D)=[69,69]
%size(sigma)=[69,69]
%length(h)=50
function[c,ceq]= nlcon (x)
load ('workspacefmincon.mat','n','sigma','D','h','h_min','h_max');
n=length(D);
x=zeros(1,n);
h=linspace(h_min,h_max,50);
for i=1:length(h)
c(i)=h(i)-(x*D*x');
ceq=[];
end
%optimization
x=zeros(1,n);
h=linspace(h_min,h_max,50);
fun=@(x) x*sigma*x';
x_rao=zeros(1,n);
x0_rao=zeros(1,n);
A_rao=[];
b_rao=[];
Aeq_rao=ones(length(h),n);
beq_rao=ones(length(h),1);
l_b_rao=zeros(1,n);
u_b_rao=ones(1,n);
risk_rao = zeros(1,n);
risk_rao = var_min;
constr=@nlcon;
[x_rao, risk_rao]=fmincon(fun,x0_rao,A_rao,b_rao,Aeq_rao,beq_rao,l_b_rao,u_b_rao,constr);
% If I add options, the problem is the same
% options = optimoptions('fmincon','Display','iter','Algorithm','sqp');
0 commentaires
Réponse acceptée
Stephan
le 1 Déc 2020
You have to give the options to the solver and to insert the MaxFunctionEvaluations Option into the optimoptions struct:
MyValue = 10e4;
options = optimoptions('fmincon','Display','iter','Algorithm','sqp', 'MaxFunctionEvaluations',MyValue);
[x_rao, risk_rao]=fmincon(fun,x0_rao,A_rao,b_rao,Aeq_rao,beq_rao,l_b_rao,u_b_rao,constr,options);
9 commentaires
Stephan
le 1 Déc 2020
Modifié(e) : Stephan
le 1 Déc 2020
This appears to work - i ran it as 1 script:
index=xlsread('C:\Users\desyp\Desktop\Tesi finass\NASDAQ100.xlsx');
P = index;
RR = diff(P)./P(1:end-1,:);
sigma=cov(RR);
rho=corrcoef(RR);
mu=mean(RR);
n=length(mu);
D=1-rho;
H=2*D;
f=zeros(n,1);
Aeq=ones(1,n);
beq=1;
l_b=zeros(1,n);
x0 = rand(1,n);
options=optimoptions('quadprog','algorithm','active-set','MaxIter',1.e7,...
'TolFun',1.e-10,'TolX',1.e-10);
[x_h_min,var_min]=quadprog(H,f,[],[],Aeq,beq,l_b,[],x0,options);
sum_xhmin=sum(x_h_min);
x_hmin_unit=x_h_min/sum_xhmin;
h_min=x_hmin_unit'*D*x_hmin_unit;
[x_h_max,var_max]=quadprog(-H,f,[],[],Aeq,beq,l_b,[],x0,options);
sum_xhmax=sum(x_h_max);
x_hmax_unit=x_h_max/sum_xhmax;
h_max=x_hmax_unit'*D*x_hmax_unit;
h=linspace(h_min,h_max,50);
%% optimization
fun=@(x) x*sigma*x';
x0_rao=rand(1,n);
A_rao=[];
b_rao=[];
Aeq_rao=ones(1,n);
beq_rao=1;
l_b_rao=-zeros(1,n);
u_b_rao=ones(1,n);
constr=@(x)nlcon(x,D,h_max);
opts = optimoptions('fmincon','Display','final-detailed','Algorithm','sqp',...
'MaxFunctionEvaluations', 5e4,'MaxIterations',5e3,'ConstraintTolerance',...
1e-6);
[x_rao, risk_rao,exitflag,output]=fmincon(fun,x0_rao,A_rao,b_rao,Aeq_rao,...
beq_rao,l_b_rao,u_b_rao,constr,opts)
function[c,ceq]= nlcon(x,D,h_max)
c=h_max-(x*D*x');
ceq=[];
end
But there is still a warning on the first call of quadprog, that the problem is non-convex. Also note that i assumed that my conclusion regarding the nonlinear constraint function is correct. You have to check if that can be correct.
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!