VAR模型

Reads: 2121 Edit

1 数据

仍然采用2016年至2020年的shibor数据构建VAR模型,分析我们长期利率和短期利率之间的相互影响。

2 加载数据

打开Excel中的数据,复制前两列,如下图所示。

r-82

> shibor2=read.table("clipboard",header = TRUE)
> library(xts)    
> sb2=as.xts(shibor2)
> sb2
              dir    wir
2016-01-04 1.9950 2.3350
2016-01-05 1.9980 2.3300
2016-01-06 1.9800 2.3220
2016-01-07 1.9660 2.3130
2016-01-08 1.9580 2.3080
2016-01-11 1.9510 2.3030
2016-01-12 1.9510 2.3000
2016-01-13 1.9500 2.3000
2016-01-14 1.9500 2.3000
2016-01-15 1.9560 2.3030

说明:读取数据并转换成时间序列数据。

3 VAR模型分析

3.1 确定VAR模型的滞后期

> install.packages("vars")
> library(vars)
> library(lmtest)

> VARselect(sb2,lag.max=10,type="const")
$selection
AIC(n)  HQ(n)  SC(n) FPE(n) 
    10      6      5     10     

说明:采用VARselect()函数自动选择最优滞后阶数!这里采用HQ方法,选择滞后期为6期。

3.2 估计VAR方程

> fit_var=VAR(sb2, p = 6, type = "none")
> summary(fit_var)

VAR Estimation Results:
========================= 
Endogenous variables: dir, wir 
Deterministic variables: none 
Sample size: 1242 
Log Likelihood: 2395.856 
Roots of the characteristic polynomial:
0.9999 0.8994 0.7271 0.7271 0.6471 0.6471 0.5777 0.5777 0.5289 0.5289 0.2362 0.1451
Call:
VAR(y = sb2, p = 6, type = "none")


Estimation results for equation dir: 
==================================== 
dir = dir.l1 + wir.l1 + dir.l2 + wir.l2 + dir.l3 + wir.l3 + dir.l4 + wir.l4 + dir.l5 + wir.l5 + dir.l6 + wir.l6 

        Estimate Std. Error t value Pr(>|t|)    
dir.l1  1.009195   0.032938  30.639  < 2e-16 ***
wir.l1  0.445452   0.085004   5.240 1.88e-07 ***
dir.l2 -0.223972   0.046408  -4.826 1.57e-06 ***
wir.l2 -0.229660   0.113201  -2.029 0.042696 *  
dir.l3 -0.029756   0.046473  -0.640 0.522106    
wir.l3  0.059198   0.113246   0.523 0.601250    
dir.l4  0.161469   0.046484   3.474 0.000531 ***
wir.l4 -0.395249   0.113128  -3.494 0.000493 ***
dir.l5  0.034306   0.046064   0.745 0.456569    
wir.l5 -0.009601   0.114548  -0.084 0.933218    
dir.l6 -0.061872   0.032251  -1.918 0.055287 .  
wir.l6  0.226027   0.087527   2.582 0.009927 ** 
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1


Residual standard error: 0.1604 on 1230 degrees of freedom
Multiple R-Squared: 0.995,	Adjusted R-squared: 0.9949 
F-statistic: 2.022e+04 on 12 and 1230 DF,  p-value: < 2.2e-16 


Estimation results for equation wir: 
==================================== 
wir = dir.l1 + wir.l1 + dir.l2 + wir.l2 + dir.l3 + wir.l3 + dir.l4 + wir.l4 + dir.l5 + wir.l5 + dir.l6 + wir.l6 

       Estimate Std. Error t value Pr(>|t|)    
dir.l1  0.01622    0.01270   1.278 0.201601    
wir.l1  0.95966    0.03277  29.285  < 2e-16 ***
dir.l2 -0.01420    0.01789  -0.794 0.427355    
wir.l2 -0.11941    0.04364  -2.736 0.006306 ** 
dir.l3  0.01721    0.01792   0.961 0.336889    
wir.l3  0.05637    0.04366   1.291 0.196910    
dir.l4 -0.02278    0.01792  -1.271 0.203879    
wir.l4 -0.06895    0.04361  -1.581 0.114119    
dir.l5  0.04542    0.01776   2.558 0.010660 *  
wir.l5  0.02402    0.04416   0.544 0.586538    
dir.l6 -0.04384    0.01243  -3.526 0.000437 ***
wir.l6  0.14986    0.03374   4.441 9.75e-06 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1


Residual standard error: 0.06184 on 1230 degrees of freedom
Multiple R-Squared: 0.9994,	Adjusted R-squared: 0.9994 
F-statistic: 1.746e+05 on 12 and 1230 DF,  p-value: < 2.2e-16    

说明:特征根均小于1,因而VAR模型平稳!

3.3 脉冲响应分析

> fit_irf=irf(fit_var, impulse =c("dir", "wir"), response = c("dir", "wir"), boot =TRUE)
> fit_irf

Impulse response coefficients
$dir
             dir        wir
 [1,] 0.16041544 0.03093850
 [2,] 0.17567210 0.03229313
 [3,] 0.14863865 0.02786771
 [4,] 0.11271534 0.02730866
 [5,] 0.09658360 0.02165304
 [6,] 0.09363509 0.02341407
 [7,] 0.09235393 0.02456126
 [8,] 0.08487094 0.02393352
 [9,] 0.07633091 0.02277386
[10,] 0.06954698 0.02231456
[11,] 0.06380204 0.02157746

$wir
              dir        wir
 [1,] 0.000000000 0.05354620
 [2,] 0.023852247 0.05138637
 [3,] 0.034664310 0.04330690
 [4,] 0.040300413 0.03866601
 [5,] 0.021353319 0.03171151
 [6,] 0.002328567 0.02582680
 [7,] 0.003786989 0.03017233
 [8,] 0.014188013 0.03374029
 [9,] 0.022599291 0.03550523
[10,] 0.026212114 0.03590071
[11,] 0.025168969 0.03483890    

说明:$dir表示dir为脉冲,其下方的dir和wir为响应系数;同理,$wir表示dir为脉冲,其下方的dir和wir为响应系数。

> plot(fit_irf$irf$dir[,1],type='l',main="Resonpose of dir to dir",ylab="",xlab=fit_irf$response[1])
> lines(fit_irf$Lower$dir[,1],type="l",lty=2,col="red")
> lines(fit_irf$Upper$dir[,1],type="l",lty=2,col="red")

r-83

> plot(fit_irf$irf$dir[,2],type='l',main="Resonpose of wir to dir",ylab="",xlab=fit_irf$response[2])
> lines(fit_irf$Lower$dir[,2],type="l",lty=2,col="red")
> lines(fit_irf$Upper$dir[,2],type="l",lty=2,col="red")

r-84

wir为脉冲对应的两个响应图不再演示!

3.4 方差分解分析

> fit_fevd=fevd(fit_var, n.ahead = 100)
> plot(fit_fevd$wir[,1],type='l',col=1,ylab='预测方差贡献率',xlab="",main="Percent dir variance due to wir")

r-85

> plot(fit_fevd$wir[,2],type='l',col=1,ylab='预测方差贡献率',xlab="",main="Percent wir variance due to wir")

r-86

dir为脉冲对应的两个方差分解图不再演示!



获取案例数据,请关注微信公众号并回复:R_dt12


Comments

Make a comment