Failure in initial objective function evaluation. LSQNONLIN cannot continue.
조회 수: 11 (최근 30일)
이전 댓글 표시
I'm building a script to generate a non-linear least squares estimation, after enterring my data. I build the follwing code:
function [x,resnorm,residual,exitflag,output] = TrCalibrationBoyle(~)
clear all
global strike; global S0; global irate; global TTM; global mktprice; global N; global k;
strike=zeros(80,8);
S0=zeros(80,8);
irate=zeros(80,8);
TTM=zeros(80,8);
mktprice=zeros(80,8);
parameter=zeros(80,2);
res=zeros(80,1);
exit=zeros(80,1);
strike=xlsread('DATA1.xls','strike','A1:A80');
S0=xlsread('DATA1.xls','S0','A1:A80');
irate=xlsread('DATA1.xls','irate','A1:A80');
TTM=xlsread('DATA1.xls','TTM','A1:A80');
mktprice=xlsread('DATA1.xls','mktprice','A1:A80');
N=xlsread('DATA1.xls','N','A1:A80');
for i=80:-1:1
x0=[0.5,1.099]; lb=[0.001,1]; ub=[2,5]; k=i;
[x,resnorm,residual,exitflag]=lsqnonlin(@TrBoyleLSQD,x0,lb,ub);
parameter(i)=x; res(i)=resnorm; exit(i)=exitflag; tr_matrix=zeros(80,8);
for j=1:8
tr_matrix(i,j)=AmericanCallTrinBoyle(strike(i,j),S0(i,j),irate(i,j),TTM(i,j),x(1),x(2),N(i,j));
end
pricedata=[tr_matrix];
end
xlswrite('apotelesmata.xls',pricedata,'results','A1:A80');
xlswrite('apotelesmata.xls',res,'results','B1:A80');
xlswrite('apotelesmata.xls',parameter,'results','C1:C80');
end
The function whitc is included is:
function [trBoyle_lsqd] = TrBoyleLSQD(x)
global strike; global S0; global irate; global TTM; global mktprice; global N; global k;
trBoyle_lsqd=zeros(1,8);
for j=1:8
trBoyle_lsqd(j)=mktprice(k,j)-AmericanCallTrinBoyle(strike(k,j),S0(k,j),irate(k,j),TTM(k,j),x(1),x(2),N(k,j));
end
end
After i run TrCalibrationBoyle in the command window, it shows me the following:
Index in position 1 exceeds array bounds.
Error in TrBoyleLSQD (line 11)
trBoyle_lsqd(j)=mktprice(k,j)-AmericanCallTrinBoyle(strike(k,j),S0(k,j),irate(k,j),TTM(k,j),x(1),x(2),N(k,j));
Error in lsqnonlin (line 206)
initVals.F = feval(funfcn{3},xCurrent,varargin{:});
Error in TrCalibrationBoyle (line 35)
[x,resnorm,residual,exitflag]=lsqnonlin(@TrBoyleLSQD,x0,lb,ub);
Caused by:
Failure in initial objective function evaluation. LSQNONLIN cannot continue.
Do you have any ideas for what is the error?
댓글 수: 9
채택된 답변
Stephan
2019년 10월 21일
The problem is that your DATA file is not complete - the sheet that should contain the data for N ist empty - therefore N is also empty in your code. I suspect there could be more problems, but this is the first thing, which leads to this error message.
댓글 수: 4
Stephan
2019년 10월 21일
편집: Stephan
2019년 10월 21일
You can use optimoptions to set this value higher - for more complex problems this could be useful - for example set it to 500:
options = optimoptions(@lsqnonlin,'MaxFunctionEvaluations',500);
[x,resnorm,residual,exitflag]=lsqnonlin(@TrBoyleLSQD,x0,lb,ub,options);
This may lead to further warnings - you have to read them and set the options accordingly. Maybe this will improve your results. Also may be you will not get better results with this. You should try it out.
Note that this will increase the calculation time.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!