rolling optimization with nonlinear constraints

1 view (last 30 days)
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

Accepted Answer

Alan Weiss
Alan Weiss on 29 Apr 2013
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

More Answers (2)

Peihong
Peihong on 29 Apr 2013
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 Comments
Alan Weiss
Alan Weiss on 30 Apr 2013
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 on 30 Apr 2013
Edited: Matt J on 30 Apr 2013
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.

Sign in to comment.


Peihong
Peihong on 4 May 2013
Thanks, friends, I tried again by correcting the syntax error, it works. thanks.

Community Treasure Hunt

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

Start Hunting!