Uploaded by nikidhia

Case-Assignment-4.2

advertisement
Cox–Ingersoll–Ross (CIR) model
113464
7/5/2020
Functions
Matplot of the paths of Vasicek
Zero-Coupon Bond price using simulated data
Zero-Coupon Bond price using CIR
Main Section
Enter input parameters
Generate N scenarios
Plot the results
Calculate ZCB price and effective yield using N scenarios
Calculate ZCB price and effective yield using CIR
The Cox–Ingersoll–Ross (CIR) model is used to model mean-reverting quantities such as interest rates, carbon emissions, inflation, and
electricity prices.It is a type of one-factor short rate model as it describes interest rate movements as driven by only one source of market risk.
The Stochastic Differential Equation of the model is given by;
drt = κ(θ − rt )dt + σ√r dWt
t
here, κ is the mean reversion, θ is the long-term interest rate, and σ is the volatility The drift factor,κ(θ − rt ) , is exactly the same as in the
Vasicek model. The standard deviation factor,σ√rt , avoids the possibility of negative interest rates for all positive values of κ and θ. An interest
rate of zero is also precluded if the condition
2κθ ≥ σ
2
is met.
Functions
Matplot of the paths of Vasicek
matplot(t, r[,1:5000], type="l", lty=1, main="Simulated Paths", ylab="rt")
Zero-Coupon Bond price using simulated data
ss <- colSums(r[2:(m+1),]*dt)
c <- exp(-ss)
estimate_price <- mean(c)
Zero-Coupon Bond price using CIR
The formula for pricing the zero-coupon bond with a maturity T will be given by;
P (0, T ) = a(T )e
−b(T )ro
where,
−
−
−
−
−
−
−
−
−
2
2
h = √ (κ
+ 2σ )
denominator = 2h + (κ + h)e
b(T ) =
2e
(T ∗h)−1
(T ∗h)−1
2h + (κ + h)e
(T ∗h)−1
and
a(T ) =
2he
(κ+h)(T )/2
2h + (κ + h)e
(T ∗h)−1
CIR_ZCB_price <- function(r0,k,theta,sigma,T){
h <- sqrt(k^2+2*(sigma^2))
denom <- 2*h+(k+h)*exp((T*h) -1)
a.CIR <- 2*h*exp((k+h)*T/2)/denom
b.CIR <-2*exp((T*h)-1)
return(a.CIR*exp(-b.CIR*r0))
}
Main Section
Enter input parameters
r0=0.03
k=0.3
theta=0.05
sigma=0.03
T=5
n=5000
m=252
dt=T/m
set.seed(1)
Generate N scenarios
r <- matrix(0,m+1,n)
r[1,] <- r0
for(j in 1:n){
for(i in 2:(m+1)){
dr <- k*(theta-r[i-1,j])*dt + sigma*sqrt(dt)*rnorm(1,0,1)
r[i,j] <- r[i-1,j] + dr
}
}
t <- seq(0, T, dt)
Expected_Xt <- theta + (r0-theta)*exp(-k*t)
exp_Xt<- mean(Expected_Xt)
Std.Dev_Xt <- sqrt( sigma^2/(2*k)*(1-exp(-2*k*t)))
std_Xt<-mean(Std.Dev_Xt)
Plot the results
matplot(t, r[,1:5000], type="l", lty=1, main="Simulated Paths", ylab="rt")
I decided to use a sample of 50 paths
matplot(t, r[,1:50], type="l", lty=1, main="Sample Simulated Paths", ylab="rt")
abline(h=theta, col="black", lty=2)
lines(t, Expected_Xt, lty=2)
lines(t, Expected_Xt + 2*Std.Dev_Xt, lty=2)
lines(t, Expected_Xt - 2*Std.Dev_Xt, lty=2)
points(0,r0)
Calculate ZCB price and effective yield using N scenarios
ss <- colSums(r[2:(m+1),]*dt)
c <- exp(-ss)
estimate_price <- mean(c)
estimate_price
## [1] 0.8249086
Calculate ZCB price and effective yield using CIR
CIR_ZCB_price <- function(r0,k,theta,sigma,T){
h <- sqrt(k^2+2*(sigma^2))
denom <- 2*h+(k+h)*exp((T*h) -1)
a.CIR <- 2*h*exp((k+h)*T/2)/denom
b.CIR <-2*exp((T*h)-1)
return(a.CIR*exp(-b.CIR*r0))
}
exact_price<-CIR_ZCB_price(r0,k,theta,sigma,T)
exact_price
## [1] 1.532264
Download