フィルターのクリア

What is the 'Yes No' error code???

1 回表示 (過去 30 日間)
형현
형현 2023 年 9 月 26 日
編集済み: Voss 2023 年 9 月 26 日
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

回答 (1 件)

Voss
Voss 2023 年 9 月 26 日
編集済み: Voss 2023 年 9 月 26 日
ki_YesNo='No'
ki_YesNo = 'No'
% ...
switch ki_YesNo
case 'NO'
% ...
case 'Yes'
% ...
otherwise
error('ki_YesNO = Yes or No');
end
ki_YesNO = Yes or No
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

カテゴリ

Help Center および File ExchangeFinancial Data Analytics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by