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

조회 수: 5 (최근 30일)
Santiago
Santiago 2022년 8월 31일
답변: Alan Weiss 2022년 9월 1일
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에서 Optimization Toolbox에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by