Natural Yield Curve Analysis

Since 2016

# 3D plot
# create a xts object
jgb.xts <- as.xts(read.zoo(jgb1))
jgb.xts["2016::"] %>%
  data.matrix() %>% 
  t() %>%
  plot_ly(
    x=as.Date(index(jgb.xts["2016::"])),
    y=c(1,2,3,4,5,6,7,8,9,10,15,20,25,30,40),
    z=.,
    type="surface"
  ) %>%
  plotly::layout(
    scene=list(
      xaxis=list(title="date"),
      yaxis=list(title="term"),
      zaxis=list(title="yield")
    )
  )

Principal Component

library(readxl)
jgb2 <- read_xlsx("jgbcm_all.xlsx")
jgb2[is.na(jgb2)]<-0
jgb3 <- jgb2[,-1]
jgb_pca <-princomp((jgb3), cor=TRUE)

## JGB 2000~
#install.packages("readxl")
library(readxl)
jgb00 <- read_xlsx("jgbcm_all2000.xlsx")
jgb00[is.na(jgb00)] <- 0
jgb2000 <- jgb00[,-1]

## JGB 2016~ 
jgb16 <- read_xlsx("jgbcm_all2016.xlsx")
jgb16[is.na(jgb16)] <- 0
jgb2016 <- jgb16[,-1]

### PCA analysis[multivariate analysis] 
### PCA, (M)CA,FAMD,MFA,HCPC,factoextra
## Results
jgb_pca16 <- princomp((jgb2016),cor = TRUE)
summary(jgb_pca16)
## Importance of components:
##                           Comp.1     Comp.2     Comp.3      Comp.4      Comp.5
## Standard deviation     3.6682205 1.01380926 0.58014936 0.293227145 0.192111453
## Proportion of Variance 0.8970561 0.06852061 0.02243822 0.005732144 0.002460454
## Cumulative Proportion  0.8970561 0.96557673 0.98801495 0.993747092 0.996207546
##                             Comp.6      Comp.7       Comp.8       Comp.9
## Standard deviation     0.140859929 0.125726858 0.0908828194 0.0700280652
## Proportion of Variance 0.001322768 0.001053816 0.0005506458 0.0003269287
## Cumulative Proportion  0.997530314 0.998584130 0.9991347756 0.9994617043
##                             Comp.10    Comp.11      Comp.12      Comp.13
## Standard deviation     0.0576906263 0.04042214 0.0393639466 2.653498e-02
## Proportion of Variance 0.0002218806 0.00010893 0.0001033014 4.694033e-05
## Cumulative Proportion  0.9996835848 0.99979251 0.9998958162 9.999428e-01
##                             Comp.14      Comp.15
## Standard deviation     2.168769e-02 1.970524e-02
## Proportion of Variance 3.135706e-05 2.588643e-05
## Cumulative Proportion  9.999741e-01 1.000000e+00
biplot(jgb_pca16)

### compute standard deviation, variance, variance explained for each principal component
jgb_pca16$sdev
##     Comp.1     Comp.2     Comp.3     Comp.4     Comp.5     Comp.6     Comp.7 
## 3.66822051 1.01380926 0.58014936 0.29322714 0.19211145 0.14085993 0.12572686 
##     Comp.8     Comp.9    Comp.10    Comp.11    Comp.12    Comp.13    Comp.14 
## 0.09088282 0.07002807 0.05769063 0.04042214 0.03936395 0.02653498 0.02168769 
##    Comp.15 
## 0.01970524
jgb_pca16.var <- jgb_pca$sdev^2
jgb_pca16.var
##       Comp.1       Comp.2       Comp.3       Comp.4       Comp.5       Comp.6 
## 9.8804389838 2.4140452405 1.1371873041 0.5963342508 0.4385273645 0.2453697621 
##       Comp.7       Comp.8       Comp.9      Comp.10      Comp.11      Comp.12 
## 0.1611650453 0.0656489261 0.0379970807 0.0160542429 0.0039613877 0.0020930411 
##      Comp.13      Comp.14      Comp.15 
## 0.0007438953 0.0002430849 0.0001903903
###proportion of variance for screen plot
propve <- jgb_pca16.var/sum(jgb_pca16.var)

#plot variance explained for each p.c.

plot(propve, xlab = "principal component",
     ylab = "proportion of variance explained",
     ylim = c(0, 1), type = "b",
          main = "screen plot")

factor.loadings <- jgb_pca16$loadings[,1:3]
legend.loadings <- c("パラレル", "ツイスト", "バタフライ")
par(xaxt="n")
matplot(factor.loadings,
        lty = 1,
        lwd = 2)

3D plot of JGB Yield Curve since 2000-

# create a xts object
jgb.xts <- as.xts(read.zoo(jgb1))


# 3D plot
jgb.xts["2000::"] %>%
  data.matrix() %>% 
  t() %>%
  plot_ly(
    x=as.Date(index(jgb.xts["2000::"])),
    y=c(1,2,3,4,5,6,7,8,9,10,15,20,25,30,40),
    z=.,
    type="surface"
  ) %>%
  plotly::layout(
    scene=list(
      xaxis=list(title="date"),
      yaxis=list(title="term"),
      zaxis=list(title="yield")
    )
  )
## JGB 2000~ 
jgb00 <- read_excel("jgbcm_all2000.xlsx")
jgb00[is.na(jgb00)] <- 0
jgb2000 <- jgb00[,-1]
head(jgb2000)
## # A tibble: 6 x 15
##   `1年` `2年` `3年` `4年` `5年` `6年` `7年` `8年` `9年` `10年` `15年` `20年`
##   <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>  <dbl>  <dbl>  <dbl>
## 1 0.197 0.402 0.53  0.796 1.01   1.24  1.44  1.55  1.75   1.74   2.16   2.4 
## 2 0.183 0.38  0.501 0.766 0.977  1.21  1.40  1.52  1.72   1.72   2.14   2.38
## 3 0.192 0.388 0.504 0.764 0.974  1.20  1.39  1.51  1.71   1.71   2.12   2.36
## 4 0.196 0.406 0.543 0.811 1.03   1.25  1.44  1.55  1.74   1.74   2.14   2.38
## 5 0.205 0.421 0.562 0.827 1.03   1.25  1.43  1.55  1.73   1.74   2.13   2.37
## 6 0.217 0.454 0.607 0.874 1.08   1.29  1.47  1.58  1.76   1.76   2.14   2.37
## # i 3 more variables: `25年` <lgl>, `30年` <dbl>, `40年` <lgl>
### PCA analysis[multivariate analysis] 
### PCA, (M)CA,FAMD,MFA,HCPC,factoextra
## Results
jgb_pca00 <- princomp((jgb2000),cor = TRUE)
summary(jgb_pca00)
## Importance of components:
##                           Comp.1    Comp.2     Comp.3     Comp.4      Comp.5
## Standard deviation     3.5063502 1.2676669 0.85203009 0.51372530 0.279670035
## Proportion of Variance 0.8196328 0.1071320 0.04839702 0.01759425 0.005214355
## Cumulative Proportion  0.8196328 0.9267648 0.97516178 0.99275602 0.997970379
##                             Comp.6       Comp.7       Comp.8       Comp.9
## Standard deviation     0.125181924 0.0730934190 0.0581743993 0.0485624438
## Proportion of Variance 0.001044701 0.0003561765 0.0002256174 0.0001572207
## Cumulative Proportion  0.999015080 0.9993712563 0.9995968737 0.9997540944
##                             Comp.10      Comp.11      Comp.12      Comp.13
## Standard deviation     0.0405546375 3.079105e-02 2.275119e-02 1.527995e-02
## Proportion of Variance 0.0001096452 6.320592e-05 3.450779e-05 1.556512e-05
## Cumulative Proportion  0.9998637396 9.999269e-01 9.999615e-01 9.999770e-01
##                             Comp.14      Comp.15
## Standard deviation     1.404418e-02 1.214431e-02
## Proportion of Variance 1.314927e-05 9.832278e-06
## Cumulative Proportion  9.999902e-01 1.000000e+00
###2016~                    Comp.1     Comp.2     Comp.3      Comp.4   
## Standard deviation     3.6682205 1.01380926 0.58014936 0.293227145 
## Proportion of Variance 0.8970561 0.06852061 0.02243822 0.005732144 
## Cumulative Proportion  0.8970561 0.96557673 0.98801495 0.993747092 
##2000~と2016からのデータを比較すると、2016年からのYCの、第2主成分(傾き)における寄与率が2000年以降からのデータよりも小さいことがわかる。2016年以降から今のYCをプロットした場合に、中期ゾーンがデータの期間一定して低いまま推移していることが、傾きで説明できる寄与率が小さいことの理由の一つではないかと考えられる。逆に2000年以降の主成分で傾き(第2主成)の寄与率が高い(0.1071320%>0.06852061%[2016])理由は、2007年以降の数年間に中期の金利が上昇しているため、カーブ全体にフラット化傾向が見えたためその後の中期のボラティリティの高さが傾きを伴ったイールドカーブの形成に寄与しているためであると思う。
biplot(jgb_pca00)

### compute standard deviation, variance, variance explained for each principal component
jgb_pca00$sdev
##     Comp.1     Comp.2     Comp.3     Comp.4     Comp.5     Comp.6     Comp.7 
## 3.50635025 1.26766689 0.85203009 0.51372530 0.27967003 0.12518192 0.07309342 
##     Comp.8     Comp.9    Comp.10    Comp.11    Comp.12    Comp.13    Comp.14 
## 0.05817440 0.04856244 0.04055464 0.03079105 0.02275119 0.01527995 0.01404418 
##    Comp.15 
## 0.01214431
jgb_pca00.var <- jgb_pca$sdev^2
jgb_pca00.var
##       Comp.1       Comp.2       Comp.3       Comp.4       Comp.5       Comp.6 
## 9.8804389838 2.4140452405 1.1371873041 0.5963342508 0.4385273645 0.2453697621 
##       Comp.7       Comp.8       Comp.9      Comp.10      Comp.11      Comp.12 
## 0.1611650453 0.0656489261 0.0379970807 0.0160542429 0.0039613877 0.0020930411 
##      Comp.13      Comp.14      Comp.15 
## 0.0007438953 0.0002430849 0.0001903903
###proportion of variance for screen plot
propve_2 <- jgb_pca00.var/sum(jgb_pca00.var)

#plot variance explained for each p.c.

plot(propve_2, xlab = "principal component",
     ylab = "proportion of variance explained",
     ylim = c(0, 1), type = "b",
          main = "screen plot")

factor.loadings <- jgb_pca00$loadings[,1:3]
legend.loadings <- c("パラレル", "ツイスト", "バタフライ")
par(xaxt="n")
matplot(factor.loadings,
        lty = 1,
        lwd = 2)