rolling optimization with nonlinear constraints

조회 수: 2 (최근 30일)
Peihong
Peihong 2013년 4월 26일
Hi,friends, I recently encountered one problem and tried many times without success, is there anyone who can give me some hints, thanks in adance. here is the question:
I want to solve a optimization with nonlinear constraints, the difficulty lies that I want to solve it with a rolling window, say, using the first 60 datapoints to derive a solution, and then, using the second to 61 datapoints to derive the second solution, etc.
the code is:
MyCov=cell(NofRepetitions,1);%cell array
W=cell(NofRepetitions,1);%cell array
dMean=cell(NofRepetitions,1);
EndIndx=RollingWindow;
eMean=cell(1,NofRepetitions);
for i=1:NofRepetitions;
%calculating mean of each repetition
eMean{i}=(RetSeries(i:EndIndx+i-1,:)'*P)';
%calculating the deviation of each repetition
dMean{i}=RetSeries(i:EndIndx+i-1,:)-repmat(eMean{i},RollingWindow,1);
%calculating covariance
MyCov{i}=dMean{i}'*diag(P)*dMean{i};
end
RiskTarget=0.1/sqrt(12);% SETTING RISK TARGET.......REVISABLE
RiskMultiple=ones(c,1)/c;%
%RiskMultiple=[0.2 0.2 0.1]';%suppose 3 assets here
w0=ones(c,1)/c;
options=optimset('Algorithm','interior-point','LargeScale','off');
A=ones(c,1)';
b=1;% LEVERAGE CONSTRAINT
W=fmincon(@(W)-1*RiskMultiple'*log(W),w0,A,b,[],[],zeros(c,1),[],@(W)deal(W'*MyCov*W-RiskTarget^2),[],options);
but after I run the code, it returns error message,
"Error using @(W)-1*RiskMultiple'*log(W)
Too many input arguments.
Error in fmincon (line 601)
initVals.f = feval(funfcn{3},X,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation. FMINCON cannot continue."
any friend can give me some hints? thanks a lot

채택된 답변

Alan Weiss
Alan Weiss 2013년 4월 29일
You seem to have a syntax error in your nonlinear constraint:
W=fmincon(@(W)-1*RiskMultiple'*log(W),w0,A,b,[],[],zeros(c,1),[],@(W)deal(W'*MyCov*W-RiskTarget^2),[],options);
I think this should be
W=fmincon(@(W)-1*RiskMultiple'*log(W),w0,A,b,[],[],zeros(c,1),[],@(W)deal(W'*MyCov*W-RiskTarget^2,[]),options);
In any case, it would be easier to read and debug if you wrote it as
nonlcon = @(W)deal(W'*MyCov*W-RiskTarget^2,[]);
But fmincon is complaining that your objective function is not well defined at the initial point. Try running
fcn = @(W)-1*RiskMultiple'*log(W)
fval = fcn(w0)
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

추가 답변 (2개)

Peihong
Peihong 2013년 4월 29일
Hi Alan, thanks for pointing out the error in nonlinear constraints, I tried, it shows that the problem lies in objective function, matlab reports following message after running codes:
Warning: The default trust-region-reflective algorithm does not solve problems with the constraints you have specified. FMINCON will use the active-set algorithm instead. For information on applicable algorithms, see Choosing the Algorithm in the documentation. > In fmincon at 486 Error using @(W)-1*RiskMultiple'*log(W) Too many input arguments.
Error in fmincon (line 601) initVals.f = feval(funfcn{3},X,varargin{:});
Caused by: Failure in initial user-supplied objective function evaluation. FMINCON cannot continue.
I don't know why it returns "too many input arguments" for the objective function, would you please have a look, thanks
  댓글 수: 2
Alan Weiss
Alan Weiss 2013년 4월 30일
Please let me know the result of the test I asked you to run previously:
fcn = @(W)-1*RiskMultiple'*log(W)
fval = fcn(w0)
Alan Weiss
MATLAB mathematical toolbox documentation
Matt J
Matt J 2013년 4월 30일
편집: Matt J 2013년 4월 30일
You still haven't corrected the syntax error in your call to FMINCON that Alan mentioned. Please show your call to FMINCON so that we can see what you are now doing.
It is clear from the messages that you're not calling FMINCON with the correct number/order of input arguments, because
(1) FMINCON does not see your "options" input and is therefore not using the interior-point algorithm as you specified, but rather the default trust-region alg.
(2) FMINCON still thinks you are passing it more than 10 arguments. It is therefore passing the 11th (probably your options struct) and higher argument as extra parameters to the objective function, which the objective cannot accept because it is only written to accept a single input arg 'W'. Hence the "too many input arguments" error message.

댓글을 달려면 로그인하십시오.


Peihong
Peihong 2013년 5월 4일
Thanks, friends, I tried again by correcting the syntax error, it works. thanks.

카테고리

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