《r语言garchcopulavar模型附代码数据.docx》由会员分享,可在线阅读,更多相关《r语言garchcopulavar模型附代码数据.docx(33页珍藏版)》请在第壹文秘上搜索。
1、# 数据处理思路# #1.原始数据为4组时间序列;# #读取软件包library(,fGarch)IibraryCquantmod)library(ghyp)Iibrary(Copula)#设置工作目录#读取数据data=read.csv(Data.csv)head(data)#PoundJpanUsdEur#1-0.016689192-0.006422036-0.0041613040.001084608#20.0000000000.0059939300.000000000-0.034008741#30.000000000-0.0068502730.008322209-0.013969242#
2、40.0125174950.0102750050.000000000-0.001120290#50.012513888-0.0072778770.020798548-0.011676878#6-0.0083421910.0021406790.0124743500.007202157data=na.omit(data)# 2.对每组数据进行根本检验(自回归,异方差,自相关,稳定性,正态性)然后进行ARCHa,刀建模,得到四个边缘分布;# #自编函数进行根本检验testfun=function(yield)# #绘制时序图ts.plot(yield)# #根本统计量summary(yield)sd
3、(yield)var(yield)# #/*偏度、峰度*/n-length(yield)m-mean(yield)s-sd(yield)gl-n(n-l)*(n-2)*sum(yield-m)八3)s八3g2-(n*(n+l)(n-l)*(n-2)*(n-3)*sum(yield-m)7k4)s八4-(3*(n-l)八2)/(n-2)*(n-3)# #偏度gl# #峰度g2# #/*作图*/hist(yield,freq=F)lines(density(yield)# #QQ图(正态性)qqnorm(yield)qqline(yield)library(tseries)# #*JB检验*/(检
4、验正态性)print(jarque.bera.test(yield)# #*自相关性检验*/print(Box.test(yield,type=Ljung-Box)# 然后用自相关图检查序列的平稳性,,最后发现一阶差分后的序列是平稳的# #检验自相关偏相关系数acf(yield)pacf(yield)# 卜面对平稳性序列建立模型,偏相关系数在滞后/期后很快地趋向地,所以取p=2,自相关系数图形具有拖尾性,所以初步判断诲ru模型# #/*单位根检验*/稳定性检验print(adf.test(yield)print(pp.test(yield)# #*ARCH-LM检验结果*/异方差检验Iibra
5、ry(FinTS)print(ArchTest(yieldjlags=12jdemean=FALSE)# #建立/*GARCH*/模型library(fGarch);library(rugarch)# #*GARCH31)-norm*/garch_norm-garchFit(yieldgarch(l,1),trace=FALSE)garch_normspec-Ugarchspec(variance,model=list(garch0rder=c(l41),mean.model=list(armarder=c(0j0)fit-ugarchfit(spec=spec,data=yield)fit#
6、 #对每一组数据进行分析yield=data,ltestfun(yield)HistogramofyieldNormalQ-QPlot-3-2-10123TheoreticalQuantiIes# # #3arqueBeraTest# # #data:yield# #X-squared=61462,df=2,p-value2.2e-16# # #Box-Ljungtest# # #data:yield# #X-squared=0.51149,df=1,p-value=0.4745OOl101520253035V oLl_ # #Warninginadf.test(yield):p-values
7、mallerthanprintedp-value# # #AugmentedDickey-FullerTest# # #data:yield# #Dickey-Fuller=-13.844,Lagorder=13,p-value=0.01# #alternativehypothesis:stationary# #Warninginpp.test(yield):p-valuesmallerthanprintedp-value# # #Phillips-PerronUnitRootTest# # #data:yield# #Dickey-FullerZ(alpha)=-2511.3,Truncat
8、ionlagparameter=9,# #p-value=0.01# #alternativehypothesis:stationary# # # #ARCHLM-test;Nullhypothesis:noARCHeffects# # #data:yield# #Chi-squared=137.66,df=12,p-valuet)#mu-0.0003060.000404-0.75660.44929#omega0.0000050.0000041.30700.19123#alphal0.0269570.0050415.34780.00000#betal0.9639890.002210436.18
9、680.00000#RobustStandardErrors:#EstimateStd.Errortvalue-Pr(t)#mu-0.0003060.0004300.711640.47669#omega0.0000050.0000250.189450.84974#alphal0.0269570.0312150.863590.38782#betal0.9639890.005525174.479640.00000#LogLikelihood:6477.686#InformationCriteria# # Akaike-4.8275# # Bayes-4.8187# # Shibata-4.8275
10、# # Hannan-Quinn -4.8243# # # Weighted Ljung-Box Test# # # # Lagl# Lag2*(p+q)+(p+q)-l2# Lag4*(p+q)+(p+q)-l5# d.o.f=0on Standardizedstatistic0.008321.482044.83395Residualsp-value 0.9273 0.3652 0.1668# #H0:Noserialcorrelationon Standardized Squared Residuals#statisticp-value#Lagl6.920.008522#Lag2*(p+q
11、)+(p+q)-l58.110.027672#Lag4*(p+q)+(p+q)-l9#d.o.f=211.590.022506#WeightedLjung-BoxTest#WeightedARCHLMTests#-#StatisticShapeScaleP-Value#ARCHLag30.29370.5002.0000.5878#ARCHLag52.03341.4401.6670.4639#ARCHLag75.60102.3151.5430.1704#Nyblomstabilitytest#JointStatistic:4.4761#IndividualStatistics:# #mu0.32
12、021# #omega0.76021# #alphal0.09171# #betal0.23634# # #AsymptoticCriticalValues(10%5%1%)# #JointStatistic:1.071.241.6# #IndividualStatistic:0.350.470.75# # #SignBiasTest# # #t-valueprobsig# #SignBias2.02860.04260*# #NegativeSignBias2.53880.01118*# #PositiveSignBias0.29350.76914# #JointEffect6.99890.07193*# # # #AdjustedPearsonGoodness-of-FitTest:# #groupstatisticp-value(g-l)#120105.74.951e-14#230216.21.590e-30#340284.3