今週も特にありません

進捗どうですか?

Vasicekモデルの債券価格とイールド

金利のモデル、デリバティブあたりをまとめた便利なRのパッケージってない…? 少なくとも、有名どころのパッケージを聞かないので、多くの人に安定的に使われているものはなさそう

未だ使い慣れないggplot2の練習も含めて、Vasicekモデルにおける債券価格とイールドについて

# zero coupon bond price and yield under Vasicek model
# 
# Args:
#   kappa : speed of reversion
#   mu    : long term mean level
#   sigma : instaneous volatility
#   r0    : current short rate
#   t     : current time
#   T     : bond maturity
#
# Return:
#   data.frame of maturity, bond price and yield
#
VasicekZCBond <- function(kappa, mu, sigma, r0, t, T) {
  tau <- T - t
  B <- (1 - exp(-kappa * tau)) / kappa
  A <- exp((mu - sigma^2 / (2 * kappa^2)) * (B - tau) - sigma ^ 2 / (4 * kappa) * B^2)
  P <- A * exp(-B * r0)
  Y <- ifelse(tau != 0, -log(P) / tau, r0)
  data.frame(maturity = tau, price = P, yield = Y)
}

現在の日本やドイツのイールドカーブにフィットするようなパラメータは大体の教科書に出てくるパラメータとはだいぶかけ離れている

Vasicekモデルなので、お遊びで現在のスポットレートをマイナスにセットしても面白いかもしれない

kappa <- 0.2
mu <- 0.015
sigma <- 0.003
r0 <- -0.001
t <- 0
T <- c(1/12, 1/4, 1/2, 1:10, 15, 20, 30)
df <- VasicekZCBond(kappa, mu, sigma, r0, t, T)

債券価格とイールドは次のようになる

> df
      maturity     price         yield
1   0.08333333 1.0000723 -0.0008674146
2   0.25000000 1.0001517 -0.0006066745
3   0.50000000 1.0001132 -0.0002263613
4   1.00000000 0.9995030  0.0004971657
5   2.00000000 0.9963899  0.0018083087
6   3.00000000 0.9911608  0.0029594929
7   4.00000000 0.9842342  0.0039728389
8   5.00000000 0.9759579  0.0048671608
9   6.00000000 0.9666189  0.0056584930
10  7.00000000 0.9564529  0.0063605269
11  8.00000000 0.9456528  0.0069849753
12  9.00000000 0.9343755  0.0075418761
13 10.00000000 0.9227486  0.0080398472
14 15.00000000 0.8623588  0.0098722601
15 20.00000000 0.8024879  0.0110019245
16 30.00000000 0.6923496  0.0122554754

イールドカーブをプロットする

library(ggplot2)
library(ggthemes)

ggplot(df, aes(x = maturity, y = yield)) + geom_line(size = 1.2) + 
theme_economist() + ggtitle("normal yield curve") + xlab("time to maturity")

f:id:masaqol:20150125221510p:plain

ここでは、Vasicekモデルで表現できるハンプ、逆イールドについてもプロット

kappa <- 0.15
mu <- 0.0012
sigma <- 0.003
r0 <- 0.001
df <- VasicekZCBond(kappa, mu, sigma, r0, t, T)
ggplot(df, aes(x = maturity, y = yield)) + geom_line(size = 1.2) + 
theme_economist() + ggtitle("humped yield curve") + xlab("time to maturity")

f:id:masaqol:20150125222349p:plain

kappa <- 0.15
mu <- 0.008
sigma <- 0.003
r0 <- 0.009
df <- VasicekZCBond(kappa, mu, sigma, r0, t, T)
ggplot(df, aes(x = maturity, y = yield)) + geom_line(size = 1.2) + 
theme_economist() + ggtitle("inverted yield curve") + xlab("time to maturity")

f:id:masaqol:20150125222326p:plain

Vasicekモデルは実務に耐え得るモデルではないものの、いくつかの短期金利モデルを比較するような論文には登場することは多いので、これぐらいはパッケージ化されていても良い気もしますが…