why doesn't the gamultiobj function give me the output of the algorithm?

5 次查看(过去 30 天)
Hi, I did this optimization by means of the gamultiobj function, but, the output argument, does not give me any information of the number of generations or iterations of the algorithm.
I have tried several methods, but none of them gives me this information, does anyone have any idea how to know this information?
format long g
filename = 'Returns.xlsx';
data = readmatrix(filename);
nAssets = size(data, 2);
%Returns and covariance
mu = mean(data);
mu
sigma = cov(data);
%formulate the problem/optimization
A = -eye(nAssets);
b = zeros(nAssets, 1);
Aeq = ones(1, nAssets) ;
beq = 1 ;
%solve the optimization
fcn = @(w)MultipleMax(w,mu,sigma);
[w,fval,exitflag,output,population,scores] = gamultiobj(fcn, nAssets, A, b, Aeq, beq);
if isempty(w)
warning('could not find any solution')
else
Risk=sqrt(sum( (w*sigma).*w ,2));
Ret=w*mu';
%print the solution
T=table(Risk,Ret,w,'Var',{'Risk', 'Ret','Pesos'})
end
writetable(T,'45.csv');
function f = MultipleMax(w,mu,sigma)
f(1) = -(w * mu');
f(2) = (sqrt(w*sigma*w'));
end

回答(1 个)

Alan Weiss
Alan Weiss 2022-9-1
Your script worked for me. I attach the result. Using these commands, I also got a plot of the Pareto front.
opts = optimoptions("gamultiobj",PlotFcn="gaplotpareto");
[w,fval,exitflag,output,population,scores] = gamultiobj(fcn, nAssets, A, b, Aeq, beq,[],[],[],opts);
You see that there were 142 generations (iterations) and 28,400 function evaluations.
Alan Weiss
MATLAB mathematical toolbox documentation

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by