Serving the Quantitative Finance Community

 
User avatar
nadim216
Topic Author
Posts: 0
Joined: July 27th, 2009, 1:22 pm

fmincon error

January 18th, 2011, 6:25 pm

Friends,I try to run a code to the portfolio optimization purpose with matlab, I get an error, and I don't know what is my mistakelet's begin step by step:I create two m files:the first one: myfune.m:function f = myfun(x);f = - y()'*expreturn()'; (expreturn is calculated in this mfile, and X is given).the second mfile: nonlcon.mfunction [c,ceq] = nonlcon(y);a=5;Q=cov(X);c = [y()'*Q*y()-a];ceq = [];a=5;the script that I try to run:Aeq = ones(1,41); beq = 1; lb = zeros(1,41); ub = ones(1,41);y0=0.1*ones(41,1);y=y0;% y = fmincon(@myfun,y0,[],[],Aeq,beq,lb,ub,@nonlcon);options = optimset('LargeScale','off'); [y,fval] = fmincon(@myfun,y0,[],[],Aeq,beq,lb,ub,@nonlcon, options);when I try to run the script, I get these messages errors, I don't kow what is my mistake:??? Error using ==> fminconFMINCON cannot continue because user supplied objective function failed with the following error: Subscripted assignment dimension mismatch.Any help is very much appreciated
 
User avatar
nadim216
Topic Author
Posts: 0
Joined: July 27th, 2009, 1:22 pm

fmincon error

January 18th, 2011, 7:44 pm

here I can describe with more details my problemwhen i try to open the debugger, I find the problem in the try catch statment:switch funfcn{1}case 'fun' try f = feval(funfcn{3},X,varargin{:}); catch error('optim:fminconbjectiveError', ... ['FMINCON cannot continue because user supplied objective function' ... ' failed with the following error:\n%s'], lasterr)
 
User avatar
Hansi
Posts: 41
Joined: January 25th, 2010, 11:47 am

fmincon error

January 18th, 2011, 7:46 pm

Well since you have ommitted some of the code I can't say for sure but my first thought would be that in myfun if y and expreturn are vectors they shouldn't be referred to with ().