The stock price on calculating date
Designed the time point which is equal to CB's left period value
function CB_ value=CB_Shanying(t,rf,S1)
%Function designed for calculating the value of convertible bond with revise
TF98 model
%t
by YEAR
%rf Designed risk-free rate
%S1
% Input the initial parameters for Shanying Convertible Bond
% CB code: 110567; Stok code: 600567
%Stock's volatility
sigma=0.527;
% Risk-credit rate
rc=0.0098;
%Initial converting value per share
X=7.31;
%Face value of CB
F=100;
%Converting ratio
k=F/X;
dt=t/200;
%The period spent by every step
up=exp(sigma*sqrt(dt)); %The percent of stock price's rise
down=1/up;
p=(exp(rf*dt)-down)/(up-down); %The probability in the risk-neutral world
% The percent of stock price's drop
% Call price
%Put price
Cv=105;
Pv=105;
TimeConvert_on=0.5; %Time to begin Conversion
TimeConvert_off=5;
%Time to finish Conversion
%Time to begin Call
TimeCall_on=1;
%Time to finish Call
TimeCall_off=5;
TimePut 一 on=2;
%Time to begin Put
%Time to finish Put
TimePut 一 off=5;
n=200;
S=zeros(n,n);
V=zeros(n,n);
U=zeros(n,n);
B=zeros(n,n);
S(1,1)=S1;
%Steps of the binary tree evaluation
%Stock value matrix
%CB value matrix
% CB's stock part value matrix
% CB's bond part value matrix
% Initial stock price
% Evaluating movements of the stock
for i=2:n;
for j=1:i;
S(j,i)=S(1,1)*down^(j-1)*up^(i-j);
end;
end;
%Calculate the final value of bond considering the compensating rate
r1=0.014;
%The first year rate of the bond
r2=0.017;
r3=0.020;
r4=0.023;
r5=0.026;
Rcomp=0.028;
due date
%The second year rate
%The third year rate
% The fourth year rate
%The fifth year rate
%The compensating rate if doesn't conve 比 the bond on
Q= F*exp (5*Rcomp);
% Q is equal to face value plus the extra interest, is the cash flow on the bond’s
due date if no conversion
%Calculate CB value on the terming!
for j=1:n
if k*S(j,n)>=Q
%The converting value is bigger than the cash flow, so exercise the conversion
U(j,n)=k*S(j,n);
B(j,n)=0;
else
U(j,n)=0;
B(j,n)=Q;
%No conversion
end;
V(j,n)=U(j,n)+B(j,n);
end;
%Calculate CB's value on every node of binary tree from the back
for i=n-1:-1:1
m=5-(n-i)*dt;
% m is a time control variable for Convert, Call and Put Clause
If (m>=TimeConvert_on) && (m<=TimeConvert_off)
% Judge whether the time steps into the converting period
flag_convert=1;
%In the converting period
else
flag_convert=0;
%Not in the converting period
end;
if(m>=TimeCall_on)&&(m<=TimeCall_off)
%Judge whether the time steps into the call period
flag_call=1;
% In the Call period
else
flag call=0;
%Not in the Call period
end;
if(m>=TimePut_on)&&(m<=TimePut_off)
%Judge whether the time steps into the put period
flag_put=1;
%In the Put period
else
flag_put=0;
% Not in the Put period
end;
for j=1:i
if flag_convert==1
U(j,i)=exp(-rf*dt)*(p*U(j,i+1)+(1-p)*U(j+l,i+1));
%Deducing backward the stock part with the risk-free rate
B(j,i)=exp(-(rf+rc)*dt)*(p*B(j,i+1)+(1-p)*B(j+i,i+1));
% Deducing backward the bond part under credit risk
V(j,i)=U(j,i)+B(j,i);
else
U(j,i)=0;
% Stock part is no value in No-conversion period
V(j,i)=exp(-(rf+rc)*dt)*(p*V(j,i+1)+(1-p)*V(j+1,i+1));
% Deducing backward CB value under credit risk in No-conversion period
B(j,i)=V(j,i);
end;
if V(j,i)<=k*S(j,i)&&(flag_convert==1)
% Stock price is high enough for conversion
U(j,i)=k*S(j,i);
B(j,i)=0;
V(j,i)=U(j,i)+B(j,i);
elseif
(S(j,i)>=1.25*X)&&(V(j,i)>Cv)&&(flag_call==1);
%Satisfy the CALL Clause and exist arbitrage benefit for the company
U(j,i)=k*S(j,i);
% investors exercise conversion under call pressure
B(j,i)=0;
V(j,i)=U(j,i)+B(j,i);
elseif
(S(j,i)<=0.7*X)&&(V(j,i)
end;
%Show value of the CB on the initial date
CBee value=V(1,1);