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

1 view (last 30 days)
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

Answers (1)

Alan Weiss
Alan Weiss on 1 Sep 2022
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

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!