What is the 'Yes No' error code???
2 views (last 30 days)
Show older comments
ns=10;
face=10000;
val_date='04-02-2007';
mid_date= ['09-05-2007';'03-05-2008';'09-05-2008';'03-05-2009'];
strike=[0.9 0.85 0.8 0.75];
c_rate=[0.055 0.11 0.165 0.22];
dummy=0.16;
ki=0.6;
ki_YesNo='No' %HERE
ref_S= [48300 86800];
S=[45800 84600];
r=0.05;
vol=[0.25 0.3];
rho=0.5;
q=[0.01 0.01];
temp_ch=datenum(mid_date)'-datenum(val_date);
mid_ch=temp_ch(find(temp_ch>=0));
c_rate=c_rate(find(temp_ch>=0));
strike=strike(find(temp_ch>=0));
N=mid_ch(end);
dt=1/365;
mid_size=length(mid_ch);
payment=zeros(ns,mid_size);
for i =1:ns
for j=1:mid_size
payment(i,j)=face*(1+c_rate(j));
end
end
corr=[1 rho;rho 1];
M=chol(corr);
SP1=zeros(ns,N+1);
SP1(:,1)=S(1);
SP2=zeros(ns,N+1);
SP2(:,1)=S(2);
for i=1:ns
w0=randn(N,2);
w=w0*M;
for j=2:N+1
SP1(i,j)=SP1(i,j-1)*exp((r-q(1)-vol(1)^2/2)*dt+...
vol(1)*sqrt(dt)*w(j-1,1));
SP2(i,j)=SP2(i,j-1)*exp((r-q(2)-vol(2)^2/2)*dt+...
vol(2)*sqrt(dt)*w(j-1,2));
end
end
R1=SP1/ref_S(1);
R2=SP2/ref_S(2);
WP=min(R1,R2);
strike_ch=WP(:,mid_ch+1);
payoff=zeros(ns,mid_size);
for i=1:ns
for j=1:mid_size
if strike_ch(i,j)>=strike(j)
payoff(i,j)=payment(i,j);
break
end
end
continue
end
for i=1:ns
if payoff(i,:)==0
switch ki_YesNo
case 'NO'
ki_event=any(WP(i,:)<ki);
if ki_event==1
payoff(i,end)=face*WP(i,end);
else
payoff(i,end)=face*(1+dummy);
end
case 'Yes'
payoff(i,end)=face*WP(i,end);
otherwise
error('ki_YesNO = Yes or No');
end
end
end
exp_payoff=mean(payoff);
disc_payoff=zeros(1,mid_size);
for j=1:mid_size
disc_payoff(j)=exp_payoff(j)*exp(-r*mid_ch(j)/365);
end
ELS_Price=sum(disc_payoff);
-----------------------------
in this code, There are "ki_YesNO = Yes or No" problem code was out. With the teaching plan i just write down correctly... What's the problem
0 Comments
Answers (1)
Voss
on 26 Sep 2023
Edited: Voss
on 26 Sep 2023
ki_YesNo='No'
% ...
switch ki_YesNo
case 'NO'
% ...
case 'Yes'
% ...
otherwise
error('ki_YesNO = Yes or No');
end
Notice that's switch 'NO' (with an upper-case O), but ki_YesNo is 'No' (lower-case o). 'No' is not the same as 'NO', and 'No' is not the same as 'Yes', so the code went to the otherwise branch and the error was thrown.
If you want the match to be case-insensitive, so that 'no', 'No', 'NO', and 'nO' all go to the 'NO' branch (and similarly 'yes', 'YES', 'yEs', etc., all go to the 'Yes' branch), one way to do that is:
switch lower(ki_YesNo) % make lower-case
case 'no' % check against lower-case
% ...
case 'yes'
% ...
otherwise
error('ki_YesNO = Yes or No');
end
0 Comments
See Also
Categories
Find more on Financial Data Analytics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!