Run the same fmincon multiple times

조회 수: 6 (최근 30일)
Markus
Markus 2015년 3월 27일
편집: Markus 2015년 3월 27일
Hey everybody, i want to minimze a risk measure (CVaR), the input is a return matrix. The Solution works if i determine the return matrix. My aim is though to run this problem 145 times with 145 different return matrixes, saved in returns {i}. So i thought i just make a 145x objfun{i} cell and so a 145x problem {i} cell, which also works. But the last command "w{i}= run(gs,problem{i})" gives several errors:
Subscript indices must either be real positive integers or logicals.
Error in @(w)CVaR(w,returns{i},conflevel)
Error in fmincon (line 635) initVals.f = feval(funfcn{3},X,varargin{:});
Error in C:\Program Files\MATLAB\R2013a\toolbox\globaloptim\globaloptim\private\globalsearchnlp.p>globalsearchnlp (line 155)
Error in GlobalSearch/run (line 336) [x,fval,exitflag,output] = ...
Caused by: Failure in initial user-supplied objective function evaluation. FMINCON cannot continue. Failure in initial call to fmincon with user-supplied problem structure.
Code:
if true
tf = 3
N = 10000
problem = cell(tf,1)
w = cell(tf,1)
CVaR = cell(tf,1)
objfun = cell(tf,1)
A = cell(tf, 1)
for i = 1:tf
conflevel=0.05; %conf.level
R0=0.0085; %target return
objfun{i}=@(w) CVaR(w,returns{i},conflevel)
w0=[(1/nAss)*ones(1,nAss)]';
%Constrains
A{i}=[-((sum(returns{i}))/N)];
b=[-R0];
b=b';
Aeq=[ ones(1,nAss)];
beq=[1];
lb=[zeros(nAss,1)]
ub=[ones(nAss,1)]
opts = optimoptions(@fmincon,'Algorithm','interior-point', 'Display', 'off');
problem{i} = createOptimProblem('fmincon','x0',w0,'objective',objfun{i},'Aineq',A{i},'bineq',b,'Aeq',Aeq,'beq',beq,'lb',lb,'ub',ub,'options',opts)
gs = GlobalSearch
end
for i = 1:tf
w{i}= run(gs,problem{i})
end
end

답변 (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