拓端数据tecdat|R语言辅导ARMA-GARCH-COPULA模型和金融时间序列案例

原文 http://tecdat.cn/?p=3385

最近我被要求撰写关于金融时间序列的copulas的调查。 从读取数据中获得各种模型的描述,包括一些图形和统计输出。

 

  1.  
     
  2.  
     
  3.  
    > oil = read.xlsx(temp,sheetName =“DATA”,dec =“,”)
  4.  
     
 

然后我们可以绘制这三个时间序列

  1.  
    1 1997-01-10 2.73672 2.25465 3.3673 1.5400
  2.  
     
  3.  
    2 1997-01-17 -3.40326 -6.01433 -3.8249 -4.1076
  4.  
     
  5.  
    3 1997-01-24 -4.09531 -1.43076 -6.6375 -4.6166
  6.  
     
  7.  
    4 1997-01-31 -0.65789 0.34873 0.7326 -1.5122
  8.  
     
  9.  
    5 1997-02-07 -3.14293 -1.97765 -0.7326 -1.8798
  10.  
     
  11.  
    6 1997-02-14 -5.60321 -7.84534 -7.6372 -11.0549

这个想法是在这里使用一些多变量ARMA-GARCH过程。这里的启发式是第一部分用于模拟时间序列平均值的动态,第二部分用于模拟时间序列方差的动态。

本文考虑了两种模型

  • 关于ARMA模型残差的多变量GARCH过程(或方差矩阵动力学模型)
  • 关于ARMA-GARCH过程残差的多变量模型(基于copula)

因此,这里将考虑不同的序列,作为不同模型的残差获得。我们还可以将这些残差标准化。

ARMA模型

  1.  
    > fit1 = arima(x = dat [,1],order = c(2,0,1))
  2.  
    > fit2 = arima(x = dat [,2],order = c(1,0,1))
  3.  
    > fit3 = arima(x = dat [,3],order = c(1,0,1))
  4.  
    > m < - apply(dat_arma,2,mean)
  5.  
    > v < - apply(dat_arma,2,var)
  6.  
    > dat_arma_std < - t((t(dat_arma)-m)/ sqrt(v))

 

ARMA-GARCH模型

  1.  
    > fit1 = garchFit(formula = ~arma(2,1)+ garch(1,1),data = dat [,1],cond.dist =“std”)
  2.  
    > fit2 = garchFit(formula = ~arma(1,1)+ garch(1,1),data = dat [,2],cond.dist =“std”)
  3.  
    > fit3 = garchFit(formula = ~arma(1,1)+ garch(1,1),data = dat [,3],cond.dist =“std”)
  4.  
    > m_res < - apply(dat_res,2,mean)
  5.  
    > v_res < - apply(dat_res,2,var)
  6.  
    > dat_res_std = cbind((dat_res [,1] -m_res [1])/ sqrt(v_res [1]),(dat_res [,2] -m_res [2])/ sqrt(v_res [2]),(dat_res [ ,3] -m_res [3])/ SQRT(v_res [3]))
 

 

多变量GARCH模型

可以考虑的第一个模型是协方差矩阵的多变量EWMA,

> ewma = EWMAvol(dat_res_std,lambda = 0.96)

 

波动性

  1.  
    > emwa_series_vol = function(i = 1){
  2.  
    + lines(Time,dat_arma [,i] + 40,col =“gray”)
  3.  
    + j = 1
  4.  
    + if(i == 2)j = 5
  5.  
    + if(i == 3)j = 9

 

隐含相关性

  1.  
    > emwa_series_cor = function(i = 1,j = 2){
  2.  
    + if((min(i,j)== 1)&(max(i,j)== 2)){
  3.  
    + a = 1; B = 9; AB = 3}
  4.  
    + r = ewma $ Sigma.t [,ab] / sqrt(ewma $ Sigma.t [,a] *
  5.  
    + ewma $ Sigma.t [,b]
  6.  
    + plot(Time,r,type =“l”,ylim = c(0,1))
  7.  
    +}

 

多变量GARCH,即BEKK(1,1)模型,例如使用:

  1.  
    > bekk = BEKK11(dat_arma)
  2.  
    > bekk_series_vol function(i = 1){
  3.  
    + plot(Time, $ Sigma.t [,1],type =“l”,
  4.  
    + ylab = (dat)[i],col =“white”,ylim = c(0,80))
  5.  
    + lines(Time,dat_arma [,i] + 40,col =“gray”)
  6.  
    + j = 1
  7.  
    + if(i == 2)j = 5
  8.  
     
  9.  
    + if(i == 3)j = 9
  10.  
     
  11.  
    > bekk_series_cor = function(i = 1,j = 2){
  12.  
    + a = 1; B = 5; AB = 2}
  13.  
    + a = 1; B = 9; AB = 3}
  14.  
    + a = 5; B = 9; AB = 6}
  15.  
    + r = bk $ Sigma.t [,ab] / sqrt(bk $ Sigma.t [,a] *
  16.  
    + bk $ Sigma.t [,b]

 


 

从单变量GARCH模型中模拟残差

第一步可能是考虑残差的一些静态(联合)分布。单变量边缘分布是

边缘密度的轮廓(使用双变量核估计器获得) 

也可以将copula密度可视化(上面有一些非参数估计,下面是参数copula)

  1.  
    > copula_NP = function(i = 1,j = 2){
  2.  
    + n = nrow(uv)
  3.  
    + s = 0.3
  4.  
     
  5.  
    + norm.cop < - normalCopula(0.5)
  6.  
    + norm.cop < - normalCopula(fitCopula(norm.cop,uv)@estimate)
  7.  
    + dc = function(x,y)dCopula(cbind(x,y),norm.cop)
  8.  
     
  9.  
     
  10.  
    + ylab = names(dat)[j],zlab =“copule Gaussienne”,ticktype =“detailed”,zlim = zl)
  11.  
    +
  12.  
    + t.cop < - tCopula(0.5,df = 3)
  13.  
    + t.cop < - tCopula(t.fit [1],df = t.fit [2])
  14.  
     
  15.  
     
  16.  
    + ylab = names(dat)[j],zlab =“copule de Student”,ticktype =“detailed”,zlim = zl)
  17.  
    +}

 

可以考虑这个函数,

计算三个序列的的经验版本,并将其与一些参数版本进行比较,

  1.  
    >
  2.  
     
  3.  
    > lambda = function(C){
  4.  
    + l = function(u)pcopula(C,cbind(u,u))/ u
  5.  
    + v = Vectorize(l)(u)
  6.  
    + return(c(v,rev(v)))
  7.  
    +}
  8.  
    >
  9.  
     
  10.  
    > graph_lambda = function(i,j){
  11.  
    + X = dat_res
  12.  
    + U = rank(X [,i])/(nrow(X)+1)
  13.  
    + V = rank(X [,j])/(nrow(X)+1)
  14.  
     
  15.  
    + normal.cop < - normalCopula(.5,dim = 2)
  16.  
    + t.cop < - tCopula(.5,dim = 2,df = 3)
  17.  
    + fit1 = fitCopula(normal.cop,cbind(U,V),method =“ml”)
  18.  
    d(U,V),method =“ml”)
  19.  
    + C1 = normalCopula(fit1 @ copula @ parameters,dim = 2)
  20.  
    + C2 = tCopula(fit2 @ copula @ parameters [1],dim = 2,df = trunc(fit2 @ copula @ parameters [2]))
  21.  
    +

但人们可能想知道相关性是否随时间稳定。

  1.  
    > time_varying_correl_2 = function(i = 1,j = 2,
  2.  
    + nom_arg =“Pearson”){
  3.  
    + uv = dat_arma [,c(i,j)]
  4.  
    nom_arg))[1,2]
  5.  
    +}
  6.  
    > time_varying_correl_2(1,2)
  7.  
     
  8.  
    > time_varying_correl_2(1,2,“spearman”)
  9.  
     
  10.  
    > time_varying_correl_2(1,2,“kendall”)

 

斯皮尔曼与时变排名相关系数

或肯德尔 相关系数

为了模型的相关性,考虑DCC模型(S)

  1.  
    > m2 = dccFit(dat_res_std)
  2.  
    > m3 = dccFit(dat_res_std,type =“Engle”)
  3.  
    > R2 = m2 $ rho.t
  4.  
    > R3 = m3 $ rho.t

 

要获得一些预测, 使用例如

  1.  
    > garch11.spec = ugarchspec(mean.model = list(armaOrder = c(2,1)),variance.model = list(garchOrder = c(1,1),model =“GARCH”))
  2.  
    > dcc.garch11.spec = dccspec(uspec = multispec(replicate(3,garch11.spec)),dccOrder = c(1,1),
  3.  
    distribution =“mvnorm”)
  4.  
    > dcc.fit = dccfit(dcc.garch11.spec,data = dat)
  5.  
    > fcst = dccforecast(dcc.fit,n.ahead = 200)

 

 


 

最受欢迎的见解

1.HAR-RV-J与递归神经网络(RNN)混合模型预测和交易大型股票指数的高频波动率

2.R语言中基于混合数据抽样(MIDAS)回归的HAR-RV模型预测GDP增长

3.波动率的实现:ARCH模型与HAR-RV模型

4.R语言ARMA-EGARCH模型、集成预测算法对SPX实际波动率进行预测

5.GARCH(1,1),MA以及历史模拟法的VaR比较

6.R语言多元COPULA GARCH 模型时间序列预测

7.R语言基于ARMA-GARCH过程的VAR拟合和预测

8.matlab预测ARMA-GARCH 条件均值和方差模型

9.R语言对S&P500股票指数进行ARIMA + GARCH交易策略

posted @ 2018-09-12 15:40  拓端tecdat  阅读(1384)  评论(0编辑  收藏  举报