在arch包顶部构建的多个单变量arch建模工具箱
muarch的Python项目详细描述
muarch
连续积分
文档
覆盖范围
安装
使用pip并在conda上安装和更新。
这是kevin sheppard的ARCH包上的包装。其目的是:
- 启用更快的蒙特卡罗模拟
- 通过copula marginals模拟创新
在包中,有两个类可以帮助您-UArch
和MUArch
。可以使用与原始arch
包中的arch_model
相似的api来定义UArch
类。MUArch
是这些UArch
模型的集合。
因此,如果你有一个生成统一边值的函数,比如copula,你可以在模拟garch过程时在不同边值之间创建一个依赖结构。
如果你需要一个copula包,我有一个here。:)
示例
我将列出一个简单的过程做ar-garch-copula模拟。
frommuarchimportMUArch,UArchfrommuarch.datasetsimportload_etffromcopulaeimportNormalCopulareturns=load_etf()# load returns datanum_assets=returns.shape[1]# sets up a MUArch model collection where each model defaults to # mean: AR(1)# vol: GARCH(1, 1)# dist: normal models=MUArch(num_assets,mean='AR',lags=1)# set first model to AR(1)-GARCH(1, 1) with skewt innovations models[0]=UArch('AR',lags=1,dist='skewt')# fit model, if you get complaints regarding non-convergence, you can scale the data up # using the scale parameter in the UArch or MUArch. i.e. UArch(..., scale=100). This will# reduce numerical errors. Don't worry, I'll rescale the simulation values subsequentlymodels.fit(returns)# Usually you'll want to fit the residuals to the copula, use the copula to generate the# residuals and subsequently transform it back to returns residuals=models.residuals()# defaults to return the standardized residualscop=NormalCopula(dim=num_assets)# use a normal copula, you could of course use a TCopulacop.fit(residuals)# simulate 10 steps into the future, over 4 repetitions. This will return a (10 x 4 x 3) arraymodels.simulate_mc(10,4,custom_dist=cop.random)
未来工作
这实际上是一个临时的黑客,以便其他人可以做garch copula模拟。另一个问题是arfima mean模型不太容易用原始的arch
包指定(并从中模拟)。你可以指定一个arfima(或者仅仅是一个arma模型),分别对其进行拟合,然后使用残差拟合一个零均值模型(纯garch)。然而,以这种方式,模拟并不是那么简单,因为您将不得不将garch过程和mean模型过程的模拟缝合起来。