Failure in initial objective function evaluation. LSQNONLIN cannot continue.
이전 댓글 표시
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일
Please attach the data
Do not use global variables to pass fixed parameters and data around. Use these techniques instead,
Violeta Oikonomou
2019년 10월 21일
Violeta Oikonomou
2019년 10월 21일
Matt J
2019년 10월 21일
Well since it is "suggested", it means you are free to ignore the suggestion! I encourage you to do so.
Violeta Oikonomou
2019년 10월 21일
You're welcome. Also, this will be helpful reading as well,
Stephan
2019년 10월 21일
Where is the function AmericanCallTrinBoyle
Violeta Oikonomou
2019년 10월 21일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 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!