黃川瑋同學

1 - (a)

ARMA-gjrGARCH-in-mean 在conditional 下的模型假設是 at | F t-1 ~ N(0,σt)。 為了建立合適的ARMA-gjrGARCH-in-mean模型,我先決定ARMA的order,再決定gjrGARCH-in-mean的order。

觀察ACF/PACF

rm(list=ls(all=TRUE))
library(quantmod)
library(rugarch)
library(ggplot2)
library(ggthemes)

start = "2013-01-01"
end = "2015-12-31"
ticker = "^GSPC"
Asset = getSymbols(ticker, from=start, to = end, auto.assign = FALSE)

Return = TTR::ROC(Ad(Asset),type="continuous")
Return = na.omit(Return)
colnames(Return) = "SP500return"
Return1 = Return[1:251]

DataSize = length(Return)
WindowSize = 251
OutSample = DataSize - WindowSize

acf(as.numeric(Return1))

pacf(as.numeric(Return1))

決定ARMA的order

關於決定ARMA的order 我用的方法是先觀察ACF與PACF,視ACF為Cut off 和PACF為Tail off,進而決定ARMA (p , q) ,再進一步確定ARMA的標準化殘差是否通過Ljung- Box檢定,我以p-value > 0.05為標準,意味著不拒絕Ho,則視為殘差為White noice。最後決定ARMA(0,0)。

ARMA_p = 0
ARMA_q = 0
spec1 = arfimaspec(mean.model = list(armaOrder = c(ARMA_p, ARMA_q), include.mean = TRUE),
                   distribution.model = "norm")
#個人傾向用第二種方法
modelfit1_1 = arfimafit(spec = spec1,
                      data=Return,
                      out.sample =OutSample,
                      solver = "hybrid",
                      solver.control = list(tol=1e-5, delta=1e-5, trace=1)
)
## 
## Iter: 1 fn: -896.3238     Pars:  0.0009308 0.0068054
## Iter: 2 fn: -896.3238     Pars:  0.0009308 0.0068054
## solnp--> Completed in 2 iterations
modelfit1_1
## 
## *----------------------------------*
## *          ARFIMA Model Fit        *
## *----------------------------------*
## Mean Model   : ARFIMA(0,0,0)
## Distribution : norm 
## 
## Optimal Parameters
## ------------------------------------
##        Estimate  Std. Error  t value Pr(>|t|)
## mu     0.000931    0.000430    2.167 0.030237
## sigma  0.006805    0.000304   22.408 0.000000
## 
## Robust Standard Errors:
##        Estimate  Std. Error  t value Pr(>|t|)
## mu     0.000931    0.000380   2.4473 0.014392
## sigma  0.006805    0.000493  13.7930 0.000000
## 
## LogLikelihood : 896.3238 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -7.1261
## Bayes        -7.0980
## Shibata      -7.1262
## Hannan-Quinn -7.1148
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      2.125  0.1449
## Lag[2*(p+q)+(p+q)-1][2]     2.144  0.2400
## Lag[4*(p+q)+(p+q)-1][5]     2.590  0.4869
## 
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic  p-value
## Lag[1]                      2.911 0.088004
## Lag[2*(p+q)+(p+q)-1][2]     6.090 0.020820
## Lag[4*(p+q)+(p+q)-1][5]    10.519 0.006771
## 
## 
## ARCH LM Tests
## ------------------------------------
##              Statistic DoF P-Value
## ARCH Lag[2]      8.255   2 0.01612
## ARCH Lag[5]     10.167   5 0.07065
## ARCH Lag[10]    11.204  10 0.34183
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  0.2254
## Individual Statistics:             
## mu    0.03074
## sigma 0.19826
## 
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic:          0.61 0.749 1.07
## Individual Statistic:     0.35 0.47 0.75
## 
## 
## Elapsed time : 0.8103819

決定gjrGARCH-in-mean的order

進一步決定ARMA-gjrGARCH-in-mean的order,我以ARMA(0, 0)為基礎再加上gjrGARCH-in-mean(q, p) 的order,採用方法為窮舉法,gjrGARCH-in-mean (1,0) => gjrGARCH-in-mean (0, 1) =>gjrGARCH-in-mean(1,1) … 直到標準化殘差的平方通過Ljung- Box檢定,我以p-value > 0.05為標準,意味著不拒絕Ho,則視為殘差平方為White noice。雖然gjrGARCH-in-mean(1,0)通過Ljung- Box檢定,但因為不符合第(b)小題探討風險溢酬,於是往下做了幾個模型,最後決定通過Ljung- Box檢定的gjrGARCH-in-mean(1,1)。

ARMA_p = 0
ARMA_q = 0
GARCH_q = 1
GARCH_p = 0

spec2_1 = ugarchspec(mean.model=list(armaOrder=c(ARMA_p,ARMA_q), include.mean=TRUE,
                                     archm=TRUE,
                                     archpow=1,
                                     external.regressors=NULL,
                                     archex=FALSE),
                     variance.model=list(model="sGARCH", garchOrder=c(GARCH_q,GARCH_p)),
                     distribution.model="norm")
modelfit2_1 = ugarchfit(spec=spec2_1, 
                        data=Return$SP500return, 
                        out.sample=OutSample, 
                        solver="hybrid",
                        solver.control=list(tol=1e-5, delta=1e-5, trace=1)
)
## 
## Iter: 1 fn: -887.9373     Pars:   0.00355699 -0.37053015  0.00002344  0.99899893
## Iter: 2 fn: -887.9373     Pars:   0.00355695 -0.37052415  0.00002344  0.99899893
## solnp--> Completed in 2 iterations
modelfit2_1 
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : sGARCH(1,0)
## Mean Model   : ARFIMA(0,0,0)
## Distribution : norm 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.003557    0.001803  1.97230 0.048575
## archm  -0.370524    0.311691 -1.18876 0.234536
## omega   0.000023    0.000008  2.97170 0.002962
## alpha1  0.998999    1.050647  0.95084 0.341685
## 
## Robust Standard Errors:
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.003557    0.005999  0.59288  0.55326
## archm  -0.370524    1.079349 -0.34329  0.73138
## omega   0.000023    0.000029  0.81782  0.41346
## alpha1  0.998999    3.896546  0.25638  0.79766
## 
## LogLikelihood : 887.9373 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -7.0433
## Bayes        -6.9871
## Shibata      -7.0438
## Hannan-Quinn -7.0207
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      1.520  0.2176
## Lag[2*(p+q)+(p+q)-1][2]     1.604  0.3379
## Lag[4*(p+q)+(p+q)-1][5]     2.507  0.5043
## d.o.f=0
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      4.028 0.04475
## Lag[2*(p+q)+(p+q)-1][2]     4.116 0.07016
## Lag[4*(p+q)+(p+q)-1][5]     5.312 0.12999
## d.o.f=1
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[2]    0.1738 0.500 2.000  0.6768
## ARCH Lag[4]    1.5439 1.397 1.611  0.5503
## ARCH Lag[6]    1.8065 2.222 1.500  0.7237
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  5.6591
## Individual Statistics:              
## mu     0.03541
## archm  0.09270
## omega  0.39048
## alpha1 1.80548
## 
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic:          1.07 1.24 1.6
## Individual Statistic:     0.35 0.47 0.75
## 
## Sign Bias Test
## ------------------------------------
##                    t-value    prob sig
## Sign Bias            0.290 0.77203    
## Negative Sign Bias   1.712 0.08821   *
## Positive Sign Bias   2.012 0.04531  **
## Joint Effect         7.723 0.05209   *
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     25.25       0.1523
## 2    30     29.52       0.4383
## 3    40     44.94       0.2372
## 4    50     50.00       0.4336
## 
## 
## Elapsed time : 1.606733
# 利用 spec2_1 的參數估計做為 spec2_2 的 starting value.
spec2_2 = ugarchspec(mean.model=list(armaOrder=c(ARMA_p,ARMA_q), include.mean=TRUE,
                                     archm=TRUE,
                                     archpow=1,
                                     external.regressors=NULL,
                                     archex=FALSE),
                     variance.model=list(model="gjrGARCH", garchOrder=c(GARCH_q,GARCH_p)),
                     start.pars=list(mu=0.003557, archm=-0.370524, omega=0.000023, alpha1=0.998999),
                     distribution.model="norm")
# start.pars
# List of staring parameters for the optimization routine. 
# These are not usually required unless the optimization has problems converging.

modelfit2_2 = ugarchfit(spec=spec2_2, 
                        data=Return$SP500return, 
                        out.sample=OutSample, 
                        #solver="hybird",
                        solver.control=list(tol=1e-5, delta=1e-5, trace=1)
)
## 
## Iter: 1 fn: -890.5601     Pars:   0.00234929 -0.14946106  0.00002696  0.99899759 -0.42970735
## Iter: 2 fn: -890.5601     Pars:   0.00234929 -0.14946106  0.00002696  0.99899759 -0.42970735
## solnp--> Completed in 2 iterations
modelfit2_2
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : gjrGARCH(1,0)
## Mean Model   : ARFIMA(0,0,0)
## Distribution : norm 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.002349    0.001058  2.22131  0.02633
## archm  -0.149461    0.116709 -1.28063  0.20033
## omega   0.000027    0.000004  7.15347  0.00000
## alpha1  0.998998    0.615499  1.62307  0.10458
## gamma1 -0.429707    0.628267 -0.68396  0.49400
## 
## Robust Standard Errors:
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.002349    0.001407  1.66968 0.094984
## archm  -0.149461    0.253561 -0.58945 0.555561
## omega   0.000027    0.000006  4.59788 0.000004
## alpha1  0.998998    0.783324  1.27533 0.202192
## gamma1 -0.429707    0.842029 -0.51032 0.609825
## 
## LogLikelihood : 890.5601 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -7.0563
## Bayes        -6.9860
## Shibata      -7.0570
## Hannan-Quinn -7.0280
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      1.236  0.2663
## Lag[2*(p+q)+(p+q)-1][2]     1.252  0.4232
## Lag[4*(p+q)+(p+q)-1][5]     2.158  0.5817
## d.o.f=0
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      3.069 0.07979
## Lag[2*(p+q)+(p+q)-1][2]     3.070 0.13429
## Lag[4*(p+q)+(p+q)-1][5]     4.858 0.16480
## d.o.f=1
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[2]  0.002629 0.500 2.000  0.9591
## ARCH Lag[4]  2.174855 1.397 1.611  0.4028
## ARCH Lag[6]  2.465319 2.222 1.500  0.5784
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  5.4886
## Individual Statistics:              
## mu     0.06202
## archm  0.09937
## omega  0.33431
## alpha1 0.43211
## gamma1 0.04642
## 
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic:          1.28 1.47 1.88
## Individual Statistic:     0.35 0.47 0.75
## 
## Sign Bias Test
## ------------------------------------
##                    t-value    prob sig
## Sign Bias            1.152 0.25051    
## Negative Sign Bias   1.756 0.08033   *
## Positive Sign Bias   1.419 0.15704    
## Joint Effect         8.115 0.04369  **
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     23.98      0.19692
## 2    30     34.30      0.22849
## 3    40     49.08      0.12931
## 4    50     69.12      0.03063
## 
## 
## Elapsed time : 0.2535689
ARMA_p = 0
ARMA_q = 0
GARCH_q = 0
GARCH_p = 1

spec3 = ugarchspec(mean.model=list(armaOrder=c(ARMA_p,ARMA_q), include.mean=TRUE,
                                   archm=TRUE,
                                   archpow=1,
                                   external.regressors=NULL,
                                   archex=FALSE),
                   variance.model=list(model="gjrGARCH", garchOrder=c(GARCH_q,GARCH_p)),
                   distribution.model="norm")
modelfit3 = ugarchfit(spec=spec3, 
                      data=Return$SP500return, 
                      out.sample=OutSample, 
                      solver="hybrid",
                      solver.control=list(tol=1e-5, delta=1e-5, trace=1)
)
## 
## Iter: 1 fn: -896.0366     Pars:   4.373e-03 -5.071e-01  9.721e-11  9.982e-01
## Iter: 2 fn: -896.0366     Pars:   4.373e-03 -5.071e-01  9.721e-11  9.982e-01
## solnp--> Completed in 2 iterations
modelfit3
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : gjrGARCH(0,1)
## Mean Model   : ARFIMA(0,0,0)
## Distribution : norm 
## 
## Optimal Parameters
## ------------------------------------
##        Estimate  Std. Error     t value Pr(>|t|)
## mu     0.004373    0.000115   37.929851  0.00000
## archm -0.507096    0.043345  -11.698976  0.00000
## omega  0.000000    0.000001    0.000152  0.99988
## beta1  0.998153    0.000363 2748.374634  0.00000
## 
## Robust Standard Errors:
##        Estimate  Std. Error    t value Pr(>|t|)
## mu     0.004373    0.001231   3.553145 0.000381
## archm -0.507096    0.042095 -12.046607 0.000000
## omega  0.000000    0.000011   0.000009 0.999993
## beta1  0.998153    0.001509 661.306877 0.000000
## 
## LogLikelihood : 896.0366 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -7.1079
## Bayes        -7.0517
## Shibata      -7.1084
## Hannan-Quinn -7.0853
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      1.484  0.2232
## Lag[2*(p+q)+(p+q)-1][2]     1.509  0.3588
## Lag[4*(p+q)+(p+q)-1][5]     1.971  0.6253
## d.o.f=0
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      2.194 0.13855
## Lag[2*(p+q)+(p+q)-1][2]     4.623 0.05130
## Lag[4*(p+q)+(p+q)-1][5]     8.552 0.02146
## d.o.f=1
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[2]     4.782 0.500 2.000 0.02876
## ARCH Lag[4]     7.339 1.397 1.611 0.02330
## ARCH Lag[6]     8.649 2.222 1.500 0.02914
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  56.5969
## Individual Statistics:              
## mu     0.06838
## archm  0.05339
## omega 37.10437
## beta1  0.21646
## 
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic:          1.07 1.24 1.6
## Individual Statistic:     0.35 0.47 0.75
## 
## Sign Bias Test
## ------------------------------------
##                    t-value    prob sig
## Sign Bias           0.8021 0.42328    
## Negative Sign Bias  1.9191 0.05612   *
## Positive Sign Bias  0.4714 0.63777    
## Joint Effect        9.5113 0.02321  **
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     17.76       0.5382
## 2    30     35.02       0.2040
## 3    40     40.79       0.3916
## 4    50     53.18       0.3163
## 
## 
## Elapsed time : 0.478941

ARMA(0,0)-gjrGARCH(1,1)-in-mean模型

合適的ARMA-gjrGARCH-in-mean模型

ARMA_p = 0
ARMA_q = 0
GARCH_q = 1
GARCH_p = 1

spec4 = ugarchspec(mean.model=list(armaOrder=c(ARMA_p,ARMA_q), include.mean=TRUE,
                                   archm=TRUE,
                                   archpow=1,
                                   external.regressors=NULL,
                                   archex=FALSE),
                   variance.model=list(model="gjrGARCH", garchOrder=c(GARCH_q,GARCH_p)),
                   distribution.model="norm")
modelfit4 = ugarchfit(spec=spec4, 
                      data=Return$SP500return, 
                      out.sample=OutSample, 
                      solver="hybrid",
                      solver.control=list(tol=1e-5, delta=1e-5, trace=1)
)
## 
## Iter: 1 fn: -895.9343     Pars:  -7.798e-04  2.507e-01  5.738e-13  1.141e-02  9.645e-01  4.319e-02
## Iter: 2 fn: -895.9346     Pars:  -7.752e-04  2.501e-01  2.915e-13  1.141e-02  9.645e-01  4.319e-02
## solnp--> Completed in 2 iterations
modelfit4
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : gjrGARCH(1,1)
## Mean Model   : ARFIMA(0,0,0)
## Distribution : norm 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error   t value Pr(>|t|)
## mu     -0.000775    0.009385 -0.082604  0.93417
## archm   0.250111    1.381789  0.181005  0.85636
## omega   0.000000    0.000001  0.000000  1.00000
## alpha1  0.011406    0.105506  0.108108  0.91391
## beta1   0.964526    0.030918 31.196764  0.00000
## gamma1  0.043193    0.127350  0.339164  0.73449
## 
## Robust Standard Errors:
##         Estimate  Std. Error   t value Pr(>|t|)
## mu     -0.000775    0.055732 -0.013910  0.98890
## archm   0.250111    8.219461  0.030429  0.97572
## omega   0.000000    0.000004  0.000000  1.00000
## alpha1  0.011406    0.606068  0.018820  0.98498
## beta1   0.964526    0.166883  5.779645  0.00000
## gamma1  0.043193    0.767090  0.056307  0.95510
## 
## LogLikelihood : 895.9346 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -7.0911
## Bayes        -7.0068
## Shibata      -7.0922
## Hannan-Quinn -7.0572
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      3.764 0.05237
## Lag[2*(p+q)+(p+q)-1][2]     3.768 0.08703
## Lag[4*(p+q)+(p+q)-1][5]     4.143 0.23672
## d.o.f=0
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      1.047  0.3063
## Lag[2*(p+q)+(p+q)-1][5]     5.233  0.1355
## Lag[4*(p+q)+(p+q)-1][9]     7.237  0.1801
## d.o.f=2
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[3]     4.249 0.500 2.000 0.03927
## ARCH Lag[5]     4.507 1.440 1.667 0.13344
## ARCH Lag[7]     5.669 2.315 1.543 0.16509
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  67.3356
## Individual Statistics:               
## mu      0.08733
## archm   0.09145
## omega  22.95788
## alpha1  0.15562
## beta1   0.15308
## gamma1  0.12764
## 
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic:          1.49 1.68 2.12
## Individual Statistic:     0.35 0.47 0.75
## 
## Sign Bias Test
## ------------------------------------
##                    t-value   prob sig
## Sign Bias           1.0462 0.2965    
## Negative Sign Bias  0.8947 0.3718    
## Positive Sign Bias  0.5244 0.6005    
## Joint Effect        4.5390 0.2088    
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     29.88      0.05339
## 2    30     44.10      0.03591
## 3    40     54.18      0.05379
## 4    50     60.35      0.12820
## 
## 
## Elapsed time : 0.6647501

1 - (b)

Rolling 過程(暫時省略,因為花時間很久)

#rollingx = ugarchroll(spec=spec4,
#                    data=Return$SP500return,
#                    n.ahead=1,
#                    forecast.length=OutSample,
#                    refit.every=1,
#                    refit.window="moving",
#                    solver="hybrid",
#                    solver.control=list(tol=1e-5,delta=1e-5,trace=1),
#                    calculate.VaR = TRUE,
#                    VaR.alpha = c(0.01,0.05),
#                    parallel=TRUE,
#                    parallel.control = list(pkg=c("snowfall"), cores=4),
#                    keep.coef=TRUE)
#rollingx = resume(rollingx, solver="gosolnp")
#convergence(rollingx)
load("c:/temp/rollingx.RData")
rollingx@model$coef[[1]]$coef
##             Estimate   Std. Error       t value     Pr(>|t|)
## mu     -7.752388e-04 5.573245e-02 -1.391001e-02 9.889018e-01
## archm   2.501112e-01 8.219461e+00  3.042915e-02 9.757248e-01
## omega   2.915273e-13 4.162322e-06  7.003959e-08 9.999999e-01
## alpha1  1.140600e-02 6.060677e-01  1.881968e-02 9.849850e-01
## beta1   9.645262e-01 1.668833e-01  5.779645e+00 7.485849e-09
## gamma1  4.319263e-02 7.670900e-01  5.630713e-02 9.550971e-01
Return_b = Return
Return_b$criteria = NA
Return_b$criteria = 0.05

Return_b$model_archm = NA
for (i in WindowSize:(DataSize-1)){
  Return_b$model_archm[i] = rollingx@model$coef[[i+1-WindowSize]]$coef[2,1]
}

Return_b$model_archm_pvalue = NA
for (i in WindowSize:(DataSize-1)){
  Return_b$model_archm_pvalue[i] = rollingx@model$coef[[i+1-WindowSize]]$coef[2,4]
}

Return_b$model_gamma = NA
for (i in WindowSize:(DataSize-1)){
  Return_b$model_gamma[i] = rollingx@model$coef[[i+1-WindowSize]]$coef[6,1]
}

Return_b$model_gamma_pvalue = NA
for (i in WindowSize:(DataSize-1)){
  Return_b$model_gamma_pvalue[i] = rollingx@model$coef[[i+1-WindowSize]]$coef[6,4]
}

Return_b$ForecastMu[(WindowSize+1):DataSize]=rollingx@forecast$density$Mu
Return_b$ForecastSigma[(WindowSize+1):DataSize]=rollingx@forecast$density$Sigma
Return_b_1 = data.frame(date = index(Return_b), coredata(Return_b))

是否存在風險溢酬?

從「風險溢酬對SP500報酬的影響 與 顯著性(rolling)」圖可以觀察,從2014年初到2015年底的參數估計的p-value幾乎都是高於0.05,意味著風險溢酬對SP500報酬率不顯著影響。由於第一筆估計參數是由前251筆資料估計出來的,我們將推論的時間往前推251天,從2013年初到2015年底對S&P500不存在顯著的風險溢酬影響。

plot1_1 = ggplot(Return_b_1, aes(x=date, y=model_archm)) +
  geom_line() + 
  xlab("")+
  scale_x_date(date_labels = "%Y %b %d")+ ggtitle("風險溢酬對SP500報酬的影響 與 顯著性_rolling")+
  theme_economist() + scale_colour_economist()


plot1_2 = ggplot(Return_b_1, aes(x=date, y=model_archm_pvalue)) +
  geom_line() + 
  xlab("")+
  scale_x_date(date_labels = "%Y %b %d")+
  geom_line(aes(y=criteria),colour="red")+
  theme_economist(stata=TRUE) + scale_colour_economist(stata=TRUE)

library(gridExtra)
grid.arrange(plot1_1,plot1_2,nrow=2,ncol=1)

是否存在波動不對稱?

從「波動不對稱性對SP500報酬的影響 與 顯著性(rolling)」圖可以觀察,從2014年初到2015年8月底的參數估計的p-value幾乎都是高於0.05,意味著波動不對稱對SP500報酬率不顯著;但從2015年9月初到2015年底的參數估計的p-value幾乎都是低於0.05,意味著波動不對稱對SP500報酬率顯著。由於第一筆估計參數是由前251筆資料估計出來的,我們將推論的時間往前推251天,從2013年初到2014年8月底對S&P500不存在顯著的波動不對稱影響,但從2014年9月初到2015年底對S&P500存在顯著的波動不對稱影響,且影響的程度大約介於0.2與0.5之間,意味著波動不對稱增加1單位對S&P500報酬平均增加0.2到0.5單位之間。

plot2_1 = ggplot(Return_b_1, aes(x=date, y=model_gamma)) +
  geom_line() + 
  xlab("")+
  scale_x_date(date_labels = "%Y %b %d")+ ggtitle("波動不對稱性對SP500報酬的影響 與 顯著性_rolling")+
  theme_economist() + scale_colour_economist()


plot2_2 = ggplot(Return_b_1, aes(x=date, y=model_gamma_pvalue)) +
  geom_line() + 
  xlab("")+
  scale_x_date(date_labels = "%Y %b %d")+
  geom_line(aes(y=criteria),colour="red")+
  theme_economist(stata=TRUE) + scale_colour_economist(stata=TRUE)

library(gridExtra)
grid.arrange(plot2_1,plot2_2,nrow=2,ncol=1)

S&P500報酬 與 ForecastMu, ForecastSigma關係_rolling

從平均日報酬預測,在2015年7/8月以前日報酬是較平穩的,大約介於-0.001與0.002之間,在2015年7/8月以後日報酬先是較不平穩之後慢慢平緩,大約介於-0.003與0.002之間; 從平均波動預測,在2015年7/8月以前波動是較平穩的,大約介於0.005與0.015之間,在2015年7/8月以後波動先是較不平穩之後慢慢平緩,大約介於0.005與0.03之間。 同時察覺平均日報酬與平均波動預測來看,平均日報酬與平均波動在2015年7/8月以前較穩定的,但在之後先是不穩定再慢慢穩定,意味著其實日報酬變動幅度會受波動影響且是正向影響,波動越大日報酬變動幅度也越大。

plot3_1 = ggplot(Return_b_1, aes(x=date, y=ForecastMu)) +
  geom_line() + 
  xlab("")+
  scale_x_date(date_labels = "%Y %b %d")+
  ggtitle("S&P500報酬 與 ForecastMu關係_rolling")

plot3_2 = ggplot(Return_b_1, aes(x=date, y=ForecastSigma)) +
  geom_line() + 
  xlab("")+
  scale_x_date(date_labels = "%Y %b %d")+
  ggtitle("S&P500報酬 與 ForecastSigma 關係_rolling")
library(gridExtra)
grid.arrange(plot3_1,plot3_2,nrow=2,ncol=1)

1 - (c)

Return= TTR::ROC(Ad(Asset),type="continuous")
Return_c = cbind(Return, Asset[,5])
colnames(Return_c) = c("SP500return", "Volume")
Return_c$Volume_lag1 = lag(Return_c$Volume,1)
Return_c = na.omit(Return_c)

Regressor.mean = as.matrix(Return_c$Volume_lag1)
Regressor.variance = as.matrix(cbind((Return_c$Volume_lag1)^2))

決定ARMA的order

關於決定有解釋變數的ARMA的order 我用的(b)小題的結論ARMA(0,0) ,再進一步確定ARMA的標準化殘差是否通過Ljung- Box檢定,我以p-value > 0.05為標準,意味著不拒絕Ho,則視為殘差為White noice。最後決定ARMA(0,0)。

ARMA_p = 0
ARMA_q = 0
spec5 = arfimaspec(mean.model = list(armaOrder = c(ARMA_p, ARMA_q), include.mean = TRUE,
                                     external.regressors=Regressor.mean),
                   distribution.model = "norm")
modelfit5 = arfimafit(spec = spec5,
                      data=Return_c$SP500,
                      out.sample =OutSample,
                      solver = "hybrid",
                      solver.control = list(tol=1e-5, delta=1e-5, trace=1)
)
## 
## Iter: 1 fn: -896.4561     Pars:  -4.564e-04  4.132e-13  6.820e-03
## solnp--> Completed in 1 iterations
modelfit5
## 
## *----------------------------------*
## *          ARFIMA Model Fit        *
## *----------------------------------*
## Mean Model   : ARFIMA(0,0,0)
## Distribution : norm 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error   t value Pr(>|t|)
## mu     -0.000456    0.000430 -1.060304  0.28901
## mxreg1  0.000000    0.000000  0.000006  0.99999
## sigma   0.006820    0.000306 22.320396  0.00000
## 
## Robust Standard Errors:
##         Estimate  Std. Error   t value Pr(>|t|)
## mu     -0.000456    0.000382 -1.193294  0.23275
## mxreg1  0.000000    0.000000  0.003457  0.99724
## sigma   0.006820    0.000496 13.757448  0.00000
## 
## LogLikelihood : 896.4561 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -7.1192
## Bayes        -7.0770
## Shibata      -7.1195
## Hannan-Quinn -7.1022
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      1.902  0.1678
## Lag[2*(p+q)+(p+q)-1][2]     1.909  0.2783
## Lag[4*(p+q)+(p+q)-1][5]     2.354  0.5375
## 
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic  p-value
## Lag[1]                      2.383 0.122671
## Lag[2*(p+q)+(p+q)-1][2]     6.074 0.021025
## Lag[4*(p+q)+(p+q)-1][5]    10.786 0.005775
## 
## 
## ARCH LM Tests
## ------------------------------------
##              Statistic DoF P-Value
## ARCH Lag[2]      8.836   2 0.01206
## ARCH Lag[5]     10.722   5 0.05717
## ARCH Lag[10]    12.037  10 0.28262
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  0.341
## Individual Statistics:              
## mu     0.03336
## mxreg1     NaN
## sigma  0.19440
## 
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic:          0.846 1.01 1.35
## Individual Statistic:     0.35 0.47 0.75
## 
## 
## Elapsed time : 0.3082778

決定gjrGARCH-in-mean的order

進一步決定有解釋變數ARMA-gjrGARCH-in-mean的order,我以ARMA(0, 0)為基礎再加上gjrGARCH-in-mean(q, p) 的order,採用方法為窮舉法,gjrGARCH-in-mean (1,0) => gjrGARCH-in-mean (0, 1) =>gjrGARCH-in-mean(1,1) … 直到標準化殘差的平方通過Ljung- Box檢定,我以p-value > 0.05為標準,意味著不拒絕Ho,則視為殘差平方為White noice。然而在此遇到無法收斂問題的錯誤訊號,故需要面對此問題。

ARMA_p = 0
ARMA_q = 0
GARCH_q = 1
GARCH_p = 0
spec6_1 = ugarchspec(mean.model = list(armaOrder=c(ARMA_p,ARMA_q),
                                     include.mean=TRUE,
                                     archm=TRUE,
                                     archpow=1,
                                     external.regressors=Regressor.mean,
                                     archex=FALSE),
                   variance.model=list(model="sGARCH",
                                       garchOrder=c(GARCH_q ,GARCH_p),
                                       submodel=NULL,
                                       external.regressors=Regressor.variance,
                                       variance.targeting=FALSE),
                   distribution.model="norm")
#modelfit6_1 = ugarchfit(spec=spec6_1, data=Return_c$SP500, 
 #                       out.sample=OutSample, 
  #                      solver="hybird",
   #                     solver.control=list(tol=1e-5, delta=1e-5, trace=1)
#)
#modelfit6_1

spec6_2 = ugarchspec(mean.model = list(armaOrder=c(ARMA_p,ARMA_q),
                                       include.mean=TRUE,
                                       archm=TRUE,
                                       archpow=1,
                                       external.regressors=Regressor.mean,
                                       archex=FALSE),
                     variance.model=list(model="gjrGARCH",
                                         garchOrder=c(GARCH_q ,GARCH_p),
                                         submodel=NULL,
                                         external.regressors=Regressor.variance,
                                         variance.targeting=FALSE),
                     start.pars=list(mu=0.005487, archm=0.161375,mxreg1 = 0.000000, omega=0.000000, alpha1=0.050001),
                     distribution.model="norm")
#modelfit6_2 = ugarchfit(spec=spec6_2, data=Return_c$SP500, 
 #                       out.sample=OutSample, 
  #                      solver="hybird",
   #                     solver.control=list(tol=1e-5, delta=1e-5, trace=1)
#)
#modelfit6_2

解決不收斂問題

由於不收斂 => 正規化Volume ,同除1000000000000

Return= TTR::ROC(Ad(Asset),type="continuous")
Return_c = cbind(Return, Asset[,5])
colnames(Return_c) = c("SP500return", "Volume")
Return_c$Volume_lag1 = lag(Return_c$Volume,1)

Return_c$NewVolume =  Return_c$Volume/1000000000000
Return_c$NewVolume_lag1 = lag(Return_c$NewVolume,1)

Return_c = na.omit(Return_c)

Regressor.mean = as.matrix(Return_c$NewVolume_lag1)
Regressor.variance = as.matrix(cbind((Return_c$NewVolume_lag1)^2))

重新決定ARMA的order

關於重新決定有解釋變數的ARMA的order 我用的(b)小題的結論ARMA(0,0) ,再進一步確定ARMA的標準化殘差是否通過Ljung- Box檢定,我以p-value > 0.05為標準,意味著不拒絕Ho,則視為殘差為White noice。最後決定ARMA(0,0)。

ARMA_p = 0
ARMA_q = 0
spec7 = arfimaspec(mean.model = list(armaOrder = c(ARMA_p, ARMA_q), include.mean = TRUE,
                                     external.regressors=Regressor.mean),
                   distribution.model = "norm")
modelfit7 = arfimafit(spec = spec7,
                      data=Return_c$SP500,
                      out.sample =OutSample,
                      solver = "hybrid",
                      solver.control = list(tol=1e-5, delta=1e-5, trace=1)
)
## 
## Iter: 1 fn: -896.4561     Pars:  -0.0004584  0.4131562  0.0068195
## solnp--> Completed in 1 iterations
modelfit7
## 
## *----------------------------------*
## *          ARFIMA Model Fit        *
## *----------------------------------*
## Mean Model   : ARFIMA(0,0,0)
## Distribution : norm 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error  t value Pr(>|t|)
## mu     -0.000458    0.002726 -0.16814  0.86647
## mxreg1  0.413156    0.800412  0.51618  0.60573
## sigma   0.006820    0.000306 22.32087  0.00000
## 
## Robust Standard Errors:
##         Estimate  Std. Error  t value Pr(>|t|)
## mu     -0.000458    0.002643 -0.17341  0.86233
## mxreg1  0.413156    0.772629  0.53474  0.59283
## sigma   0.006820    0.000496 13.75766  0.00000
## 
## LogLikelihood : 896.4561 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -7.1192
## Bayes        -7.0770
## Shibata      -7.1195
## Hannan-Quinn -7.1022
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      1.902  0.1678
## Lag[2*(p+q)+(p+q)-1][2]     1.909  0.2783
## Lag[4*(p+q)+(p+q)-1][5]     2.354  0.5375
## 
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic  p-value
## Lag[1]                      2.383 0.122701
## Lag[2*(p+q)+(p+q)-1][2]     6.073 0.021039
## Lag[4*(p+q)+(p+q)-1][5]    10.785 0.005778
## 
## 
## ARCH LM Tests
## ------------------------------------
##              Statistic DoF P-Value
## ARCH Lag[2]      8.834   2 0.01207
## ARCH Lag[5]     10.722   5 0.05718
## ARCH Lag[10]    12.039  10 0.28247
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  0.3414
## Individual Statistics:              
## mu     0.03284
## mxreg1 0.04096
## sigma  0.19447
## 
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic:          0.846 1.01 1.35
## Individual Statistic:     0.35 0.47 0.75
## 
## 
## Elapsed time : 0.008004904

重新決定gjrGARCH-in-mean的order

進一步決定ARMA-gjrGARCH-in-mean的order,我以ARMA(0, 0)為基礎再加上gjrGARCH-in-mean(q, p) 的order,採用方法為窮舉法,gjrGARCH-in-mean (1,0) => gjrGARCH-in-mean (0, 1) =>gjrGARCH-in-mean(1,1) … 直到標準化殘差的平方通過Ljung- Box檢定,我以p-value > 0.05為標準,意味著不拒絕Ho,則視為殘差平方為White noice。雖然gjrGARCH-in-mean(1,0)通過Ljung- Box檢定,但因為不符合第(b)小題探討風險溢酬,於是往下做了幾個模型,最後決定通過Ljung- Box檢定的gjrGARCH-in-mean(1,1)。

ARMA_p = 0
ARMA_q = 0
GARCH_q = 1
GARCH_p = 0
spec8_1 = ugarchspec(mean.model = list(armaOrder=c(ARMA_p,ARMA_q),
                                       include.mean=TRUE,
                                       archm=TRUE,
                                       archpow=1,
                                       external.regressors=Regressor.mean,
                                       archex=FALSE),
                     variance.model=list(model="sGARCH",
                                         garchOrder=c(GARCH_q ,GARCH_p),
                                         submodel=NULL,
                                         external.regressors=Regressor.variance,
                                         variance.targeting=FALSE),
                     distribution.model="norm")
modelfit8_1 = ugarchfit(spec=spec8_1, data=Return_c$SP500,
                        out.sample=OutSample,
                        solver="hybrid",
                        solver.control=list(tol=1e-5, delta=1e-5, trace=1))
## 
## Iter: 1 fn: -893.2507     Pars:   0.00287760321 -1.20149266349  1.59093714356  0.00003282769  0.17567117421  0.00000004033
## Iter: 2 fn: -893.2507     Pars:   0.00287760321 -1.20149266349  1.59093714356  0.00003282769  0.17567117421  0.00000004033
## solnp--> Completed in 2 iterations
modelfit8_1
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : sGARCH(1,0)
## Mean Model   : ARFIMA(0,0,0)
## Distribution : norm 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.002878    0.003203  0.89846 0.368940
## archm  -1.201493    0.559058 -2.14914 0.031623
## mxreg1  1.590937    0.259540  6.12985 0.000000
## omega   0.000033    0.000006  5.63068 0.000000
## alpha1  0.175671    0.105981  1.65757 0.097405
## vxreg1  0.000000    0.111496  0.00000 1.000000
## 
## Robust Standard Errors:
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.002878     0.00491  0.58606  0.55783
## archm  -1.201493     1.14268 -1.05147  0.29304
## mxreg1  1.590937     1.20043  1.32530  0.18507
## omega   0.000033     0.00001  3.23413  0.00122
## alpha1  0.175671     0.16313  1.07686  0.28154
## vxreg1  0.000000     0.99175  0.00000  1.00000
## 
## LogLikelihood : 893.2507 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -7.0697
## Bayes        -6.9855
## Shibata      -7.0708
## Hannan-Quinn -7.0358
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      1.621  0.2029
## Lag[2*(p+q)+(p+q)-1][2]     1.707  0.3165
## Lag[4*(p+q)+(p+q)-1][5]     2.179  0.5768
## d.o.f=0
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                     0.0371  0.8473
## Lag[2*(p+q)+(p+q)-1][2]    1.0782  0.4736
## Lag[4*(p+q)+(p+q)-1][5]    3.9993  0.2542
## d.o.f=1
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[2]     2.049 0.500 2.000  0.1523
## ARCH Lag[4]     4.724 1.397 1.611  0.1027
## ARCH Lag[6]     5.341 2.222 1.500  0.1638
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  5.5804
## Individual Statistics:              
## mu     0.05290
## archm  0.08050
## mxreg1 0.07161
## omega  0.57633
## alpha1 0.17902
## vxreg1 0.96266
## 
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic:          1.49 1.68 2.12
## Individual Statistic:     0.35 0.47 0.75
## 
## Sign Bias Test
## ------------------------------------
##                    t-value   prob sig
## Sign Bias           0.2459 0.8059    
## Negative Sign Bias  0.5662 0.5718    
## Positive Sign Bias  0.3870 0.6991    
## Joint Effect        1.9015 0.5931    
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     24.30       0.1849
## 2    30     32.39       0.3032
## 3    40     40.79       0.3916
## 4    50     41.63       0.7634
## 
## 
## Elapsed time : 0.4839029
spec8_2 = ugarchspec(mean.model = list(armaOrder=c(ARMA_p,ARMA_q),
                                       include.mean=TRUE,
                                       archm=TRUE,
                                       archpow=1,
                                       external.regressors=Regressor.mean,
                                       archex=FALSE),
                     variance.model=list(model="gjrGARCH",
                                         garchOrder=c(GARCH_q ,GARCH_p),
                                         submodel=NULL,
                                         external.regressors=Regressor.variance,
                                         variance.targeting=FALSE),
                     start.pars=list(mu=0.035101, archm=-1.471415,mxreg1 = -2.337372, omega=0.000217, alpha1=0.999951, vxreg1=0.00000),
                     distribution.model="norm")
modelfit8_2 = ugarchfit(spec=spec8_2, data=Return_c$SP500,
                        out.sample=OutSample,
                        solver="gosolnp",
                        solver.control=list(tol=1e-5, delta=1e-5, trace=1))
## 
## Calculating Random Initialization Parameters...ok!
## 
## Evaluating Objective Function with Random Sampled Parameters...ok!
## 
## Sorting and Choosing Best Candidates for starting Solver...ok!
## 
## Starting Parameters and Starting Objective Function:
##            [,1]
## par1  2.161e-03
## par2  2.573e-01
## par3 -1.226e+00
## par4  2.336e-05
## par5  7.911e-02
## par6  1.107e-01
## par7  3.860e-02
## objf -8.712e+02
## 
## gosolnp-->Starting Solver
## 
## Iter: 1 fn: -898.7731     Pars:  -0.00083389  0.43502920 -0.26378189  0.00003083  0.08133780  0.36530652  0.03955261
## Iter: 2 fn: -898.7731     Pars:  -0.00083389  0.43502920 -0.26378189  0.00003083  0.08133780  0.36530652  0.03955261
## solnp--> Completed in 2 iterations
modelfit8_2
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : gjrGARCH(1,0)
## Mean Model   : ARFIMA(0,0,0)
## Distribution : norm 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error   t value Pr(>|t|)
## mu     -0.000834    0.001171 -0.712153 0.476370
## archm   0.435029    0.250202  1.738711 0.082086
## mxreg1 -0.263782    0.736006 -0.358396 0.720047
## omega   0.000031    0.000007  4.135648 0.000035
## alpha1  0.081338    0.080755  1.007213 0.313832
## gamma1  0.365307    0.166492  2.194143 0.028225
## vxreg1  0.039553    0.648490  0.060992 0.951366
## 
## Robust Standard Errors:
##         Estimate  Std. Error   t value Pr(>|t|)
## mu     -0.000834    0.004104 -0.203175 0.838998
## archm   0.435029    0.526292  0.826594 0.408467
## mxreg1 -0.263782    0.802978 -0.328505 0.742530
## omega   0.000031    0.000011  2.717629 0.006575
## alpha1  0.081338    0.137426  0.591868 0.553939
## gamma1  0.365307    0.214219  1.705299 0.088139
## vxreg1  0.039553    0.805081  0.049129 0.960817
## 
## LogLikelihood : 898.7731 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -7.1058
## Bayes        -7.0074
## Shibata      -7.1073
## Hannan-Quinn -7.0662
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                    0.08915  0.7653
## Lag[2*(p+q)+(p+q)-1][2]   0.09610  0.9224
## Lag[4*(p+q)+(p+q)-1][5]   0.68252  0.9262
## d.o.f=0
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      2.415 0.12014
## Lag[2*(p+q)+(p+q)-1][2]     4.676 0.04965
## Lag[4*(p+q)+(p+q)-1][5]     8.705 0.01964
## d.o.f=1
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[2]     4.450 0.500 2.000 0.03490
## ARCH Lag[4]     7.558 1.397 1.611 0.02054
## ARCH Lag[6]     8.248 2.222 1.500 0.03624
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  2.9547
## Individual Statistics:              
## mu     0.03430
## archm  0.04816
## mxreg1 0.05558
## omega  0.86328
## alpha1 0.07476
## gamma1 0.06693
## vxreg1 0.93330
## 
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic:          1.69 1.9 2.35
## Individual Statistic:     0.35 0.47 0.75
## 
## Sign Bias Test
## ------------------------------------
##                    t-value   prob sig
## Sign Bias           0.7003 0.4844    
## Negative Sign Bias  1.1123 0.2671    
## Positive Sign Bias  0.3661 0.7146    
## Joint Effect        1.7068 0.6354    
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     24.62      0.17352
## 2    30     44.58      0.03232
## 3    40     54.18      0.05379
## 4    50     70.71      0.02281
## 
## 
## Elapsed time : 0.459332
ARMA_p = 0
ARMA_q = 0
GARCH_q = 0
GARCH_p = 1

spec9 = ugarchspec(mean.model = list(armaOrder=c(ARMA_p,ARMA_q),
                                       include.mean=TRUE,
                                       archm=TRUE,
                                       archpow=1,
                                       external.regressors=Regressor.mean,
                                       archex=FALSE),
                     variance.model=list(model="gjrGARCH",
                                         garchOrder=c(GARCH_q ,GARCH_p),
                                         submodel=NULL,
                                         external.regressors=Regressor.variance,
                                         variance.targeting=FALSE),
                     distribution.model="norm")
modelfit9 = ugarchfit(spec=spec9, data=Return_c$SP500,
                        out.sample=OutSample,
                        solver="gosolnp",
                        solver.control=list(tol=1e-5, delta=1e-5, trace=1))
## 
## Calculating Random Initialization Parameters...ok!
## 
## Evaluating Objective Function with Random Sampled Parameters...ok!
## 
## Sorting and Choosing Best Candidates for starting Solver...ok!
## 
## Starting Parameters and Starting Objective Function:
##            [,1]
## par1 -4.241e-03
## par2  4.127e-01
## par3  4.554e-01
## par4  4.900e-08
## par5  9.935e-01
## par6  2.405e-08
## objf -8.684e+02
## 
## gosolnp-->Starting Solver
## 
## Iter: 1 fn: -896.4210     Pars:  -0.00316725967  0.34644606097  0.53731474209  0.00000001293  0.99863889764  0.00000002405
## Iter: 2 fn: -896.5257     Pars:  -0.0029425645011  0.3486231456255  0.4417949739786  0.0000000004333  0.9990372517602  0.0000000240473
## Iter: 3 fn: -896.5270     Pars:  -0.0029859986814  0.3494561409914  0.4572460817257  0.0000000001714  0.9990449048488  0.0000000240473
## solnp--> Completed in 3 iterations
modelfit9
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : gjrGARCH(0,1)
## Mean Model   : ARFIMA(0,0,0)
## Distribution : norm 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error     t value Pr(>|t|)
## mu     -0.002986    0.002826 -1.0567e+00 0.290655
## archm   0.349456    0.148139  2.3590e+00 0.018326
## mxreg1  0.457246    0.790131  5.7870e-01 0.562794
## omega   0.000000    0.000001  2.5900e-04 0.999793
## beta1   0.999045    0.000001  1.2137e+06 0.000000
## vxreg1  0.000000    0.000020  1.2020e-03 0.999041
## 
## Robust Standard Errors:
##         Estimate  Std. Error     t value Pr(>|t|)
## mu     -0.002986    0.003776 -7.9087e-01  0.42902
## archm   0.349456    0.525107  6.6549e-01  0.50573
## mxreg1  0.457246    0.774706  5.9022e-01  0.55504
## omega   0.000000    0.000012  1.5000e-05  0.99999
## beta1   0.999045    0.000008  1.1849e+05  0.00000
## vxreg1  0.000000    0.000062  3.8600e-04  0.99969
## 
## LogLikelihood : 896.527 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -7.0958
## Bayes        -7.0116
## Shibata      -7.0969
## Hannan-Quinn -7.0619
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      1.557  0.2121
## Lag[2*(p+q)+(p+q)-1][2]     1.564  0.3465
## Lag[4*(p+q)+(p+q)-1][5]     2.012  0.6157
## d.o.f=0
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      1.839 0.17502
## Lag[2*(p+q)+(p+q)-1][2]     5.173 0.03657
## Lag[4*(p+q)+(p+q)-1][5]     9.519 0.01222
## d.o.f=1
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale  P-Value
## ARCH Lag[2]     6.561 0.500 2.000 0.010421
## ARCH Lag[4]     9.048 1.397 1.611 0.008651
## ARCH Lag[6]    10.169 2.222 1.500 0.012538
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  58.3619
## Individual Statistics:               
## mu      0.09205
## archm   0.04236
## mxreg1  0.10917
## omega  37.42826
## beta1   0.18113
## vxreg1  0.18041
## 
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic:          1.49 1.68 2.12
## Individual Statistic:     0.35 0.47 0.75
## 
## Sign Bias Test
## ------------------------------------
##                    t-value    prob sig
## Sign Bias           0.5338 0.59393    
## Negative Sign Bias  1.8558 0.06467   *
## Positive Sign Bias  0.3297 0.74190    
## Joint Effect        7.4033 0.06010   *
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     20.16       0.3853
## 2    30     27.84       0.5262
## 3    40     40.47       0.4051
## 4    50     60.35       0.1282
## 
## 
## Elapsed time : 0.853152

ARMA(0,0)-gjrGARCH(1,1)-in-mean模型

通過Ljung Box 檢定

ARMA_p = 0
ARMA_q = 0
GARCH_q = 1
GARCH_p = 1

spec10 = ugarchspec(mean.model = list(armaOrder=c(ARMA_p,ARMA_q),
                                     include.mean=TRUE,
                                     archm=TRUE,
                                     archpow=1,
                                     external.regressors=Regressor.mean,
                                     archex=FALSE),
                   variance.model=list(model="gjrGARCH",
                                       garchOrder=c(GARCH_q ,GARCH_p),
                                       submodel=NULL,
                                       external.regressors=Regressor.variance,
                                       variance.targeting=FALSE),
                   distribution.model="norm")
modelfit10 = ugarchfit(spec=spec10, data=Return_c$SP500,
                      out.sample=OutSample,
                      solver="gosolnp",
                      solver.control=list(tol=1e-5, delta=1e-5, trace=1))
## 
## Calculating Random Initialization Parameters...ok!
## 
## Evaluating Objective Function with Random Sampled Parameters...ok!
## 
## Sorting and Choosing Best Candidates for starting Solver...ok!
## 
## Starting Parameters and Starting Objective Function:
##            [,1]
## par1 -1.145e-03
## par2  1.795e-01
## par3 -1.358e-02
## par4  1.285e-07
## par5  8.145e-02
## par6  8.880e-01
## par7  1.233e-01
## par8  5.839e-09
## objf -8.931e+02
## 
## gosolnp-->Starting Solver
## 
## Iter: 1 fn: -895.9041     Pars:  -0.001759486585  0.163033275009  0.472861060377  0.000000128374  0.080819830788  0.886318749442  0.086086642955  0.000000005839
## Iter: 2 fn: -895.9041     Pars:  -0.001759486585  0.163033275009  0.472861060377  0.000000128374  0.080819830788  0.886318749442  0.086086642955  0.000000005839
## solnp--> Completed in 2 iterations
modelfit10
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : gjrGARCH(1,1)
## Mean Model   : ARFIMA(0,0,0)
## Distribution : norm 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error  t value Pr(>|t|)
## mu     -0.001759    0.003066 -0.57382  0.56609
## archm   0.163033    0.279978  0.58231  0.56036
## mxreg1  0.472861    0.746895  0.63310  0.52667
## omega   0.000000    0.000000  0.27134  0.78613
## alpha1  0.080820    0.140497  0.57524  0.56513
## beta1   0.886319    0.022559 39.28895  0.00000
## gamma1  0.086087    0.173216  0.49699  0.61920
## vxreg1  0.000000    0.109292  0.00000  1.00000
## 
## Robust Standard Errors:
##         Estimate  Std. Error   t value Pr(>|t|)
## mu     -0.001759    0.010368 -0.169700  0.86525
## archm   0.163033    1.180984  0.138049  0.89020
## mxreg1  0.472861    0.955682  0.494789  0.62075
## omega   0.000000    0.000003  0.045716  0.96354
## alpha1  0.080820    0.482539  0.167489  0.86699
## beta1   0.886319    0.112937  7.847907  0.00000
## gamma1  0.086087    0.765493  0.112459  0.91046
## vxreg1  0.000000    0.376402  0.000000  1.00000
## 
## LogLikelihood : 895.9041 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -7.0749
## Bayes        -6.9626
## Shibata      -7.0769
## Hannan-Quinn -7.0297
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      3.231 0.07224
## Lag[2*(p+q)+(p+q)-1][2]     3.278 0.11804
## Lag[4*(p+q)+(p+q)-1][5]     3.575 0.31202
## d.o.f=0
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                    0.06199  0.8034
## Lag[2*(p+q)+(p+q)-1][5]   2.53803  0.4978
## Lag[4*(p+q)+(p+q)-1][9]   5.22872  0.3966
## d.o.f=2
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[3]     3.186 0.500 2.000 0.07429
## ARCH Lag[5]     4.181 1.440 1.667 0.15831
## ARCH Lag[7]     6.306 2.315 1.543 0.12199
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  63.9618
## Individual Statistics:              
## mu     0.04005
## archm  0.05571
## mxreg1 0.04366
## omega  6.62034
## alpha1 0.11136
## beta1  0.06196
## gamma1 0.03074
## vxreg1 0.77954
## 
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic:          1.89 2.11 2.59
## Individual Statistic:     0.35 0.47 0.75
## 
## Sign Bias Test
## ------------------------------------
##                    t-value   prob sig
## Sign Bias          1.51794 0.1303    
## Negative Sign Bias 0.48233 0.6300    
## Positive Sign Bias 0.05756 0.9541    
## Joint Effect       4.14892 0.2458    
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     23.02       0.2363
## 2    30     27.61       0.5391
## 3    40     40.47       0.4051
## 4    50     50.39       0.4181
## 
## 
## Elapsed time : 0.863651
#BIC -6.9637

模型精簡 - BIC 判斷

ARMA(0,0)-gjrGARCH(1,1)-in-mean模型通過Ljung Box 檢定,但因為mean.model與variance.model的解釋變數呈現不顯著,在同時滿足Ljung- Box 與題意要求下,運用以下模型精簡手法找到最適合模型,模型精簡方式為mean與variance 模型同時都有解釋變數,或只有variance.model有解釋變數,或只有mean.model有解釋變數,故再比較BIC最小,決定模型精簡的樣貌。最後決定ARMA(0,0)-gjrGARCH(1,1)-in-mean 只有mean.model有解釋變數。

模型精簡1

BIC -6.9637

ARMA_p = 0
ARMA_q = 0
GARCH_q = 1
GARCH_p = 1

spec10 = ugarchspec(mean.model = list(armaOrder=c(ARMA_p,ARMA_q),
                                     include.mean=TRUE,
                                     archm=TRUE,
                                     archpow=1,
                                     external.regressors=Regressor.mean,
                                     archex=FALSE),
                   variance.model=list(model="gjrGARCH",
                                       garchOrder=c(GARCH_q ,GARCH_p),
                                       submodel=NULL,
                                       external.regressors=Regressor.variance,
                                       variance.targeting=FALSE),
                   distribution.model="norm")
modelfit10 = ugarchfit(spec=spec10, data=Return_c$SP500,
                      out.sample=OutSample,
                      solver="gosolnp",
                      solver.control=list(tol=1e-5, delta=1e-5, trace=1))
## 
## Calculating Random Initialization Parameters...ok!
## 
## Evaluating Objective Function with Random Sampled Parameters...ok!
## 
## Sorting and Choosing Best Candidates for starting Solver...ok!
## 
## Starting Parameters and Starting Objective Function:
##            [,1]
## par1 -7.771e-04
## par2  1.003e-01
## par3  4.892e-01
## par4  8.197e-08
## par5  1.604e-01
## par6  8.772e-01
## par7 -2.149e-02
## par8  2.616e-08
## objf -8.935e+02
## 
## gosolnp-->Starting Solver
## 
## Iter: 1 fn: -895.8453     Pars:  -0.00297340691  0.33348708298  0.48259328814  0.00000003887  0.05825727578  0.92552029419  0.04245944850  0.00000002616
## Iter: 2 fn: -895.8453     Pars:  -0.00297340691  0.33348708298  0.48259328814  0.00000003887  0.05825727578  0.92552029419  0.04245944850  0.00000002616
## solnp--> Completed in 2 iterations
modelfit10
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : gjrGARCH(1,1)
## Mean Model   : ARFIMA(0,0,0)
## Distribution : norm 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error   t value Pr(>|t|)
## mu     -0.002973    0.000812 -3.660692 0.000252
## archm   0.333487    0.320520  1.040457 0.298128
## mxreg1  0.482593    0.789599  0.611188 0.541075
## omega   0.000000    0.000000  0.095612 0.923828
## alpha1  0.058257    0.115024  0.506480 0.612520
## beta1   0.925520    0.012864 71.946398 0.000000
## gamma1  0.042459    0.129571  0.327693 0.743144
## vxreg1  0.000000    0.097605  0.000000 1.000000
## 
## Robust Standard Errors:
##         Estimate  Std. Error   t value Pr(>|t|)
## mu     -0.002973    0.006781 -0.438498  0.66103
## archm   0.333487    0.900136  0.370485  0.71102
## mxreg1  0.482593    0.812761  0.593770  0.55267
## omega   0.000000    0.000001  0.028042  0.97763
## alpha1  0.058257    0.259638  0.224379  0.82246
## beta1   0.925520    0.110710  8.359858  0.00000
## gamma1  0.042459    0.296271  0.143313  0.88604
## vxreg1  0.000000    0.250641  0.000000  1.00000
## 
## LogLikelihood : 895.8453 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -7.0745
## Bayes        -6.9621
## Shibata      -7.0764
## Hannan-Quinn -7.0292
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      3.436 0.06378
## Lag[2*(p+q)+(p+q)-1][2]     3.456 0.10565
## Lag[4*(p+q)+(p+q)-1][5]     3.818 0.27771
## d.o.f=0
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                     0.2042  0.6513
## Lag[2*(p+q)+(p+q)-1][5]    3.2708  0.3598
## Lag[4*(p+q)+(p+q)-1][9]    5.8040  0.3214
## d.o.f=2
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[3]     3.949 0.500 2.000  0.0469
## ARCH Lag[5]     4.578 1.440 1.667  0.1285
## ARCH Lag[7]     6.417 2.315 1.543  0.1156
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  69.7929
## Individual Statistics:               
## mu      0.09628
## archm   0.12535
## mxreg1  0.10542
## omega  14.60498
## alpha1  0.07295
## beta1   0.06535
## gamma1  0.05838
## vxreg1  0.37429
## 
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic:          1.89 2.11 2.59
## Individual Statistic:     0.35 0.47 0.75
## 
## Sign Bias Test
## ------------------------------------
##                    t-value   prob sig
## Sign Bias          1.54363 0.1240    
## Negative Sign Bias 0.04838 0.9614    
## Positive Sign Bias 0.39528 0.6930    
## Joint Effect       4.56056 0.2070    
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     25.89       0.1332
## 2    30     38.36       0.1145
## 3    40     46.53       0.1901
## 4    50     51.19       0.3877
## 
## 
## Elapsed time : 0.91465

模型精簡2

BIC -6.9827

ARMA_p = 0
ARMA_q = 0
GARCH_q = 1
GARCH_p = 1

spec11 = ugarchspec(mean.model = list(armaOrder=c(ARMA_p,ARMA_q),
                                      include.mean=TRUE,
                                      archm=TRUE,
                                      archpow=1,
                                      external.regressors=NULL,
                                      archex=FALSE),
                    variance.model=list(model="gjrGARCH",
                                        garchOrder=c(GARCH_q ,GARCH_p),
                                        submodel=NULL,
                                        external.regressors=Regressor.variance,
                                        variance.targeting=FALSE),
                    distribution.model="norm")
modelfit11 = ugarchfit(spec=spec11, data=Return_c$SP500,
                       out.sample=OutSample,
                       solver="gosolnp",
                       solver.control=list(tol=1e-5, delta=1e-5, trace=1))
## 
## Calculating Random Initialization Parameters...ok!
## 
## Evaluating Objective Function with Random Sampled Parameters...ok!
## 
## Sorting and Choosing Best Candidates for starting Solver...ok!
## 
## Starting Parameters and Starting Objective Function:
##            [,1]
## par1  6.153e-04
## par2  9.813e-02
## par3  7.049e-08
## par4  1.928e-02
## par5  9.046e-01
## par6  1.429e-01
## par7  2.928e-08
## objf -8.949e+02
## 
## gosolnp-->Starting Solver
## 
## Iter: 1 fn: -896.0140     Pars:  -0.00059207450  0.22078868107  0.00000004996  0.02015631278  0.94794179118  0.06039498362  0.00000002928
## Iter: 2 fn: -896.0140     Pars:  -0.00059207450  0.22078868107  0.00000004996  0.02015631278  0.94794179118  0.06039498362  0.00000002928
## solnp--> Completed in 2 iterations
modelfit11
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : gjrGARCH(1,1)
## Mean Model   : ARFIMA(0,0,0)
## Distribution : norm 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error   t value Pr(>|t|)
## mu     -0.000592    0.001742 -0.339960  0.73389
## archm   0.220789    0.250551  0.881213  0.37820
## omega   0.000000    0.000000  0.132065  0.89493
## alpha1  0.020156    0.053620  0.375912  0.70698
## beta1   0.947942    0.011086 85.511205  0.00000
## gamma1  0.060395    0.063111  0.956959  0.33859
## vxreg1  0.000000    0.014820  0.000002  1.00000
## 
## Robust Standard Errors:
##         Estimate  Std. Error   t value Pr(>|t|)
## mu     -0.000592    0.006898 -0.085827  0.93160
## archm   0.220789    1.000087  0.220769  0.82527
## omega   0.000000    0.000002  0.032421  0.97414
## alpha1  0.020156    0.096715  0.208409  0.83491
## beta1   0.947942    0.109656  8.644668  0.00000
## gamma1  0.060395    0.279321  0.216221  0.82882
## vxreg1  0.000000    0.143015  0.000000  1.00000
## 
## LogLikelihood : 896.014 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -7.0838
## Bayes        -6.9855
## Shibata      -7.0853
## Hannan-Quinn -7.0442
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      3.877 0.04896
## Lag[2*(p+q)+(p+q)-1][2]     3.886 0.08092
## Lag[4*(p+q)+(p+q)-1][5]     4.221 0.22779
## d.o.f=0
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                     0.7269  0.3939
## Lag[2*(p+q)+(p+q)-1][5]    4.1716  0.2334
## Lag[4*(p+q)+(p+q)-1][9]    6.3740  0.2575
## d.o.f=2
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[3]     4.271 0.500 2.000 0.03877
## ARCH Lag[5]     4.614 1.440 1.667 0.12609
## ARCH Lag[7]     6.085 2.315 1.543 0.13563
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  69.5811
## Individual Statistics:               
## mu      0.08615
## archm   0.09290
## omega  16.92492
## alpha1  0.12720
## beta1   0.12369
## gamma1  0.08703
## vxreg1  0.45419
## 
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic:          1.69 1.9 2.35
## Individual Statistic:     0.35 0.47 0.75
## 
## Sign Bias Test
## ------------------------------------
##                    t-value   prob sig
## Sign Bias           1.3105 0.1913    
## Negative Sign Bias  0.4619 0.6446    
## Positive Sign Bias  0.5167 0.6058    
## Joint Effect        4.2945 0.2314    
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     23.50       0.2160
## 2    30     34.54       0.2201
## 3    40     43.66       0.2800
## 4    50     49.60       0.4493
## 
## 
## Elapsed time : 0.8491809

模型精簡3

BIC -6.9876

ARMA_p = 0
ARMA_q = 0
GARCH_q = 1
GARCH_p = 1

spec12 = ugarchspec(mean.model = list(armaOrder=c(ARMA_p,ARMA_q),
                                      include.mean=TRUE,
                                      archm=TRUE,
                                      archpow=1,
                                      external.regressors=Regressor.mean,
                                      archex=FALSE),
                    variance.model=list(model="gjrGARCH",
                                        garchOrder=c(GARCH_q ,GARCH_p),
                                        submodel=NULL,
                                        external.regressors=NULL,
                                        variance.targeting=FALSE),
                    distribution.model="norm")
modelfit12 = ugarchfit(spec=spec12, data=Return_c$SP500,
                       out.sample=OutSample,
                       solver="gosolnp",
                       solver.control=list(tol=1e-5, delta=1e-5, trace=1))
## 
## Calculating Random Initialization Parameters...ok!
## 
## Excluding Inequality Violations...
## 
## ...Excluded 57/500 Random Sequences
## 
## Evaluating Objective Function with Random Sampled Parameters...ok!
## 
## Sorting and Choosing Best Candidates for starting Solver...ok!
## 
## Starting Parameters and Starting Objective Function:
##            [,1]
## par1 -1.824e-03
## par2  3.528e-01
## par3  6.703e-02
## par4  3.806e-08
## par5  2.284e-02
## par6  9.362e-01
## par7  6.782e-02
## objf -8.942e+02
## 
## gosolnp-->Starting Solver
## 
## Iter: 1 fn: -896.2816     Pars:  -0.0022510703276  0.1570532847511  0.6287284415002  0.0000000008651  0.0074647784176  0.9678786031071  0.0437607008518
## Iter: 2 fn: -896.2870     Pars:  -0.0022462168936  0.1550614875298  0.6307486993027  0.0000000001592  0.0071698124177  0.9682563524511  0.0436172780079
## solnp--> Completed in 2 iterations
modelfit12
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : gjrGARCH(1,1)
## Mean Model   : ARFIMA(0,0,0)
## Distribution : norm 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error   t value Pr(>|t|)
## mu     -0.002246    0.004032 -0.557081  0.57747
## archm   0.155061    0.853333  0.181713  0.85581
## mxreg1  0.630749    0.676445  0.932446  0.35111
## omega   0.000000    0.000001  0.000249  0.99980
## alpha1  0.007170    0.064478  0.111197  0.91146
## beta1   0.968256    0.012509 77.405426  0.00000
## gamma1  0.043617    0.094807  0.460065  0.64547
## 
## Robust Standard Errors:
##         Estimate  Std. Error   t value Pr(>|t|)
## mu     -0.002246    0.026419 -0.085021  0.93224
## archm   0.155061    4.537510  0.034173  0.97274
## mxreg1  0.630749    1.536830  0.410422  0.68150
## omega   0.000000    0.000004  0.000042  0.99997
## alpha1  0.007170    0.306262  0.023411  0.98132
## beta1   0.968256    0.041814 23.156395  0.00000
## gamma1  0.043617    0.539731  0.080813  0.93559
## 
## LogLikelihood : 896.287 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -7.0860
## Bayes        -6.9876
## Shibata      -7.0875
## Hannan-Quinn -7.0464
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      3.191 0.07402
## Lag[2*(p+q)+(p+q)-1][2]     3.210 0.12312
## Lag[4*(p+q)+(p+q)-1][5]     3.588 0.31011
## d.o.f=0
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                     0.7418  0.3891
## Lag[2*(p+q)+(p+q)-1][5]    5.1112  0.1445
## Lag[4*(p+q)+(p+q)-1][9]    7.2571  0.1786
## d.o.f=2
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[3]     4.137 0.500 2.000 0.04195
## ARCH Lag[5]     4.437 1.440 1.667 0.13839
## ARCH Lag[7]     5.754 2.315 1.543 0.15865
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  65.851
## Individual Statistics:               
## mu      0.06374
## archm   0.07071
## mxreg1  0.06227
## omega  23.57037
## alpha1  0.13992
## beta1   0.14235
## gamma1  0.12448
## 
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic:          1.69 1.9 2.35
## Individual Statistic:     0.35 0.47 0.75
## 
## Sign Bias Test
## ------------------------------------
##                    t-value   prob sig
## Sign Bias           0.8061 0.4210    
## Negative Sign Bias  0.9438 0.3462    
## Positive Sign Bias  0.3210 0.7485    
## Joint Effect        3.8669 0.2762    
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     26.05     0.128752
## 2    30     51.51     0.006179
## 3    40     52.59     0.071791
## 4    50     59.16     0.151704
## 
## 
## Elapsed time : 1.047289

根據BIC最小化選擇模型精簡3

最後決定ARMA(0,0)-gjrGARCH(1,1)-in-mean 只有mean.model有解釋變數

Rolling 過程(暫時省略,因為花時間很久)

#rollingx1 = ugarchroll(spec=spec12,
#                      data=Return_c$SP500return,
 #                     n.ahead=1,
  #                    forecast.length=OutSample,
   #                   refit.every=1,
    #                  refit.window="moving",
     #                 solver="hybrid",
      #                solver.control=list(tol=1e-5,delta=1e-5,trace=1),
       #               calculate.VaR = TRUE,
        #              VaR.alpha = c(0.01,0.05),
         #             parallel=TRUE,
          #            parallel.control = list(pkg=c("snowfall"), cores=4),
           #           keep.coef=TRUE)
#rollingx1 = resume(rollingx1, solver="gosolnp")
#convergence(rollingx1)
#save(rollingx1, file="c:/temp/rollingx1.RData")
load("c:/temp/rollingx1.RData")
#str(rollingx1)
rollingx1@model$coef[[1]]
## $index
## [1] "2013-12-31"
## 
## $coef
##             Estimate   Std. Error       t value  Pr(>|t|)
## mu     -2.252779e-03 2.621327e-02 -8.594041e-02 0.9315138
## archm   1.573776e-01 4.514593e+00  3.485976e-02 0.9721916
## mxreg1  6.299170e-01 1.562441e+00  4.031620e-01 0.6868291
## omega   9.469068e-11 3.752492e-06  2.523408e-05 0.9999799
## alpha1  7.389119e-03 3.084564e-01  2.395515e-02 0.9808884
## beta1   9.679566e-01 4.120387e-02  2.349189e+01 0.0000000
## gamma1  4.366129e-02 5.336000e-01  8.182400e-02 0.9347867
Return= na.omit(Return)
Return_c = Return
Return_c$criteria = NA
Return_c$criteria = 0.05

Return_c$model_archm = NA
for (i in WindowSize:(DataSize-1)){
  Return_c$model_archm[i] = rollingx1@model$coef[[i+1-WindowSize]]$coef[2,1]
}

Return_c$model_archm_pvalue = NA
for (i in WindowSize:(DataSize-1)){
  Return_c$model_archm_pvalue[i] = rollingx1@model$coef[[i+1-WindowSize]]$coef[2,4]
}

Return_c$model_gamma = NA
for (i in WindowSize:(DataSize-1)){
  Return_c$model_gamma[i] = rollingx1@model$coef[[i+1-WindowSize]]$coef[7,1]
}

Return_c$model_gamma_pvalue = NA
for (i in WindowSize:(DataSize-1)){
  Return_c$model_gamma_pvalue[i] = rollingx1@model$coef[[i+1-WindowSize]]$coef[7,4]
}
Return_c$model_mxreg1 = NA
for (i in WindowSize:(DataSize-1)){
  Return_c$model_mxreg1[i] = rollingx1@model$coef[[i+1-WindowSize]]$coef[3,1]
}

Return_c$model_mxreg1_pvalue = NA
for (i in WindowSize:(DataSize-1)){
  Return_c$model_mxreg1_pvalue[i] = rollingx1@model$coef[[i+1-WindowSize]]$coef[3,4]
}

Return_c$ForecastMu[(WindowSize+1):DataSize]=rollingx1@forecast$density$Mu
Return_c$ForecastSigma[(WindowSize+1):DataSize]=rollingx1@forecast$density$Sigma
Return_c_1 = data.frame(date = index(Return_c), coredata(Return_c))

是否存在風險溢酬?

從「風險溢酬對SP500報酬的影響 與 顯著性(rolling)」圖可以觀察,從2014年初到2015年底的參數估計的p-value幾乎都是高於0.05,意味著風險溢酬對SP500報酬率不顯著影響。由於第一筆估計參數是由前251筆資料估計出來的,我們將推論的時間往前推251天,從2013年初到2015年底對S&P500不存在顯著的風險溢酬影響。

plot4_1 = ggplot(Return_c_1, aes(x=date, y=model_archm)) +
  geom_line() + 
  xlab("")+
  scale_x_date(date_labels = "%Y %b %d")+ ggtitle("風險溢酬對SP500報酬的影響 與 顯著性_rolling")+
  theme_economist() + scale_colour_economist()


plot4_2 = ggplot(Return_c_1, aes(x=date, y=model_archm_pvalue)) +
  geom_line() + 
  xlab("")+
  scale_x_date(date_labels = "%Y %b %d")+
  geom_line(aes(y=criteria),colour="red")+
  theme_economist(stata=TRUE) + scale_colour_economist(stata=TRUE)

library(gridExtra)
grid.arrange(plot4_1,plot4_2,nrow=2,ncol=1)

是否存在波動不對稱性?

從「波動不對稱性對SP500報酬的影響 與 顯著性(rolling)」圖可以觀察,從2014年初到2015年8月底的參數估計的p-value幾乎都是高於0.05,意味著波動不對稱對SP500報酬率不顯著;但從2015年9月初到2015年底的參數估計的p-value幾乎都是低於0.05,意味著波動不對稱對SP500報酬率顯著。由於第一筆估計參數是由前251筆資料估計出來的,我們將推論的時間往前推251天,從2013年初到2014年8月底對S&P500不存在顯著的波動不對稱影響,但從2014年9月初到2015年底對S&P500存在顯著的波動不對稱影響,且影響的程度大約介於0.2與0.5之間,意味著波動不對稱增加1單位對S&P500報酬平均增加0.2到0.5單位之間。

plot5_1 = ggplot(Return_c_1, aes(x=date, y=model_gamma)) +
  geom_line() + 
  xlab("")+
  scale_x_date(date_labels = "%Y %b %d")+ ggtitle("波動不對稱性對SP500報酬的影響 與 顯著性_rolling")+
  theme_economist() + scale_colour_economist()


plot5_2 = ggplot(Return_c_1, aes(x=date, y=model_gamma_pvalue)) +
  geom_line() + 
  xlab("")+
  scale_x_date(date_labels = "%Y %b %d")+
  geom_line(aes(y=criteria),colour="red")+
  theme_economist(stata=TRUE) + scale_colour_economist(stata=TRUE)

library(gridExtra)
grid.arrange(plot5_1,plot5_2,nrow=2,ncol=1)

是否存在交易量前期的影響

從「解釋變數對SP500報酬的影響 與 顯著性(rolling)」圖可以觀察,從2014年初到2015年底的參數估計的p-value幾乎都是高於0.05,意味著交易量前期對SP500報酬率不顯著影響。由於第一筆估計參數是由前251筆資料估計出來的,我們將推論的時間往前推251天,從2013年初到2015年底對S&P500不存在顯著的交易量前期的影響。

plot6_1 = ggplot(Return_c_1, aes(x=date, y=model_mxreg1)) +
  geom_line() + 
  xlab("")+
  scale_x_date(date_labels = "%Y %b %d")+ ggtitle("解釋變數對SP500報酬的影響 與 顯著性_rolling")+
  theme_economist() + scale_colour_economist()


plot6_2 = ggplot(Return_c_1, aes(x=date, y=model_mxreg1_pvalue)) +
  geom_line() + 
  xlab("")+
  scale_x_date(date_labels = "%Y %b %d")+
  geom_line(aes(y=criteria),colour="red")+
  theme_economist(stata=TRUE) + scale_colour_economist(stata=TRUE)

library(gridExtra)
grid.arrange(plot6_1,plot6_2,nrow=2,ncol=1)

S&P500報酬 與 ForecastMu, ForecastSigma關係_rolling

從平均日報酬預測,在2015年7/8月以前日報酬是較平穩的,大約介於0.000與0.002之間,在2015年7/8月以後日報酬先是較不平穩之後慢慢平緩,大約介於-0.004與0.002之間; 從平均波動預測,在2015年7/8月以前波動是較平穩的,大約介於0.005與0.015之間,在2015年7/8月以後波動先是較不平穩之後慢慢平緩,大約介於0.005與0.03之間。 同時察覺平均日報酬與平均波動預測來看,平均日報酬與平均波動在2015年7/8月以前較穩定的,但在之後先是不穩定再慢慢穩定,意味著其實日報酬變動幅度會受波動影響且是正向影響,波動越大日報酬變動幅度也越大。

plot7_1 = ggplot(Return_c_1, aes(x=date, y=ForecastMu)) +
  geom_line() + 
  xlab("")+
  scale_x_date(date_labels = "%Y %b %d")+
  ggtitle("S&P500報酬 與 ForecastMu關係_rolling")

plot7_2 = ggplot(Return_c_1, aes(x=date, y=ForecastSigma)) +
  geom_line() + 
  xlab("")+
  scale_x_date(date_labels = "%Y %b %d")+
  ggtitle("S&P500報酬 與 ForecastSigma 關係_rolling")
library(gridExtra)
grid.arrange(plot7_1,plot7_2,nrow=2,ncol=1)

1 - (d)

比較b與c小題

主要的差別是模型是否有解釋變數介入,但同下圖很明白的,解釋變數對S&P500不具影響,故我認為解釋變數介入的模型,與沒有解釋變數介入的模型,這二者之間並無明顯差異。

解釋變數對S&P500不具影響性

grid.arrange(plot6_1,plot6_2,nrow=2,ncol=1)

風險溢酬影響性

介入解釋變數下的風險溢酬差異不大

grid.arrange(plot1,plot4,nrow=1,ncol=2)

波動不對稱性影響性

介入解釋變數下的波動不對稱性差異不大

grid.arrange(plot2,plot5,nrow=1,ncol=2)

平均日報酬與波動預測

介入解釋變數下的平均日報酬與波動預測差異不大

grid.arrange(plot3,plot7,nrow=1,ncol=2)