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

4 ビュー (過去 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 Center および File ExchangeOptimization Toolbox についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by