Few questions regarding optimization using fmincon (EXITFLAG = 5 or 0)

2 次查看(过去 30 天)
Hi MATLAB Experts,
I have some issues with my optimization code. The objective function that I've made is to minimize the trades that can satisfy assigned turnover limits (i.e. 2%).
The objective function that will need to run with fmincon is below.
function [c,ceq] = conTO(x,D,C,sglTotTurn)
c = (sum(abs(D+x-C))/2 - sglTotTurn);
ceq = [];
end
%%Optimization
diff = currentportfolio_A - modelportfolio_A; % difference in weights between modelportfolio_A and currentportfolio_A
TotTurn = 0.02; % set Turnover limit to 2%
fullexec = [20;30;40]; % fund funds that have to be fully executed
% 1st constraint: Full implementation on desired portfolio
lb = zeros(size(diff,1),1); ub = zeros(size(diff,1),1);
lb(diff<0,1) = diff(diff<0,1);
ub(diff>0,1) = diff(diff>0,1);
lb(fullexec,1) = 0; ub(fullexec,1) = 0;
% linear inequality
A=[]; b=[];
% linear equality
Aeq = ones(size(diff,1),1)';
beq = 0;
% find trades
desired_w = modelportfolio_A;
current_w = currentportfolio_A;
[trades,FVAL,EXITFLAG] = fmincon(@(x)std(x), diff, A, b, Aeq, beq, lb, ub, @(x) conTO(x,desired_w,current_w,TotTurn));
fval_1 = FVAL;
flag_1 = EXITFLAG;
actual_w = desired_w + trades; % actual weight
However, after running this script, I found that "fmincon stopped because the predicted change in the objective function is less than the default value of the function tolerance and constraints are satisfied to within the default value of the constraint tolerance."
Every time I run the script, flag_1 is '5' or '0'. I think the default value is already very tiny.. So, I don't think the predicted change in the objective function is less than the default value as mentioned..
Could you please give me some advise to improve the model? Please let me know if I miss anything important.
Thanks for any help you could provide in advance!!
Best Regards,
Jake

采纳的回答

Walter Roberson
Walter Roberson 2016-4-7
I recommend you pass an options structure that changes the tolerances that you feel are better suited.
  3 个评论
Alan Weiss
Alan Weiss 2016-4-7
Take a look at the documentation. It won't take more than 20 minutes or so to read through the first five topics. Then you'll be well-versed in setting options.
Alan Weiss
MATLAB mathematical toolbox documentation

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by