r语言garchcopulavar模型附代码数据.docx

上传人:李司机 文档编号:1585025 上传时间:2022-12-09 格式:DOCX 页数:32 大小:524.89KB
返回 下载 相关 举报
r语言garchcopulavar模型附代码数据.docx_第1页
第1页 / 共32页
r语言garchcopulavar模型附代码数据.docx_第2页
第2页 / 共32页
r语言garchcopulavar模型附代码数据.docx_第3页
第3页 / 共32页
r语言garchcopulavar模型附代码数据.docx_第4页
第4页 / 共32页
r语言garchcopulavar模型附代码数据.docx_第5页
第5页 / 共32页
点击查看更多>>
资源描述

《r语言garchcopulavar模型附代码数据.docx》由会员分享,可在线阅读,更多相关《r语言garchcopulavar模型附代码数据.docx(32页珍藏版)》请在三一办公上搜索。

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.4745OOl101520253035VoLl_# #Warninginadf.test(yield):p-valuesma

7、llerthanprintedp-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,Truncatio

8、nlagparameter=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.1868

9、0.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=0onStandardizedstatistic0.008321.482044.83395Residualsp-value0.9273 0.3652 0.1668# #H0:NoserialcorrelationonStandardized Squared Residuals#statisticp-value#Lagl6.920.008522#Lag2*(p+q)+(p+q

11、)-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.32021# #

12、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*#

13、 # # #AdjustedPearsonGoodness-of-FitTest:# #groupstatisticp-value(g-l)#120105.74.951e-14#230216.21.590e-30#340284.35.053e-39#450404.91.711e-57#Eilapsedtime:0.784045yield=data42testfun(yield)TimeHistogramofyield-006-004-002000002004NormalQ-QPlot-3-2-10123TheoreticalQuantiIes# #3arqueBeraTest# # #data

14、:yielddf= 2, p-value 2.2e-16#X-squared=622.46,# #Box-Ljungtest# #df= 1, p-value = 0.003235# #data:yield# #X-squared=86698,LLlI.).II.I.-H-:-l-4-二J二-+-0O9oVOCMOOT05101520253035Lag-value# #Warninginadf.test(yield):p-valuesmallerthanprinted# # #AugmentedDickey-FullerTest# # #data:yield# #Dickey-Fuller=-

15、13.404,Lagorder=13,p-value=0.01# #alternativehypothesis:stationary# #Warninginpp.test(yield):p-valuesmallerthanprintedp-value# # #Phillips-PerronUnitRootTest# # #data:yield# #Dickey-FullerZ(alpha)=-2799.7,Truncationlagparameter=9,# #p-value=0.01# #alternativehypothesis:stationary# # # #ARCHLM-test;N

16、ullhypothesis:noARCHeffects# # #data:yield# #Chi-squared=200.84,df=12,p-valuet)#mu-0.0003780.000162-2.326060.020015#omega0.0000010.0000030.298290.765484#alphal0.0734540.0541461.356590.174911#betal0.9184890.05378717.076550.000000#RobustStandardErrors:#EstimateStd.Errortvalue-Pr(t)#mu-0.0003780.004551

17、0.0830400.93382#omega0.0000010.0002240.0044030.99649#alphal0.0734543.6091320.0203520.98376#betal0.9184893.5989370.2552110.79856#LogLikelihood:8875.036#InformationCriteria#Akaike-6.6152# #Bayes-6.6064# #Shibata-6.6152# #Hannan-Quinn-6.6121#WeightedLjung-BoxTestonStandardizedResiduals# # #Lagl# #Lag2*

18、(p+q)+(p+q)-l2# #Lag4*(p+q)+(p+q)-l5# #d.o.f=0statisticp-value1.6700.19632.1290.24223.1790.3754#H0:NoserialcorrelationStandardizedSquaredResiduals#statisticp-value#Lagl1.3650.2427#Lag2*(p+q)+(p+q)-l51.7810.6711#Lag4*(p+q)+(p+q)-l92.0510.8988#WeightedLjung-BoxTeston#d.o.f=2#WeightedARCHLMTests# #ARCH

19、Lag3# #ARCHLag5# #ARCHLag7#StatisticShapeScale0.59470.5002.0000.71501.4401.6670.81942.3151.543P-Value0.44060.81890.9411#Nyblomstabilitytest#JointStatistic:83.8698# #IndividualStatistics:# #mu0.1258# #omega8.1451# #alphal0.1628# #betal0.2932# # #ASymPtotiCCriticalValues(10%5%1%)# #JointStatistic:1.07

20、1.241.6# #IndividualStatistic:0.350.470.75# # #SignBiasTest# # #t-valueprobsig# #SignBias0.83000.4066# #NegativeSignBias0.00960.9923# #PositiveSignBias0.85000.3954#JointEffect#3.90340.2721#AdjustedPearsonGoodness-Of-Fit#groupstatisticp-value(g-l)#120134.12.473e-19#230178.12.286e-23#340156.35.577e-16

21、#450207.42.232e-21#Elapsedtime:0.686039yield=data3testfun(yield)C5O500WOO150)20002500TimeHistogramofyieldNormalQ-QPlot# #3arqueBeraTest# # #data:yield# #X-squared=1139.4,df=2p-value2.2e-16# # # #Box-Ljungtest# # #data:yield# #X-squared=1.7147,df=1,p-value=0.1904OLL152D 25303510Lag# #Warninginadf.tes

22、t(yield):p-valuesmallerthanprintedp-value# # #AugmentedDickey-FullerTest# # #data:yield# #Dickey-Fuller=-13.046,Lagorder=13,p-value=0.01# #alternativehypothesis:stationary# #Warninginpp.test(yield):p-valuesmallerthanprintedp-valueO5101520253035Lag# # #Phillips-PerronUnitRootTest# # #data:yield# #Dic

23、key-FullerZ(alpha)=-2592.1,Truncationlagparameter=9,# #p-value=0.01# #alternativehypothesis:stationary# # # #ARCHLM-test;Nullhypothesis:noARCHeffects# # #data:yield# #Chi-squared=186.82,df=12,p-valuetI)#mu-0.0002800.000409-0.685010.493340#omega0.0000030.0000022.046400.040717#alphal0.0407330.0043129.

24、446900.000000#betal0.9537840.004676203.976870.000000#RobustStandardErrors:tvalue-Pr(t)#Estimate0.71474#mu-0.000280Error0.932510.47477#omega0.0000030.0003928.216790.35107#alphal0.0407330.000004145.340660.00000#betal0.9537840.0049570.00000Std.0.006562#LogLikelihood:6305.272#InformationCriteria# # #Aka

25、ike-4.6989# #Bayes-4.6901# #Shibata-4.6989# #Hannan-Quinn-4.6958# #WeightedLjung-BoxTestonStandardizedResiduals# # #statisticp-value# #Lagl1.4870.2227# #Lag2*(p+q)+(p+q)-l22.7930.1596# #Lag4*(p+q)+(p+q)-l54.1670.2340# #d.o.f=0# #H0:Noserialcorrelation# # #WeightedLjung-BoxTestonstandardizedSquaredRe

26、siduals# # #statisticp-value# #Lagl0.22180.6377# #Lag2*(p+q)+(p+q)-l50.62450.9369# #Lag4*(p+q)+(p+q)-l91.21580.9755# #d.o.f=2# # #WeightedARCHLMTests# # # #ARCH Lag3# # ARCH Lag5# # ARCH Lag7# #Statistic0.003795ShapeScale P-Value0.500 2.000 0.95090.5585351.440 1.667 0.86620.8600152.315 1.5430.9352#

27、#Nyblomstabilitytest# # #JointStatistic:11.858# #IndividualStatistics:# #mu0.04612# #omega1.68786# #alphal0.21234# #betal0.13921# #AsymptoticCriticalValues(10%5%1%)# #3ointStatistic:1.071.241.6# #IndividualStatistic:0.350.470.75# # #SignBiasTest# # #t-valueprobsig# #SignBias0.508820.6109# #NegativeS

28、ignBias0.029040.9768# #PositiveSignBias0.956150.3391#JointEffect3.239740.3561# #AdjustedPearsonGoodness-of-FitTest:# #groupstatisticp-value(g-l)#120224.44.516e-37#230414.97.179e-70#340530.31.819e-87#450669.57.785e-110#Elapsedtime:0.5700321yield=data,4testfun(yield)TimeHistogramofyieldyieldNormalQ-QP

29、lot-3-2-10123TheoreticalQuantiIes# #3arqueBeraTest# # #data:yield# #X-squared=2657,df=2p-value2.2e-16# # # #Box-Ljungtest# # #data:yield# #X-squared=12.253,df=1,p-value=0.0004644CDOCD5101520253035Lag# #Warninginadf.test(yield):p-valuesmallerthanprintedp-value# # #AugmentedDickey-FullerTest# # #data:

30、yield# #Dickey-Fuller=-13.616,Lagorder=13,p-value=0.01# #alternativehypothesis:stationary# #Warninginpp.test(yield):p-valuesmallerthanprintedp-value# #Phillips-PerronUnitRootTest# # #data:yield# #Dickey-FullerZ(alpha)=-2410.8,Truncationlagparameter=9j# #p-value=0.01# #alternativehypothesis:stationar

31、y# # #ARCHLM-test;Nullhypothesis:noARCHeffects# # #data:yield# #Chi-squared=146.83,df=12jp-valuetI)#mu-0.00051750.000300-1.91510.055481#omega0.0000050.0000022.43740.014795#alphal0.0473470.00470810.05710.000000#betal0.9348780.006087153.58900.000000#RobustStandardErrors:#EstimateStd.ErrortvaluePr(tI)#

32、mu-0.0005750.000334-1.721940.085081#omega0.0000050.0000060.897570.369417#alphal0.0473470.0125443.774410.000160#betal0.9348780.01012192.368670.000000#LogLikelihood:7255.899#InformationCriteria#-#Akaike-5.4078#Bayes-5.3990#Shibata-5.4078#Hannan-Quinn-5.4046#WeightedLjung-BoxTestonStandardizedResiduals

33、#statisticp-value#Laglie.020.001547#Lag2*(p+q)+(p+q)-l2161.180.001714#Lag4*(p+q)+(p+q)-l511.340.004141#d.o.f=0#H0:Noserialcorrelation#WeightedLjung-BoxTestonStandardizedSquaredResiduals#statisticp-value#Lagl3.9520.04683#Lag2*(p+q)+(p+q)-l55.9390.09297#Lag4*(p+q)+(p+q)-l96.8330.21355#d.o.f=2#Weighted

34、ARCHLMTests在丑#StatisticShapeScaleP-Value#ARCHLag32.3210.5002.0000.1276#ARCHLag53.0691.4401.6670.2799#ARCHLag73.2102.3151.5430.4749#Nyblomstabilitytest#JointStatistic:1.5527# #IndividualStatistics:# #mu1.0709# #omega0.1964# #alphal0.1429# #betal0.1513# # #AsymptoticCriticalValues(10%5%1%)# #JointStat

35、istic:1.071.241.6# #IndividualStatistic:0.350.470.75# # #SignBiasTest# # #t-valueprobsig# #SignBias1.25450.2098# #NegativeSignBias0.96500.3346# #PositiveSignBias0.69060.4899# #JointEffect4.17510.2432# # # #AdjustedPearsonGoodness-of-FitTest:# #groupstatisticp-value(g-l)#12030.350.04752#23033.060.275

36、49#34042.380.32717#45053.610.30205# # # #Elapsedtime:0.742043# 3.利用得到的四组边缘分布,测度两两之间的相关性后,选择适宜检ULa函数,建立四元CopuLa函数,并检验拟合程度;y2-datahead(y2)#PoundJpanUsdEur#1-0.016689192-0.006422036-0.0041613040.001084608#20.0000000000.0059939300.000000000-0.034008741#30.000000000-0.0068502730.008322209-0.013969242#40.0125174950.0102750050.000000000-0.001120290#50.012513888-0.0072778770.020798548-0

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号