ARMA-GARCH-COPULA模型和金融时间序列案例

简介: ARMA-GARCH-COPULA模型和金融时间序列案例

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

> oil = read.xlsx(temp,sheetName =“DATA”,dec =“,”)

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

1 1997-01-10 2.73672 2.25465 3.3673 1.5400


2 1997-01-17 -3.40326 -6.01433 -3.8249 -4.1076


3 1997-01-24 -4.09531 -1.43076 -6.6375 -4.6166


4 1997-01-31 -0.65789 0.34873 0.7326 -1.5122


5 1997-02-07 -3.14293 -1.97765 -0.7326 -1.8798


6 1997-02-14 -5.60321 -7.84534 -7.6372 -11.0549

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

本文考虑了两种模型

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

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

ARMA模型

> fit1 = arima(x = dat \[,1\],order = c(2,0,1))
> fit2 = arima(x = dat \[,2\],order = c(1,0,1))
> fit3 = arima(x = dat \[,3\],order = c(1,0,1))
> m < - apply(dat_arma,2,mean)
> v < - apply(dat_arma,2,var)
> dat\_arma\_std < - t((t(dat_arma)-m)/ sqrt(v))
ARMA-GARCH模型
> fit1 = garchFit(formula = ~arma(2,1)+ garch(1,1),data = dat \[,1\],cond.dist =“std”)
> fit2 = garchFit(formula = ~arma(1,1)+ garch(1,1),data = dat \[,2\],cond.dist =“std”)
> fit3 = garchFit(formula = ~arma(1,1)+ garch(1,1),data = dat \[,3\],cond.dist =“std”)
> m\_res < - apply(dat\_res,2,mean)
> v\_res < - apply(dat\_res,2,var)
> 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)
波动性
> emwa\_series\_vol = function(i = 1){
+ lines(Time,dat_arma \[,i\] + 40,col =“gray”)
+ j = 1
+ if(i == 2)j = 5
+ if(i == 3)j = 9


01

02

03

04


隐含相关性

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

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

> bekk = BEKK11(dat_arma)
> bekk\_series\_vol function(i = 1){
+ plot(Time, $ Sigma.t \[,1\],type =“l”,
+ ylab = (dat)\[i\],col =“white”,ylim = c(0,80))
+ lines(Time,dat_arma \[,i\] + 40,col =“gray”)
+ j = 1
+ if(i == 2)j = 5
+ if(i == 3)j = 9
> bekk\_series\_cor = function(i = 1,j = 2){
+ a = 1; B = 5; AB = 2}
+ a = 1; B = 9; AB = 3}
+ a = 5; B = 9; AB = 6}
+ r = bk $ Sigma.t \[,ab\] / sqrt(bk $ Sigma.t \[,a\] *
+ bk $ Sigma.t \[,b\])

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

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

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

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

> copula_NP = function(i = 1,j = 2){
+ n = nrow(uv)
+ s = 0.3
+ norm.cop < - normalCopula(0.5)
+ norm.cop < - normalCopula(fitCopula(norm.cop,uv)@estimate)
+ dc = function(x,y)dCopula(cbind(x,y),norm.cop)
+ ylab = names(dat)\[j\],zlab =“copule Gaussienne”,ticktype =“detailed”,zlim = zl)
+
+ t.cop < - tCopula(0.5,df = 3)
+ t.cop < - tCopula(t.fit \[1\],df = t.fit \[2\])
+ ylab = names(dat)\[j\],zlab =“copule de Student”,ticktype =“detailed”,zlim = zl)
+}

可以考虑这个 函数,

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

>
> lambda = function(C){
+ l = function(u)pcopula(C,cbind(u,u))/ u
+ v = Vectorize(l)(u)
+ return(c(v,rev(v)))
+}
>
> graph_lambda = function(i,j){
+ X = dat_res
+ U = rank(X \[,i\])/(nrow(X)+1)
+ V = rank(X \[,j\])/(nrow(X)+1)
+ normal.cop < - normalCopula(.5,dim = 2)
+ t.cop < - tCopula(.5,dim = 2,df = 3)
+ fit1 = fitCopula(normal.cop,cbind(U,V),method =“ml”)
d(U,V),method =“ml”)
+ C1 = normalCopula(fit1 @ copula @ parameters,dim = 2)
+ C2 = tCopula(fit2 @ copula @ parameters \[1\],dim = 2,df = trunc(fit2 @ copula @ parameters \[2\]))
+

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

> time\_varying\_correl_2 = function(i = 1,j = 2,
+ nom_arg =“Pearson”){
+ uv = dat_arma \[,c(i,j)\]
nom_arg))\[1,2\]
+}
> time\_varying\_correl_2(1,2)
> time\_varying\_correl_2(1,2,“spearman”)
> time\_varying\_correl_2(1,2,“kendall”)

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

或肯德尔 相关系数

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

> m2 = dccFit(dat\_res\_std)
> m3 = dccFit(dat\_res\_std,type =“Engle”)
> R2 = m2 $ rho.t
> R3 = m3 $ rho.t

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

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


相关文章
|
10月前
|
机器学习/深度学习 自然语言处理 语音技术
《探秘卷积神经网络:权重共享与局部连接的神奇力量》
卷积神经网络(CNN)中的权重共享和局部连接是其核心特性。权重共享通过同一卷积核在不同位置使用相同权重,减少参数量并提高泛化能力;局部连接则使每个神经元仅与输入的局部区域相连,专注于提取局部特征。两者相辅相成,显著降低计算复杂度,增强对空间结构的感知,使CNN在图像识别等领域表现出色。
662 8
|
JavaScript 前端开发
时间序列分析实战(二):时序的ARMA模型拟合与预测
时间序列分析实战(二):时序的ARMA模型拟合与预测
|
数据采集 分布式计算 大数据
数据治理之道:大数据平台的搭建与数据质量管理
【10月更文挑战第27天】在数字化时代,数据治理对于确保数据资产的保值增值至关重要。本文探讨了大数据平台的搭建和数据质量管理的重要性及实践方法。大数据平台应包括数据存储、处理、分析和展示等功能,常用工具如Hadoop、Apache Spark和Flink。数据质量管理则涉及数据的准确性、一致性和完整性,通过建立数据质量评估和监控体系,确保数据分析结果的可靠性。企业应设立数据治理委员会,投资相关工具和技术,提升数据治理的效率和效果。
428 2
|
Web App开发
Chrome——谷歌浏览器chrome如何模拟其他客户端
Chrome——谷歌浏览器chrome如何模拟其他客户端
347 1
Chrome——谷歌浏览器chrome如何模拟其他客户端
|
数据可视化 算法 Python
python中的copula:Frank、Clayton和Gumbel copula模型估计与可视化
python中的copula:Frank、Clayton和Gumbel copula模型估计与可视化
|
机器学习/深度学习 人工智能 安全
隐语小课丨「论文研究」隐私保护纵向联邦图神经网络
隐语小课丨「论文研究」隐私保护纵向联邦图神经网络
392 0
|
算法 Python
算法理论——回溯算法及剪枝优化
回溯法也可以叫做回溯搜索法,它是一种搜索的方式。
599 0
算法理论——回溯算法及剪枝优化
|
IDE 程序员 开发工具
22【Python基础】VS2019中使用Python及安装Python包
要使用Python语言来写一些程序,使用哪个IDE是个问题,若是专业开发Python,PyCharm无疑是最佳选择,作为使用VS较多的程序员,直接在VS中写Python是个不错的选择。本文主要介绍VS2019中安装Python环境、安装后环境配置、使用pip install ***安装Python包的过程。
738 0
|
机器学习/深度学习 决策智能 计算机视觉
基于SVM的时间序列预测-python实现(附源码)
基于SVM的时间序列预测-python实现(附源码)
518 0