r語(yǔ)言garchcopulavar模型附代碼數(shù)據(jù)_第1頁(yè)
r語(yǔ)言garchcopulavar模型附代碼數(shù)據(jù)_第2頁(yè)
r語(yǔ)言garchcopulavar模型附代碼數(shù)據(jù)_第3頁(yè)
r語(yǔ)言garchcopulavar模型附代碼數(shù)據(jù)_第4頁(yè)
r語(yǔ)言garchcopulavar模型附代碼數(shù)據(jù)_第5頁(yè)
免費(fèi)預(yù)覽已結(jié)束,剩余24頁(yè)可下載查看

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、#數(shù)據(jù)處理思路#1,原始數(shù)據(jù)為4組時(shí)間序列;#讀取軟件包library(fGarch)library(quantmod)library(ghyp)library(copula)#設(shè)置工作目錄#讀取數(shù)據(jù)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#40.012

2、5174950.0102750050.000000000-0.001120290#50.012513888-0.0072778770.020798548-0.011676878#6-0.0083421910.0021406790.0124743500.007202157data=na.omit(data)#2.對(duì)每組數(shù)據(jù)進(jìn)行基本檢驗(yàn)(自回歸,異方差,自相關(guān),穩(wěn)定性,正態(tài)性)然后進(jìn)行ARCH(1,1)建模,得到四個(gè)邊緣分布;#自編函數(shù)進(jìn)行基本檢驗(yàn)testfun=function(yield)#繪制時(shí)序圖ts.plot(yield)#基本統(tǒng)計(jì)量summary(yield)sd(yield)var(

3、yield)# #/*偏度、峰度*/n-length(yield)m-mean(yield)s-sd(yield)g1-n/(n-1)*(n-2)*sum(yield-m)A3)/sA3g2-(n*(n+1)/(n-1)*(n-2)*(n-3)*sum(yield-m4)/sA4-(3*(n-1)A2)/(n-2)*(n-3)#偏度gi#峰度g2#/*作圖*/hist(yield,freq=F)lines(density(yield)#QQ圖(正態(tài)性)qqnorm(yield)qqline(yield)library(tseries)#/*JB檢驗(yàn)*/(檢驗(yàn)正態(tài)性)print(jarque.b

4、era.test(yield)# #/*自相關(guān)性檢驗(yàn)*/print(Box.test(yield,type=Ljung-Box)# 然后用自相關(guān)圖檢查序列的平穩(wěn)性,最后發(fā)現(xiàn)一階差分后的序列是平穩(wěn)的#檢驗(yàn)自相關(guān)偏相關(guān)系數(shù)acf(yield)pacf(yield)# 下面對(duì)平穩(wěn)性序列建立模型,偏相關(guān)系數(shù)在滯后1期后很快地趨向于0,所以取p=1,自相關(guān)系數(shù)圖形具有拖尾性,所以初步判斷為ar(1)模型#/*單位根檢驗(yàn)*/穩(wěn)定性檢驗(yàn)print(adf.test(yield)print(pp.test(yield)#/*ARCH-LM檢驗(yàn)2J果*/異方差檢驗(yàn)library(FinTS)print(Arch

5、Test(yield,lags=12,demean=FALSE)#建立/*GARCH*/模型library(fGarch);library(rugarch)#/*GARCH(1,1)-norm*/garch_norm-garchFit(yieldgarch(1,1),trace=FALSE)garch_normspec-ugarchspec(variance.model=list(garchOrder=c(1,1),mean.model=list(armaOrder=c(0,0)fit-ugarchfit(spec=spec,data=yield)fit# #對(duì)每一組數(shù)據(jù)進(jìn)行分析yield=d

6、ata,1testfun(yield)TimeHistogramofyieldHistogramofyieldNormalQ-QPlotNormalQ-QPlotino-3-2-10123TheoreticalQuaMiles#JarqueBeraTest#data:yield#X-squared=614.62,df=2,p-value2.2e-16#Box-Ljungtest#data:yield#X-squared=0.51149,df=1,p-value=0.4745roro-dER-dER(D(DSeriesyieldSeriesyield05101520253035#Warningi

7、nadf.test(yield):p-valuesmallerthanprintedp-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,Trunca

8、tionlagparameter=9,#p-value=0.01#alternativehypothesis:stationary#ARCHLM-test;Nullhypothesis:noARCHeffects#data:yield#Chi-squared=137.66,df=12,p-value|t|)#mu-0.0003060.000404-0.75660.44929#omega0.0000050.0000041.30700.19123#alpha10.0269570.0050415.34780.00000#beta10.9639890.002210436.18680.00000#Rob

9、ustStandardErrors:上。4 4rereEBEBCLCL53 3 30301 15 52 2 2020I I15Io1 11 15 51 1o o#EstimateStd.ErrortvaluePr(|t|)#mu-0.0003060.000430-0.711640.47669#omega0.0000050.0000250.189450.84974#alpha10.0269570.0312150.863590.38782#beta10.9639890.005525174.479640.00000#LogLikelihood:6477.686#InformationCriteria

10、#Akaike-4.8275#Bayes-4.8187#Shibata-4.8275#Hannan-Quinn-4.8243#WeightedLjung-BoxTestonStandardizedResiduals#statisticp-value#Lag10.008320.9273#Lag2*(p+q)+(p+q)-121.482040.3652#Lag4*(p+q)+(p+q)-154.833950.1668#d.o.f=0#H0:Noserialcorrelation#WeightedLjung-BoxTestonStandardizedSquaredResiduals#statisti

11、cp-value#Lag16.920.008522#Lag2*(p+q)+(p+q)-158.110.027672#Lag4*(p+q)+(p+q)-1911.590.022506#d.o.f=2#WeightedARCHLMTests#StatisticShapeScaleP-Value#ARCHLag30.29370.5002.0000.5878#ARCHLag52.03341.4401.6670.4639#ARCHLag75.60102.3151.5430.1704#Nyblomstabilitytest#JointStatistic:4.4761#IndividualStatistic

12、s:#mu0.32013#omega0.76021#alpha10.09171#beta10.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*#AdjustedPearson

13、Goodness-of-FitTest:#groupstatisticp-value(g-1)#120105.74.951e-14#230216.21.590e-30#340284.35.053e-39#450404.91.711e-57#Elapsedtime:0.784045yield=data,2testfun(yield)O OO O1 105001000150020002500TimeHistogramofyieldHistogramofyieldNormalQ-QPlotNormalQ-QPlot-3-2-10123TheoreticalQuantiles#JarqueBeraTe

14、st#data:yield#X-squared=622.46,df=2,p-value2.2e-16#Box-Ljungtest#data:yield#X-squared=8.6698,df=1,p-value=0.003235roro-dER-dER(D(DSeriesyieldSeriesyield05101520253035#Warninginadf.test(yield):p-valuesmallerthanprintedp-value#AugmentedDickey-FullerTest#data:yield#Dickey-Fuller=-13.404,Lagorder=13,p-v

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

16、esis:noARCHeffects#data:yield#Chi-squared=200.84,df=12,p-value|t|)#mu-0.0003780.000162-2.326060.020015#omega0.0000010.0000030.298290.765484#alpha10.0734540.0541461.356590.174911#beta10.9184890.05378717.076550.000000#RobustStandardErrors:#EstimateStd.ErrortvaluePr(|t|)#mu-0.0003780.004551-0.0830400.9

17、3382#omega0.0000010.0002240.0044030.99649#alpha10.0734543.6091320.0203520.98376#beta10.9184893.5989370.2552110.79856#LogLikelihood:8875.036#InformationCriteria#Akaike-6.6152#Bayes-6.6064#Shibata-6.6152#Hannan-Quinn-6.6121#WeightedLjung-BoxTestonStandardizedResiduals#statisticp-value#Lag11.6700.1963#

18、Lag2*(p+q)+(p+q)-122.1290.2422#Lag4*(p+q)+(p+q)-153.1790.3754#d.o.f=0#H0:Noserialcorrelation#WeightedLjung-BoxTestonStandardizedSquaredResiduals#statisticp-value#Lag11.3650.2427#Lag2*(p+q)+(p+q)-151.7810.6711#Lag4*(p+q)+(p+q)-192.0510.8988#d.o.f=2#WeightedARCHLMTests#StatisticShapeScaleP-Value#ARCHL

19、ag30.59470.5002.0000.4406#ARCHLag50.71501.4401.6670.8189#ARCHLag70.81942.3151.5430.9411#Nyblomstabilitytest#JointStatistic:83.8698#IndividualStatistics:#mu0.1258#omega8.1451#alpha10.1628#beta10.2932#AsymptoticCriticalValues(10%5%1%)#JointStatistic:1.071.241.6#IndividualStatistic:0.350.470.75#SignBia

20、sTest#t-valueprobsig#SignBias0.83000.4066#NegativeSignBias0.00960.9923#PositiveSignBias0.85000.3954#JointEffect3.90340.2721#AdjustedPearsonGoodness-of-FitTest:#groupstatisticp-value(g-1)#120134.12.473e-19#230178.12.286e-23#340156.35.577e-16#450207.42.232e-21#Elapsedtime:0.686039yield=data,3testfun(y

21、ield)TimeHistogramofyieldHistogramofyieldinNormalQ-QPlotNormalQ-QPlot-3-2-10123TheoreticalQuantiles#JarqueBeraTest#data:yield#X-squared=1139.4,df=2,p-value2.2e-16#Box-Ljungtest#data:yield#X-squared=1.7147,df=1,p-value=0.1904roro-dER-dER(D(DoToI I舄oSeriesyieldSeriesyield05101520253035#Warninginadf.te

22、st(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-valueLLLLOCDVciNooSenesyieldSenesyield101520253D35#Phillips-PerronUnitRootTest#data:yiel

23、d#Dickey-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-value|t|)#mu-0.0002800.000409-0.685010.493340#omega0.0000030.0000022.046400.040717#alpha10.0407330.0043129.446900.000

24、000#beta10.9537840.004676203.976870.000000#RobustStandardErrors:#EstimateStd.ErrortvaluePr(|t|)#mu-0.0002800.000392-0.714740.47477#omega0.0000030.0000040.932510.35107#alpha10.0407330.0049578.216790.00000#beta10.9537840.006562145.340660.00000#LogLikelihood:6305.272#InformationCriteria#Akaike-4.6989#B

25、ayes-4.6901#Shibata-4.6989#Hannan-Quinn-4.6958#WeightedLjung-BoxTestonStandardizedResiduals#statisticp-value#Lag11.4870.2227#Lag2*(p+q)+(p+q)-122.7930.1596#Lag4*(p+q)+(p+q)-154.1670.2340#d.o.f=0#H0:Noserialcorrelation#WeightedLjung-BoxTestonStandardizedSquaredResiduals#statisticp-value#Lag10.22180.6

26、377#Lag2*(p+q)+(p+q)-150.62450.9369#Lag4*(p+q)+(p+q)-191.21580.9755#d.o.f=2#WeightedARCHLMTests#StatisticShapeScaleP-Value#ARCHLag30.0037950.5002.0000.9509#ARCHLag50.5585351.4401.6670.8662#ARCHLag70.8600152.3151.5430.9352#IndividualStatistics:#mu0.04612#omega1.68786#alpha10.21234#beta10.13921#Asympt

27、oticCriticalValues(10%5%1%)#JointStatistic:1.071.241.6#IndividualStatistic:0.350.470.75#SignBiasTest#t-valueprobsig#SignBias0.508820.6109#NegativeSignBias0.029040.9768#PositiveSignBias0.956150.3391#JointEffect3.239740.3561#AdjustedPearsonGoodness-of-FitTest:#groupstatisticp-value(g-1)#120224.44.516e

28、-37#230414.97.179e-70#340530.31.819e-87#450669.57.785e-110#Elapsedtime:0.5700321yield=data,4testfun(yield)TimeHistogramofyieldHistogramofyieldd delely yNormalQ-QPlotNormalQ-QPlot-3-2-10123TheoreticalQuaritiles#JarqueBeraTest#data:yield#X-squared=265.7,df=2,p-value2.2e-16#Box-Ljungtest#data:yield#X-s

29、quared=12.253,df=1,p-value=0.0004644ino-ororo-dER-dER(D(DSenesyieldSenesyieldO O9匕二1一二一二十二二一卜:二-1二一卜-11一廠-105101520253035#Warninginadf.test(yield):p-valuesmallerthanprintedp-value#AugmentedDickey-FullerTest#data:yield#Dickey-Fuller=-13.616,Lagorder=13,p-value=0.01#alternativehypothesis:stationary#Wa

30、rninginpp.test(yield):p-valuesmallerthanprintedp-valueSenesyieldSenesyield05101520253D35Lag#Phillips-PerronUnitRootTest#data:yield#Dickey-FullerZ(alpha)=-2410.8,Truncationlagparameter=9,#p-value=0.01#alternativehypothesis:stationary#ARCHLM-test;Nullhypothesis:noARCHeffects#data:yield#Chi-squared=146

31、.83,df=12,p-value|t|)#mu-0.0005750.000300-1.91510.055481#omega0.0000050.0000022.43740.014795#alpha10.0473470.00470810.05710.000000#beta10.9348780.006087153.58900.000000#RobustStandardErrors:#EstimateStd.ErrortvaluePr(|t|)#mu-0.0005750.000334-1.721940.085081#omega0.0000050.0000060.897570.369417#alpha

32、10.0473470.0125443.774410.000160#beta10.9348780.01012192.368670.000000#LogLikelihood:7255.899#InformationCriteria#Akaike-5.4078#Bayes-5.3990#Shibata-5.4078#Hannan-Quinn-5.4046#WeightedLjung-BoxTestonStandardizedResiduals#statisticp-value#Lag110.020.001547#Lag2*(p+q)+(p+q)-1210.180.001714#Lag4*(p+q)+

33、(p+q)-1511.340.004141#d.o.f=0#H0:Noserialcorrelation#WeightedLjung-BoxTestonStandardizedSquaredResiduals#statisticp-value#Lag13.9520.04683#Lag2*(p+q)+(p+q)-155.9390.09297#Lag4*(p+q)+(p+q)-196.8330.21355#d.o.f=2#WeightedARCHLMTests#StatisticShapeScaleP-Value2.3210.5002.0000.12763.0691.4401.6670.27993

34、.2102.3151.5430.4749#ARCHLag3#ARCHLag5#ARCHLag7#IndividualStatistics:#mu1.0709#omega0.1964#alpha10.1429#beta10.1513#AsymptoticCriticalValues(10%5%1%)#JointStatistic:1.071.241.6#IndividualStatistic:0.350.470.75#SignBiasTest#t-valueprobsig#SignBias1.25450.2098#NegativeSignBias0.96500.3346#PositiveSign

35、Bias0.69060.4899#JointEffect4.17510.2432#AdjustedPearsonGoodness-of-FitTest:#groupstatisticp-value(g-1)#12030.350.04752#23033.060.27549#34042.380.32717#45053.610.30205#Elapsedtime:0.742043#3.利用得到的四組邊緣分布,測(cè)度兩兩之間的相關(guān)性后,選擇合適的Copula函數(shù),建立四元Copula函數(shù),并檢驗(yàn)擬合程度;y2-datahead(y2)#PoundJpanUsdEur#1-0.016689192-0.00

36、6422036-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.011676878#6-0.0083421910.0021406790.0124743500.007202157#2Ddistributionofyields:cdf-pobs(

37、y2)#測(cè)度兩兩之間的相關(guān)性plot(cdf)0.00.20.40.60.810Pound#建立四元Copula函數(shù)t.cop-tCopula(dim=4,param=0.5,df=2,df.fixed=TRUE)fit|z|)#rho.10.0044736140.0099021170.45178370.6514248#attr(,class)#1summary.fitCopula#4.利用四元Copula函數(shù),用MonteCarlo方法進(jìn)行VaR的估計(jì);#Monte-Carlo&VaR:N0-10000points_cop-rCopula(copula=fitcopula,N0)plot(points_cop,cex=0.2)0.00.20.40.60.810point

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論