library(forecast)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
library(stargazer)
## 
## Please cite as:
##  Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
##  R package version 5.2.3. https://CRAN.R-project.org/package=stargazer
library(urca)

gdp_data <- read.csv("A939RX0Q048SBEA.csv")  
gdp_ts <- ts(gdp_data$A939RX0Q048SBEA, start = c(1947, 1), frequency = 4)
ln_gdp <- log(gdp_ts)

ar1_model <- arima(ln_gdp, order = c(1, 0, 0))

stargazer(ar1_model, type = "text", title = "AR(1) Model for Log GDP")
## 
## AR(1) Model for Log GDP
## =============================================
##                       Dependent variable:    
##                   ---------------------------
##                             ln_gdp           
## ---------------------------------------------
## ar1                        1.000***          
##                            (0.0002)          
##                                              
## intercept                  10.413***         
##                             (0.699)          
##                                              
## ---------------------------------------------
## Observations                  302            
## Log Likelihood              896.046          
## sigma2                      0.0002           
## Akaike Inf. Crit.         -1,786.092         
## =============================================
## Note:             *p<0.1; **p<0.05; ***p<0.01
residuals_ar1 <- residuals(ar1_model)

ar1_residuals <- arima(residuals_ar1, order = c(1, 0, 0), include.mean = FALSE)

stargazer(ar1_residuals, type = "text", title = "AR(1) Model for Residuals")
## 
## AR(1) Model for Residuals
## =============================================
##                       Dependent variable:    
##                   ---------------------------
##                          residuals_ar1       
## ---------------------------------------------
## ar1                        0.265***          
##                             (0.055)          
##                                              
## ---------------------------------------------
## Observations                  302            
## Log Likelihood              911.122          
## sigma2                      0.0001           
## Akaike Inf. Crit.         -1,818.243         
## =============================================
## Note:             *p<0.1; **p<0.05; ***p<0.01
rho_hat <- coef(ar1_residuals)["ar1"]

ln_gdp_lag <- lag(ln_gdp, -1)
transformed_var <- ln_gdp - rho_hat * ln_gdp_lag

transformed_var <- na.omit(transformed_var)
final_ar1 <- arima(transformed_var, order = c(1, 0, 0))

stargazer(final_ar1, type = "text", title = "AR(1) Model for Transformed Variable")
## 
## AR(1) Model for Transformed Variable
## =============================================
##                       Dependent variable:    
##                   ---------------------------
##                         transformed_var      
## ---------------------------------------------
## ar1                        1.000***          
##                            (0.0004)          
##                                              
## intercept                  7.652***          
##                             (0.513)          
##                                              
## ---------------------------------------------
## Observations                  301            
## Log Likelihood              903.944          
## sigma2                      0.0001           
## Akaike Inf. Crit.         -1,801.888         
## =============================================
## Note:             *p<0.1; **p<0.05; ***p<0.01
phi_bar <- coef(final_ar1)["ar1"]
alpha <- coef(final_ar1)["intercept"]
rho <- rho_hat
checkresiduals(final_ar1)

## 
##  Ljung-Box test
## 
## data:  Residuals from ARIMA(1,0,0) with non-zero mean
## Q* = 11.968, df = 7, p-value = 0.1016
## 
## Model df: 1.   Total lags used: 8
checkresiduals(final_ar1, plot = FALSE)
## 
##  Ljung-Box test
## 
## data:  Residuals from ARIMA(1,0,0) with non-zero mean
## Q* = 11.968, df = 7, p-value = 0.1016
## 
## Model df: 1.   Total lags used: 8
library(sandwich)
library(lmtest)
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
gdp_var <- gdp_ts

gdp_df <- data.frame(
  y = log(gdp_var),
  y_lag = log(lag(gdp_var, -1)))

gdp_df <- na.omit(gdp_df)

ar_lm <- lm(y ~ y_lag, data = gdp_df)
hac_results <- coeftest(ar_lm, 
                       vcov = kernHAC(ar_lm, 
                                     prewhite = 0,
                                     kernel = "Quadratic Spectral"))
## Warning in summary.lm(x): essentially perfect fit: summary may be unreliable
ols_results <- coeftest(ar_lm)
## Warning in summary.lm(object, ...): essentially perfect fit: summary may be
## unreliable
"HAC Standard Errors:"
## [1] "HAC Standard Errors:"
hac_results
## 
## t test of coefficients:
## 
##                Estimate  Std. Error     t value  Pr(>|t|)    
## (Intercept) -1.1448e-14  1.0893e-15 -1.0510e+01 < 2.2e-16 ***
## y_lag        1.0000e+00  1.0213e-16  9.7913e+15 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
"OLS Standard Errors:"
## [1] "OLS Standard Errors:"
ols_results
## 
## t test of coefficients:
## 
##                Estimate  Std. Error     t value  Pr(>|t|)    
## (Intercept) -1.1448e-14  6.1222e-16 -1.8700e+01 < 2.2e-16 ***
## y_lag        1.0000e+00  5.8671e-17  1.7044e+16 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Part 4: GARCH

1.

wilshire <- read.csv("WILL5000INDFC.csv")
colnames(wilshire) <- c("time", "value")

2.

library(tsbox)

wilshire <- subset(wilshire, value != ".")

wilshire$value <- as.numeric(wilshire$value)

if(!require(tsbox)) install.packages("tsbox")


wilshire_ts <- ts_ts(ts_long(wilshire))

3.

pacf(wilshire_ts, lag.max = 365.2425, na.action = na.pass)

### (a) The PACF shows significant spikes at lags 1, 2, and some seasonal lags, suggesting an AR(2) or AR(3) model might be appropriate. Yes this does seem feasable.

4. & 5.

if(!require(fGarch)) install.packages("fGarch")
## Loading required package: fGarch
## NOTE: Packages 'fBasics', 'timeDate', and 'timeSeries' are no longer
## attached to the search() path when 'fGarch' is attached.
## 
## If needed attach them yourself in your R script by e.g.,
##         require("timeSeries")
if(!require(mice)) install.packages("mice")
## Loading required package: mice
## 
## Attaching package: 'mice'
## The following object is masked from 'package:stats':
## 
##     filter
## The following objects are masked from 'package:base':
## 
##     cbind, rbind
library(fGarch)
library(mice)

wilshire_mice <- mice(ts_df(wilshire_ts), method = "norm.nob", m = 1)
## 
##  iter imp variable
##   1   1  value
##   2   1  value
##   3   1  value
##   4   1  value
##   5   1  value
wilshire_imp <- ts_ts(complete(wilshire_mice))

6.

garch_out<-garchFit(formula = ~arma(1,1) + garch(1,1), data = wilshire_imp)
## 
## Series Initialization:
##  ARMA Model:                arma
##  Formula Mean:              ~ arma(1, 1)
##  GARCH Model:               garch
##  Formula Variance:          ~ garch(1, 1)
##  ARMA Order:                1 1
##  Max ARMA Order:            1
##  GARCH Order:               1 1
##  Max GARCH Order:           1
##  Maximum Order:             1
##  Conditional Dist:          norm
##  h.start:                   2
##  llh.start:                 1
##  Length of Series:          15296
##  Recursion Init:            mci
##  Series Scale:              1.086248
## 
## Parameter Initialization:
##  Initial Parameters:          $params
##  Limits of Transformations:   $U, $V
##  Which Parameters are Fixed?  $includes
##  Parameter Matrix:
##                      U           V      params includes
##     mu     -0.50567183   0.5056718  0.05057028     TRUE
##     ar1    -0.99999999   1.0000000 -0.26724848     TRUE
##     ma1    -0.99999999   1.0000000  0.24583815     TRUE
##     omega   0.00000100 100.0000000  0.10000000     TRUE
##     alpha1  0.00000001   1.0000000  0.10000000     TRUE
##     gamma1 -0.99999999   1.0000000  0.10000000    FALSE
##     beta1   0.00000001   1.0000000  0.80000000     TRUE
##     delta   0.00000000   2.0000000  2.00000000    FALSE
##     skew    0.10000000  10.0000000  1.00000000    FALSE
##     shape   1.00000000  10.0000000  4.00000000    FALSE
##  Index List of Parameters to be Optimized:
##     mu    ar1    ma1  omega alpha1  beta1 
##      1      2      3      4      5      7 
##  Persistence:                  0.9 
## 
## 
## --- START OF TRACE ---
## Selected Algorithm: nlminb 
## 
## R coded nlminb Solver: 
## 
##   0:     20411.381: 0.0505703 -0.267248 0.245838 0.100000 0.100000 0.800000
##   1:     20395.059: 0.0505718 -0.266319 0.246744 0.0936242 0.0979293 0.797505
##   2:     20363.202: 0.0505877 -0.257249 0.255571 0.0774887 0.108586 0.815151
##   3:     20356.383: 0.0505890 -0.256829 0.255971 0.0739031 0.106403 0.814115
##   4:     20344.267: 0.0506019 -0.252794 0.259813 0.0689535 0.103737 0.829666
##   5:     20304.655: 0.0506286 -0.248613 0.263581 0.0520653 0.0857533 0.853700
##   6:     20269.455: 0.0507088 -0.262902 0.247824 0.0119184 0.0615288 0.926466
##   7:     20262.669: 0.0507090 -0.262785 0.247938 0.0137037 0.0617405 0.927219
##   8:     20259.035: 0.0507105 -0.262394 0.248303 0.0135092 0.0599109 0.926828
##   9:     20254.153: 0.0507163 -0.261317 0.249277 0.0142420 0.0577959 0.929687
##  10:     20248.873: 0.0507300 -0.259031 0.251325 0.0125308 0.0525185 0.934264
##  11:     20248.598: 0.0507804 -0.253623 0.255894 0.0108168 0.0448105 0.945727
##  12:     20242.555: 0.0509708 -0.248980 0.257424 0.0113407 0.0461802 0.941146
##  13:     20239.513: 0.0510896 -0.248862 0.255552 0.0142593 0.0498671 0.935663
##  14:     20238.635: 0.0513858 -0.248459 0.250963 0.0148300 0.0475576 0.935762
##  15:     20237.055: 0.0516397 -0.242688 0.252522 0.0151510 0.0479589 0.935890
##  16:     20237.009: 0.0519011 -0.237146 0.253612 0.0149511 0.0487503 0.934504
##  17:     20236.417: 0.0520634 -0.235603 0.252236 0.0153357 0.0484544 0.935209
##  18:     20236.141: 0.0522235 -0.234362 0.250530 0.0151749 0.0476848 0.935662
##  19:     20235.933: 0.0525522 -0.231569 0.247212 0.0155256 0.0475089 0.935716
##  20:     20235.565: 0.0532032 -0.225493 0.241049 0.0159330 0.0485139 0.933974
##  21:     20234.776: 0.0563887 -0.192275 0.212704 0.0145999 0.0452775 0.938313
##  22:     20234.680: 0.0563888 -0.192280 0.212698 0.0147397 0.0453446 0.938372
##  23:     20234.647: 0.0563892 -0.192300 0.212670 0.0148040 0.0452954 0.938231
##  24:     20234.630: 0.0564020 -0.192176 0.212533 0.0149060 0.0453340 0.938225
##  25:     20234.604: 0.0564290 -0.191900 0.212262 0.0148841 0.0453086 0.938152
##  26:     20234.571: 0.0564832 -0.191346 0.211716 0.0149820 0.0453495 0.938103
##  27:     20232.987: 0.0652931 -0.0986378 0.125659 0.0152403 0.0472434 0.935980
##  28:     20232.599: 0.0676752 -0.0757590 0.0966464 0.0155123 0.0461372 0.937039
##  29:     20232.437: 0.0676751 -0.0757652 0.0966403 0.0153487 0.0460191 0.936882
##  30:     20232.425: 0.0676646 -0.0758495 0.0967408 0.0154134 0.0460451 0.936876
##  31:     20232.414: 0.0676432 -0.0760251 0.0969339 0.0154421 0.0460250 0.936755
##  32:     20232.400: 0.0675990 -0.0763429 0.0973500 0.0155243 0.0460662 0.936716
##  33:     20232.385: 0.0675081 -0.0769379 0.0981117 0.0155646 0.0460868 0.936565
##  34:     20232.183: 0.0658722 -0.0786194 0.100056 0.0163190 0.0473043 0.934606
##  35:     20232.106: 0.0658034 -0.0575490 0.0753088 0.0164647 0.0477831 0.933894
##  36:     20232.082: 0.0649328 -0.0378682 0.0559391 0.0166506 0.0477552 0.933761
##  37:     20232.034: 0.0604449 0.0301222 -0.0107285 0.0165600 0.0481484 0.933626
##  38:     20231.981: 0.0561562 0.100489 -0.0800078 0.0166930 0.0481974 0.933307
##  39:     20231.942: 0.0507397 0.152778 -0.132319 0.0167772 0.0480100 0.933359
##  40:     20231.928: 0.0514719 0.154771 -0.134914 0.0167464 0.0478811 0.933509
##  41:     20231.927: 0.0509148 0.163713 -0.143966 0.0167191 0.0478559 0.933568
##  42:     20231.927: 0.0510069 0.161691 -0.142006 0.0167130 0.0478456 0.933583
##  43:     20231.927: 0.0509759 0.162320 -0.142612 0.0167143 0.0478483 0.933580
##  44:     20231.927: 0.0509759 0.162322 -0.142614 0.0167143 0.0478482 0.933580
## 
## Final Estimate of the Negative LLH:
##  LLH:  21497.36    norm LLH:  1.405424 
##          mu         ar1         ma1       omega      alpha1       beta1 
##  0.05537247  0.16232206 -0.14261412  0.01972173  0.04784823  0.93358002 
## 
## R-optimhess Difference Approximated Hessian Matrix:
##                  mu         ar1          ma1         omega        alpha1
## mu     -23916.66244  -1611.3770    -27.47556      979.5106  6.600338e+01
## ar1     -1611.37700 -14368.5483 -14267.08711    -1406.6139  1.553302e+02
## ma1       -27.47556 -14267.0871 -14278.75800    -1468.2747  1.622687e+02
## omega     979.51059  -1406.6139  -1468.27471 -2473313.2819 -1.665822e+06
## alpha1     66.00338    155.3302    162.26875 -1665822.3535 -1.548837e+06
## beta1     113.14297  -1210.3305  -1216.87150 -2057251.3905 -1.635710e+06
##               beta1
## mu          113.143
## ar1       -1210.330
## ma1       -1216.871
## omega  -2057251.391
## alpha1 -1635709.811
## beta1  -1903384.256
## attr(,"time")
## Time difference of 0.2443931 secs
## 
## --- END OF TRACE ---
## 
## 
## Time to Estimate Parameters:
##  Time difference of 1.231213 secs
garch_21 <- garchFit(formula = ~arma(2,1) + garch(1,1), data = wilshire_imp)
## 
## Series Initialization:
##  ARMA Model:                arma
##  Formula Mean:              ~ arma(2, 1)
##  GARCH Model:               garch
##  Formula Variance:          ~ garch(1, 1)
##  ARMA Order:                2 1
##  Max ARMA Order:            2
##  GARCH Order:               1 1
##  Max GARCH Order:           1
##  Maximum Order:             2
##  Conditional Dist:          norm
##  h.start:                   3
##  llh.start:                 1
##  Length of Series:          15296
##  Recursion Init:            mci
##  Series Scale:              1.086248
## 
## Parameter Initialization:
##  Initial Parameters:          $params
##  Limits of Transformations:   $U, $V
##  Which Parameters are Fixed?  $includes
##  Parameter Matrix:
##                      U           V      params includes
##     mu     -0.50567183   0.5056718  0.05056329     TRUE
##     ar1    -0.99999999   1.0000000  0.13287262     TRUE
##     ar2    -0.99999999   1.0000000  0.01510075     TRUE
##     ma1    -0.99999999   1.0000000 -0.15335324     TRUE
##     omega   0.00000100 100.0000000  0.10000000     TRUE
##     alpha1  0.00000001   1.0000000  0.10000000     TRUE
##     gamma1 -0.99999999   1.0000000  0.10000000    FALSE
##     beta1   0.00000001   1.0000000  0.80000000     TRUE
##     delta   0.00000000   2.0000000  2.00000000    FALSE
##     skew    0.10000000  10.0000000  1.00000000    FALSE
##     shape   1.00000000  10.0000000  4.00000000    FALSE
##  Index List of Parameters to be Optimized:
##     mu    ar1    ar2    ma1  omega alpha1  beta1 
##      1      2      3      4      5      6      8 
##  Persistence:                  0.9 
## 
## 
## --- START OF TRACE ---
## Selected Algorithm: nlminb 
## 
## R coded nlminb Solver: 
## 
##   0:     20405.827: 0.0505633 0.132873 0.0151007 -0.153353 0.100000 0.100000 0.800000
##   1:     20389.422: 0.0505635 0.133727 0.0149829 -0.152506 0.0935931 0.0979311 0.797484
##   2:     20357.677: 0.0505656 0.142181 0.0136991 -0.144131 0.0771058 0.108807 0.815277
##   3:     20351.049: 0.0505658 0.142579 0.0135645 -0.143738 0.0735746 0.106634 0.814282
##   4:     20339.349: 0.0505671 0.146346 0.0122469 -0.140007 0.0689097 0.103865 0.829673
##   5:     20299.648: 0.0505692 0.150671 0.00940542 -0.135723 0.0522265 0.0862843 0.853170
##   6:     20263.248: 0.0505730 0.137101 0.00231670 -0.149181 0.0105597 0.0582482 0.930799
##   7:     20255.090: 0.0505730 0.137193 0.00233455 -0.149090 0.0123752 0.0585694 0.931576
##   8:     20251.257: 0.0505732 0.137678 0.00239045 -0.148607 0.0121347 0.0567033 0.931487
##   9:     20246.686: 0.0505738 0.138914 0.00252876 -0.147379 0.0128907 0.0544936 0.934239
##  10:     20242.172: 0.0505752 0.141554 0.00289746 -0.144760 0.0112814 0.0492353 0.938725
##  11:     20240.931: 0.0505781 0.144804 0.00368962 -0.141587 0.0111557 0.0456269 0.944205
##  12:     20235.552: 0.0505888 0.146368 0.00484512 -0.140439 0.0129083 0.0489988 0.937516
##  13:     20234.840: 0.0505959 0.146622 -0.00146574 -0.140576 0.0144927 0.0460852 0.939199
##  14:     20234.354: 0.0506040 0.149781 0.00202873 -0.137788 0.0129987 0.0436770 0.941008
##  15:     20232.299: 0.0506104 0.151851 0.00713406 -0.135991 0.0138633 0.0457849 0.939422
##  16:     20232.015: 0.0506166 0.151433 0.00300707 -0.136569 0.0146934 0.0485003 0.935462
##  17:     20231.838: 0.0506166 0.151448 0.00301198 -0.136555 0.0149641 0.0484848 0.935531
##  18:     20231.697: 0.0506166 0.151468 0.00301895 -0.136536 0.0149861 0.0482559 0.935373
##  19:     20231.572: 0.0506182 0.151575 0.00345912 -0.136499 0.0153039 0.0481951 0.935420
##  20:     20231.416: 0.0506231 0.152079 0.00438022 -0.136208 0.0152292 0.0479937 0.935296
##  21:     20231.325: 0.0506387 0.153799 0.00368894 -0.135106 0.0153178 0.0477309 0.935752
##  22:     20231.221: 0.0506800 0.152310 0.00622126 -0.138288 0.0157790 0.0470945 0.935464
##  23:     20231.167: 0.0506801 0.152503 0.00615928 -0.138098 0.0161845 0.0468804 0.935261
##  24:     20231.148: 0.0506801 0.152517 0.00615469 -0.138085 0.0161085 0.0468349 0.935191
##  25:     20231.138: 0.0506810 0.152571 0.00606764 -0.138066 0.0161464 0.0468470 0.935208
##  26:     20231.125: 0.0506827 0.152705 0.00590877 -0.137999 0.0161389 0.0468334 0.935150
##  27:     20231.098: 0.0506887 0.153003 0.00559733 -0.137949 0.0162158 0.0468128 0.935161
##  28:     20231.070: 0.0506993 0.153531 0.00626272 -0.137887 0.0162767 0.0469099 0.934927
##  29:     20231.035: 0.0507220 0.154172 0.00464376 -0.138200 0.0163733 0.0468555 0.934891
##  30:     20231.019: 0.0507546 0.155263 0.00503866 -0.138733 0.0162069 0.0477480 0.934201
##  31:     20230.997: 0.0507546 0.155270 0.00503665 -0.138727 0.0162863 0.0477737 0.934241
##  32:     20230.990: 0.0507546 0.155301 0.00501234 -0.138712 0.0162976 0.0477005 0.934204
##  33:     20230.980: 0.0507556 0.155422 0.00492135 -0.138743 0.0163480 0.0476494 0.934276
##  34:     20230.972: 0.0507605 0.155741 0.00490728 -0.138889 0.0163412 0.0475814 0.934274
##  35:     20230.963: 0.0507706 0.156331 0.00504821 -0.139253 0.0164069 0.0476333 0.934206
##  36:     20230.953: 0.0507787 0.157421 0.00495146 -0.140225 0.0164754 0.0476666 0.934022
##  37:     20230.949: 0.0507381 0.158225 0.00441469 -0.140937 0.0164819 0.0474328 0.934276
##  38:     20230.942: 0.0506974 0.159244 0.00465660 -0.141615 0.0164532 0.0474506 0.934240
##  39:     20230.937: 0.0506664 0.160234 0.00481213 -0.142496 0.0165337 0.0475913 0.934076
##  40:     20230.935: 0.0506358 0.161127 0.00476552 -0.143488 0.0165860 0.0476910 0.933864
##  41:     20230.932: 0.0505984 0.162081 0.00476819 -0.144353 0.0165963 0.0476910 0.933882
##  42:     20230.930: 0.0505020 0.163816 0.00480570 -0.145828 0.0165515 0.0476201 0.933977
##  43:     20230.920: 0.0499448 0.172195 0.00416582 -0.154262 0.0166994 0.0477118 0.933693
##  44:     20230.919: 0.0499448 0.172198 0.00416465 -0.154260 0.0167083 0.0477226 0.933702
##  45:     20230.918: 0.0499448 0.172216 0.00415696 -0.154242 0.0166834 0.0477382 0.933696
##  46:     20230.918: 0.0499444 0.172274 0.00415419 -0.154294 0.0166920 0.0477471 0.933703
##  47:     20230.917: 0.0499436 0.172394 0.00414693 -0.154397 0.0166814 0.0477506 0.933697
##  48:     20230.917: 0.0499417 0.172620 0.00413894 -0.154618 0.0166871 0.0477574 0.933701
##  49:     20230.916: 0.0499368 0.173073 0.00412207 -0.155056 0.0166792 0.0477601 0.933693
##  50:     20230.916: 0.0499190 0.173941 0.00409655 -0.155920 0.0166865 0.0477677 0.933693
##  51:     20230.887: 0.0459617 0.249998 0.00240166 -0.231147 0.0168572 0.0479695 0.933270
##  52:     20230.880: 0.0445618 0.265253 0.00207769 -0.245995 0.0168786 0.0479878 0.933263
##  53:     20230.874: 0.0434861 0.284829 0.00103103 -0.265552 0.0167216 0.0476852 0.933696
##  54:     20230.871: 0.0423445 0.303483 0.000538829 -0.284573 0.0166941 0.0478068 0.933651
##  55:     20230.871: 0.0423445 0.303484 0.000538505 -0.284572 0.0166885 0.0478051 0.933647
##  56:     20230.870: 0.0423444 0.303481 0.000538146 -0.284568 0.0166909 0.0478078 0.933648
##  57:     20230.870: 0.0423441 0.303481 0.000536159 -0.284557 0.0166863 0.0478134 0.933644
##  58:     20230.870: 0.0423436 0.303463 0.000535111 -0.284536 0.0166889 0.0478164 0.933643
##  59:     20230.870: 0.0423270 0.302396 0.000483001 -0.283321 0.0167106 0.0478693 0.933568
##  60:     20230.870: 0.0423868 0.301599 0.000471091 -0.282484 0.0167098 0.0478637 0.933574
##  61:     20230.870: 0.0423628 0.302079 0.000449654 -0.282905 0.0167145 0.0478703 0.933563
##  62:     20230.870: 0.0423902 0.301629 0.000453415 -0.282463 0.0167139 0.0478697 0.933564
## 
## Final Estimate of the Negative LLH:
##  LLH:  21496.3    norm LLH:  1.405354 
##            mu           ar1           ar2           ma1         omega 
##  0.0460462558  0.3016287965  0.0004534149 -0.2824626429  0.0197212578 
##        alpha1         beta1 
##  0.0478697266  0.9335641234 
## 
## R-optimhess Difference Approximated Hessian Matrix:
##                  mu         ar1          ar2          ma1         omega
## mu     -34162.47278  -2316.3254  -2384.05207    -55.14521     1154.1153
## ar1     -2316.32542 -15422.1434  -4718.00288 -15150.17485    -1404.9683
## ar2     -2384.05207  -4718.0029 -15362.11134  -4165.04624      230.7877
## ma1       -55.14521 -15150.1748  -4165.04624 -15043.10196    -1478.0505
## omega    1154.11530  -1404.9683    230.78768  -1478.05046 -2472414.8242
## alpha1     51.75001    145.1154     -9.57813    141.67306 -1664861.9947
## beta1     127.66010  -1185.7886    290.76717  -1197.45548 -2056329.0484
##               alpha1         beta1
## mu      5.175001e+01      127.6601
## ar1     1.451154e+02    -1185.7886
## ar2    -9.578130e+00      290.7672
## ma1     1.416731e+02    -1197.4555
## omega  -1.664862e+06 -2056329.0484
## alpha1 -1.547624e+06 -1634682.1830
## beta1  -1.634682e+06 -1902431.0622
## attr(,"time")
## Time difference of 0.3225029 secs
## 
## --- END OF TRACE ---
## 
## 
## Time to Estimate Parameters:
##  Time difference of 2.502192 secs
garch_12 <- garchFit(formula = ~arma(1,2) + garch(1,1), data = wilshire_imp)
## 
## Series Initialization:
##  ARMA Model:                arma
##  Formula Mean:              ~ arma(1, 2)
##  GARCH Model:               garch
##  Formula Variance:          ~ garch(1, 1)
##  ARMA Order:                1 2
##  Max ARMA Order:            2
##  GARCH Order:               1 1
##  Max GARCH Order:           1
##  Maximum Order:             2
##  Conditional Dist:          norm
##  h.start:                   3
##  llh.start:                 1
##  Length of Series:          15296
##  Recursion Init:            mci
##  Series Scale:              1.086248
## 
## Parameter Initialization:
##  Initial Parameters:          $params
##  Limits of Transformations:   $U, $V
##  Which Parameters are Fixed?  $includes
##  Parameter Matrix:
##                      U           V      params includes
##     mu     -0.50567183   0.5056718  0.05054327     TRUE
##     ar1    -0.99999999   1.0000000  0.13143031     TRUE
##     ma1    -0.99999999   1.0000000 -0.15199348     TRUE
##     ma2    -0.99999999   1.0000000  0.01563575     TRUE
##     omega   0.00000100 100.0000000  0.10000000     TRUE
##     alpha1  0.00000001   1.0000000  0.10000000     TRUE
##     gamma1 -0.99999999   1.0000000  0.10000000    FALSE
##     beta1   0.00000001   1.0000000  0.80000000     TRUE
##     delta   0.00000000   2.0000000  2.00000000    FALSE
##     skew    0.10000000  10.0000000  1.00000000    FALSE
##     shape   1.00000000  10.0000000  4.00000000    FALSE
##  Index List of Parameters to be Optimized:
##     mu    ar1    ma1    ma2  omega alpha1  beta1 
##      1      2      3      4      5      6      8 
##  Persistence:                  0.9 
## 
## 
## --- START OF TRACE ---
## Selected Algorithm: nlminb 
## 
## R coded nlminb Solver: 
## 
##   0:     20405.944: 0.0505433 0.131430 -0.151993 0.0156357 0.100000 0.100000 0.800000
##   1:     20389.538: 0.0505436 0.132289 -0.151145 0.0155065 0.0935939 0.0979306 0.797484
##   2:     20357.763: 0.0505469 0.140778 -0.142762 0.0141126 0.0771215 0.108796 0.815269
##   3:     20351.128: 0.0505471 0.141178 -0.142368 0.0139729 0.0735889 0.106624 0.814273
##   4:     20339.386: 0.0505493 0.144968 -0.138634 0.0126067 0.0689147 0.103861 0.829659
##   5:     20299.699: 0.0505532 0.149317 -0.134366 0.00970515 0.0522393 0.0862666 0.853162
##   6:     20263.098: 0.0505604 0.135742 -0.147918 0.00267225 0.0106327 0.0583546 0.930628
##   7:     20255.060: 0.0505604 0.135835 -0.147826 0.00268893 0.0124419 0.0586699 0.931403
##   8:     20251.252: 0.0505607 0.136317 -0.147348 0.00273379 0.0122019 0.0568097 0.931304
##   9:     20246.692: 0.0505614 0.137545 -0.146132 0.00284203 0.0129550 0.0546102 0.934053
##  10:     20242.164: 0.0505632 0.140170 -0.143538 0.00314352 0.0113450 0.0493679 0.938529
##  11:     20240.882: 0.0505670 0.143400 -0.140403 0.00381703 0.0112091 0.0457624 0.944015
##  12:     20235.490: 0.0505835 0.145360 -0.138997 0.00486843 0.0129185 0.0490427 0.937448
##  13:     20234.743: 0.0505971 0.145137 -0.139764 -0.00109587 0.0144572 0.0462373 0.939031
##  14:     20234.310: 0.0506077 0.148168 -0.137162 0.00234589 0.0130293 0.0438100 0.940894
##  15:     20232.347: 0.0506155 0.150398 -0.135239 0.00720852 0.0138543 0.0458168 0.939409
##  16:     20232.066: 0.0506267 0.150495 -0.135436 0.00314590 0.0146230 0.0484913 0.935548
##  17:     20232.001: 0.0507149 0.148950 -0.140121 0.00605475 0.0161777 0.0476994 0.934949
##  18:     20231.644: 0.0507511 0.151497 -0.138875 0.00581215 0.0157198 0.0467516 0.935252
##  19:     20231.151: 0.0507711 0.153291 -0.137769 0.00363496 0.0158974 0.0465976 0.935900
##  20:     20231.036: 0.0508073 0.155685 -0.136803 0.00524308 0.0158362 0.0466498 0.935686
##  21:     20231.007: 0.0508551 0.156931 -0.137521 0.00298269 0.0160235 0.0476165 0.934809
##  22:     20231.007: 0.0508696 0.157027 -0.138138 0.00426582 0.0160598 0.0477240 0.934357
##  23:     20230.971: 0.0508764 0.157095 -0.138404 0.00493223 0.0162276 0.0478474 0.934300
##  24:     20230.952: 0.0508808 0.157314 -0.138380 0.00423513 0.0161925 0.0476749 0.934404
##  25:     20230.950: 0.0508808 0.157317 -0.138378 0.00423057 0.0163381 0.0476254 0.934392
##  26:     20230.936: 0.0508828 0.157356 -0.138446 0.00432228 0.0163035 0.0475878 0.934320
##  27:     20230.933: 0.0508857 0.157421 -0.138540 0.00439461 0.0163458 0.0475990 0.934303
##  28:     20230.931: 0.0508925 0.157593 -0.138745 0.00444145 0.0163589 0.0475848 0.934249
##  29:     20230.928: 0.0509051 0.157973 -0.139106 0.00423150 0.0163846 0.0475876 0.934258
##  30:     20230.924: 0.0509279 0.158732 -0.139961 0.00426098 0.0164182 0.0476234 0.934144
##  31:     20230.923: 0.0509336 0.159395 -0.140705 0.00452323 0.0164894 0.0476876 0.934049
##  32:     20230.919: 0.0509318 0.160128 -0.141262 0.00403299 0.0164666 0.0476425 0.934090
##  33:     20230.918: 0.0509318 0.160134 -0.141257 0.00402963 0.0164975 0.0476079 0.934049
##  34:     20230.917: 0.0509311 0.160172 -0.141288 0.00400730 0.0165222 0.0476172 0.934056
##  35:     20230.917: 0.0509303 0.160213 -0.141326 0.00399058 0.0165173 0.0476123 0.934043
##  36:     20230.916: 0.0509287 0.160296 -0.141399 0.00396101 0.0165476 0.0476173 0.934019
##  37:     20230.915: 0.0509254 0.160463 -0.141566 0.00392620 0.0165451 0.0476243 0.933992
##  38:     20230.913: 0.0509028 0.161702 -0.142847 0.00386107 0.0165817 0.0477374 0.933860
##  39:     20230.912: 0.0508802 0.163045 -0.144027 0.00374358 0.0165868 0.0477132 0.933845
##  40:     20230.911: 0.0508406 0.164287 -0.145144 0.00368397 0.0166076 0.0477169 0.933855
##  41:     20230.910: 0.0507757 0.165245 -0.146062 0.00375807 0.0166014 0.0477189 0.933840
##  42:     20230.907: 0.0501415 0.172317 -0.153285 0.00318750 0.0166381 0.0476936 0.933802
##  43:     20230.899: 0.0488860 0.190965 -0.172158 0.00313856 0.0166865 0.0477020 0.933773
##  44:     20230.892: 0.0480170 0.213617 -0.194771 0.00241804 0.0166688 0.0475794 0.933872
##  45:     20230.888: 0.0467047 0.232162 -0.212162 0.00175673 0.0165840 0.0478524 0.933755
##  46:     20230.883: 0.0454685 0.250837 -0.231499 0.00167975 0.0165753 0.0478700 0.933667
##  47:     20230.872: 0.0443155 0.270796 -0.251545 0.00128362 0.0166770 0.0478512 0.933656
##  48:     20230.870: 0.0439017 0.277251 -0.257859 0.00111702 0.0167065 0.0478117 0.933615
##  49:     20230.870: 0.0435395 0.284100 -0.264949 0.00100476 0.0166843 0.0478345 0.933619
##  50:     20230.869: 0.0431369 0.290614 -0.271478 0.000863630 0.0167063 0.0478431 0.933607
##  51:     20230.869: 0.0427018 0.296720 -0.277572 0.000718489 0.0167142 0.0478743 0.933560
##  52:     20230.869: 0.0427888 0.295635 -0.276501 0.000705372 0.0167173 0.0478708 0.933558
##  53:     20230.869: 0.0427915 0.295447 -0.276310 0.000728209 0.0167105 0.0478636 0.933574
##  54:     20230.869: 0.0427981 0.295363 -0.276225 0.000738160 0.0167147 0.0478714 0.933562
##  55:     20230.869: 0.0427823 0.295631 -0.276493 0.000724189 0.0167137 0.0478683 0.933566
## 
## Final Estimate of the Negative LLH:
##  LLH:  21496.3    norm LLH:  1.405354 
##            mu           ar1           ma1           ma2         omega 
##  0.0464721394  0.2956305608 -0.2764933057  0.0007241893  0.0197210433 
##        alpha1         beta1 
##  0.0478683223  0.9335655452 
## 
## R-optimhess Difference Approximated Hessian Matrix:
##                  mu         ar1          ma1          ma2         omega
## mu     -33534.17641  -2273.1670    -53.55374   -121.42405     1143.6507
## ar1     -2273.16699 -15358.9552 -15092.53951  -4356.28838    -1403.1306
## ma1       -53.55374 -15092.5395 -14987.99053  -3974.25975    -1475.5392
## ma2      -121.42405  -4356.2884  -3974.25975 -14578.82438      191.5599
## omega    1143.65069  -1403.1306  -1475.53922    191.55988 -2472509.3888
## alpha1     51.51849    147.1725    143.60193      6.07595 -1664941.8334
## beta1     126.88106  -1185.6213  -1197.25953    302.16323 -2056413.3347
##               alpha1         beta1
## mu      5.151849e+01      126.8811
## ar1     1.471725e+02    -1185.6213
## ma1     1.436019e+02    -1197.2595
## ma2     6.075950e+00      302.1632
## omega  -1.664942e+06 -2056413.3347
## alpha1 -1.547707e+06 -1634758.5137
## beta1  -1.634759e+06 -1902507.8437
## attr(,"time")
## Time difference of 0.3276031 secs
## 
## --- END OF TRACE ---
## 
## 
## Time to Estimate Parameters:
##  Time difference of 1.919876 secs
garch_22 <- garchFit(formula = ~arma(2,2) + garch(1,1), data = wilshire_imp)
## 
## Series Initialization:
##  ARMA Model:                arma
##  Formula Mean:              ~ arma(2, 2)
##  GARCH Model:               garch
##  Formula Variance:          ~ garch(1, 1)
##  ARMA Order:                2 2
##  Max ARMA Order:            2
##  GARCH Order:               1 1
##  Max GARCH Order:           1
##  Maximum Order:             2
##  Conditional Dist:          norm
##  h.start:                   3
##  llh.start:                 1
##  Length of Series:          15296
##  Recursion Init:            mci
##  Series Scale:              1.086248
## Warning in arima(.series$x, order = c(u, 0, v), include.mean = include.mean):
## possible convergence problem: optim gave code = 1
## Parameter Initialization:
##  Initial Parameters:          $params
##  Limits of Transformations:   $U, $V
##  Which Parameters are Fixed?  $includes
##  Parameter Matrix:
##                      U           V      params includes
##     mu     -0.50567183   0.5056718  0.05140263     TRUE
##     ar1    -0.99999999   1.0000000  0.20705614     TRUE
##     ar2    -0.99999999   1.0000000 -0.60822176     TRUE
##     ma1    -0.99999999   1.0000000 -0.22409936     TRUE
##     ma2    -0.99999999   1.0000000  0.62684493     TRUE
##     omega   0.00000100 100.0000000  0.10000000     TRUE
##     alpha1  0.00000001   1.0000000  0.10000000     TRUE
##     gamma1 -0.99999999   1.0000000  0.10000000    FALSE
##     beta1   0.00000001   1.0000000  0.80000000     TRUE
##     delta   0.00000000   2.0000000  2.00000000    FALSE
##     skew    0.10000000  10.0000000  1.00000000    FALSE
##     shape   1.00000000  10.0000000  4.00000000    FALSE
##  Index List of Parameters to be Optimized:
##     mu    ar1    ar2    ma1    ma2  omega alpha1  beta1 
##      1      2      3      4      5      6      7      9 
##  Persistence:                  0.9 
## 
## 
## --- START OF TRACE ---
## Selected Algorithm: nlminb 
## 
## R coded nlminb Solver: 
## 
##   0:     20412.535: 0.0514026 0.207056 -0.608222 -0.224099 0.626845 0.100000 0.100000 0.800000
##   1:     20395.900: 0.0514042 0.208114 -0.608463 -0.223060 0.626555 0.0936065 0.0979235 0.797505
##   2:     20364.281: 0.0514198 0.217861 -0.610838 -0.213508 0.623725 0.0779684 0.108443 0.814968
##   3:     20362.658: 0.0514223 0.218349 -0.611076 -0.213060 0.623426 0.0708581 0.104162 0.812811
##   4:     20354.065: 0.0514234 0.218537 -0.611170 -0.212890 0.623307 0.0731141 0.105597 0.816172
##   5:     20320.629: 0.0514509 0.223118 -0.613425 -0.208755 0.620386 0.0580530 0.0972570 0.845113
##   6:     20291.364: 0.0514912 0.219834 -0.608154 -0.212861 0.624227 0.0417851 0.0798488 0.870026
##   7:     20267.262: 0.0515502 0.214546 -0.605384 -0.219347 0.624653 0.0333098 0.0665462 0.900541
##   8:     20259.513: 0.0515765 0.216646 -0.609608 -0.217725 0.619476 0.0304973 0.0578965 0.904565
##   9:     20251.643: 0.0516214 0.213056 -0.607624 -0.222213 0.620189 0.0241020 0.0613456 0.912300
##  10:     20251.383: 0.0516227 0.213780 -0.607683 -0.221507 0.620098 0.0247157 0.0610586 0.913343
##  11:     20249.537: 0.0516285 0.214389 -0.607167 -0.221005 0.620456 0.0239538 0.0601007 0.913573
##  12:     20247.795: 0.0516432 0.215812 -0.606289 -0.219852 0.620940 0.0238875 0.0588767 0.915665
##  13:     20244.618: 0.0516885 0.217190 -0.607573 -0.219339 0.618406 0.0221968 0.0552314 0.919421
##  14:     20242.143: 0.0517794 0.218806 -0.607134 -0.219395 0.616727 0.0205650 0.0533998 0.924561
##  15:     20241.519: 0.0518366 0.220885 -0.602660 -0.218343 0.620010 0.0191035 0.0528995 0.925748
##  16:     20240.037: 0.0519904 0.223340 -0.603992 -0.218597 0.615122 0.0195812 0.0526690 0.925695
##  17:     20239.876: 0.0519925 0.223746 -0.604118 -0.218225 0.614947 0.0196197 0.0524280 0.926287
##  18:     20239.617: 0.0520105 0.223851 -0.604206 -0.218440 0.614441 0.0192936 0.0520524 0.926543
##  19:     20239.398: 0.0520553 0.224167 -0.604170 -0.218921 0.613426 0.0191137 0.0516576 0.927384
##  20:     20239.110: 0.0521738 0.225558 -0.602741 -0.219675 0.612085 0.0188576 0.0512541 0.927709
##  21:     20238.904: 0.0522911 0.227088 -0.601039 -0.220290 0.611013 0.0189436 0.0512950 0.927838
##  22:     20237.806: 0.0537505 0.240826 -0.583809 -0.233565 0.592534 0.0163075 0.0506970 0.931608
##  23:     20237.075: 0.0552111 0.255723 -0.566523 -0.245928 0.574165 0.0172479 0.0481095 0.933837
##  24:     20235.691: 0.0566710 0.271379 -0.548707 -0.257700 0.556273 0.0164904 0.0465526 0.934065
##  25:     20234.224: 0.0580982 0.287732 -0.531575 -0.269175 0.537181 0.0175803 0.0476700 0.932779
##  26:     20233.426: 0.0594774 0.300153 -0.512268 -0.284986 0.519056 0.0169313 0.0459783 0.935029
##  27:     20233.376: 0.0594775 0.300151 -0.512269 -0.284991 0.519050 0.0167814 0.0460136 0.934977
##  28:     20233.336: 0.0594776 0.300149 -0.512271 -0.284998 0.519043 0.0167908 0.0461597 0.935047
##  29:     20233.298: 0.0594867 0.300244 -0.512156 -0.285099 0.518905 0.0166581 0.0461891 0.934987
##  30:     20233.259: 0.0595066 0.300459 -0.511895 -0.285317 0.518605 0.0166865 0.0463089 0.935030
##  31:     20233.213: 0.0595472 0.300901 -0.511362 -0.285752 0.518001 0.0165900 0.0463503 0.934957
##  32:     20233.149: 0.0596288 0.301798 -0.510284 -0.286619 0.516799 0.0166336 0.0464715 0.934946
##  33:     20231.749: 0.0645632 0.356621 -0.444298 -0.338523 0.444794 0.0180202 0.0479519 0.931594
##  34:     20231.692: 0.0645632 0.356616 -0.444280 -0.338529 0.444810 0.0180613 0.0480879 0.931708
##  35:     20231.651: 0.0645641 0.356626 -0.444234 -0.338550 0.444818 0.0178903 0.0481132 0.931681
##  36:     20231.612: 0.0645724 0.356752 -0.444022 -0.338672 0.444712 0.0179174 0.0482315 0.931763
##  37:     20231.574: 0.0645902 0.357030 -0.443584 -0.338928 0.444464 0.0177910 0.0482573 0.931716
##  38:     20231.534: 0.0646259 0.357609 -0.442714 -0.339442 0.443928 0.0178293 0.0483735 0.931747
##  39:     20231.491: 0.0646930 0.358795 -0.440961 -0.340486 0.442797 0.0177600 0.0484173 0.931624
##  40:     20231.464: 0.0647651 0.361294 -0.437223 -0.342799 0.440185 0.0179285 0.0486019 0.931467
##  41:     20231.422: 0.0645004 0.362000 -0.435707 -0.344077 0.438567 0.0178351 0.0487517 0.931260
##  42:     20231.391: 0.0639689 0.363984 -0.433098 -0.346216 0.435078 0.0177116 0.0487897 0.931563
##  43:     20231.345: 0.0636566 0.368731 -0.427513 -0.349870 0.429378 0.0174808 0.0484532 0.931999
##  44:     20231.309: 0.0633427 0.372855 -0.421475 -0.353883 0.423904 0.0175658 0.0485649 0.931947
##  45:     20231.272: 0.0629253 0.375705 -0.416302 -0.357488 0.419242 0.0176165 0.0488407 0.931474
##  46:     20231.241: 0.0624727 0.378719 -0.411977 -0.360470 0.414634 0.0175985 0.0488541 0.931613
##  47:     20231.188: 0.0615505 0.386396 -0.402058 -0.367242 0.403970 0.0173594 0.0485204 0.932123
##  48:     20230.994: 0.0541913 0.444843 -0.319821 -0.426578 0.322043 0.0175687 0.0490853 0.931154
##  49:     20230.751: 0.0462850 0.498728 -0.246186 -0.480142 0.244897 0.0172970 0.0489364 0.932025
##  50:     20230.710: 0.0453863 0.508830 -0.238663 -0.489591 0.237664 0.0172540 0.0487332 0.932149
##  51:     20230.706: 0.0447832 0.513273 -0.238394 -0.494376 0.236950 0.0171384 0.0487157 0.932166
##  52:     20230.682: 0.0442802 0.519834 -0.237847 -0.500910 0.236287 0.0171588 0.0486978 0.932277
##  53:     20230.605: 0.0378079 0.636326 -0.247942 -0.616500 0.245100 0.0167962 0.0479036 0.933427
##  54:     20230.580: 0.0315549 0.750443 -0.280089 -0.731908 0.273894 0.0164234 0.0475990 0.934190
##  55:     20230.566: 0.0324833 0.766889 -0.304096 -0.748590 0.297718 0.0164087 0.0475678 0.934240
##  56:     20230.549: 0.0350879 0.715725 -0.295009 -0.696590 0.289902 0.0167807 0.0478179 0.933522
##  57:     20230.547: 0.0332544 0.745763 -0.290415 -0.726564 0.284314 0.0167662 0.0479233 0.933452
##  58:     20230.545: 0.0336162 0.748931 -0.303048 -0.729893 0.297157 0.0166749 0.0478622 0.933624
##  59:     20230.545: 0.0336588 0.744868 -0.299387 -0.725770 0.293468 0.0167253 0.0478634 0.933556
##  60:     20230.545: 0.0336264 0.745515 -0.299287 -0.726409 0.293375 0.0167162 0.0478718 0.933561
##  61:     20230.545: 0.0336116 0.746046 -0.299638 -0.726945 0.293714 0.0167160 0.0478694 0.933563
##  62:     20230.545: 0.0336192 0.745820 -0.299538 -0.726718 0.293617 0.0167162 0.0478699 0.933562
## 
## Final Estimate of the Negative LLH:
##  LLH:  21495.98    norm LLH:  1.405333 
##          mu         ar1         ar2         ma1         ma2       omega 
##  0.03651878  0.74581989 -0.29953765 -0.72671761  0.29361692  0.01972408 
##      alpha1       beta1 
##  0.04786988  0.93356216 
## 
## R-optimhess Difference Approximated Hessian Matrix:
##                  mu         ar1         ar2         ma1         ma2
## mu     -54715.26981  -3747.6342  -3843.7607   -124.5819   -221.9342
## ar1     -3747.63423 -22942.1318 -13189.1836 -22420.9856 -12877.8406
## ar2     -3843.76073 -13189.1836 -22991.8243 -12364.5596 -22366.5587
## ma1      -124.58195 -22420.9856 -12364.5596 -22164.1872 -12315.8195
## ma2      -221.93416 -12877.8406 -22366.5587 -12315.8195 -22020.4561
## omega    1449.48319  -1353.1497   -536.8078  -1414.7656   -586.2912
## alpha1     54.14917    152.0862   -349.5990    168.0418   -327.6197
## beta1     145.26516  -1063.4659   -166.0546  -1054.2157   -142.8460
##                omega        alpha1         beta1
## mu         1449.4832  5.414917e+01      145.2652
## ar1       -1353.1497  1.520862e+02    -1063.4659
## ar2        -536.8078 -3.495990e+02     -166.0546
## ma1       -1414.7656  1.680418e+02    -1054.2157
## ma2        -586.2912 -3.276197e+02     -142.8460
## omega  -2472228.4064 -1.664739e+06 -2056235.2735
## alpha1 -1664738.8727 -1.547425e+06 -1634519.7414
## beta1  -2056235.2735 -1.634520e+06 -1902303.0988
## attr(,"time")
## Time difference of 0.5152261 secs
## 
## --- END OF TRACE ---
## 
## 
## Time to Estimate Parameters:
##  Time difference of 3.448922 secs

(b) The ARMA (1,1) model seems to fit the best with the highest log-likelihood.

stargazer(garch_out, title = "GARCH(1,1) Model Results", type = "text")
## 
## GARCH(1,1) Model Results
## ===============================================
##                         Dependent variable:    
##                     ---------------------------
##                            wilshire_imp        
## -----------------------------------------------
## mu                            0.055**          
##                               (0.024)          
##                                                
## ar1                            0.162           
##                               (0.349)          
##                                                
## ma1                           -0.143           
##                               (0.348)          
##                                                
## omega                        0.020***          
##                               (0.002)          
##                                                
## alpha1                       0.048***          
##                               (0.003)          
##                                                
## beta1                        0.934***          
##                               (0.005)          
##                                                
## -----------------------------------------------
## Observations                  15,296           
## Log Likelihood              21,497.360         
## Akaike Inf. Crit.              2.812           
## Bayesian Inf. Crit.            2.815           
## ===============================================
## Note:               *p<0.1; **p<0.05; ***p<0.01
plot(garch_out, which=2)

### (d) I notice that there are 3 significant spikes.

pred_out <- predict(garch_out,n.ahead=365,plot=TRUE,nx=365)

# Part 5: Cochrane-Orcutt GDP ## 1.

ar1_model <- arima(ln_gdp, order = c(1, 0, 0))
residuals_co <- residuals(ar1_model)
library(fGarch)
garch_resid <- garchFit(~garch(1,1), data = residuals_co)
## 
## Series Initialization:
##  ARMA Model:                arma
##  Formula Mean:              ~ arma(0, 0)
##  GARCH Model:               garch
##  Formula Variance:          ~ garch(1, 1)
##  ARMA Order:                0 0
##  Max ARMA Order:            0
##  GARCH Order:               1 1
##  Max GARCH Order:           1
##  Maximum Order:             1
##  Conditional Dist:          norm
##  h.start:                   2
##  llh.start:                 1
##  Length of Series:          302
##  Recursion Init:            mci
##  Series Scale:              0.01133152
## 
## Parameter Initialization:
##  Initial Parameters:          $params
##  Limits of Transformations:   $U, $V
##  Which Parameters are Fixed?  $includes
##  Parameter Matrix:
##                      U          V    params includes
##     mu     -4.22683757   4.226838 0.4226838     TRUE
##     omega   0.00000100 100.000000 0.1000000     TRUE
##     alpha1  0.00000001   1.000000 0.1000000     TRUE
##     gamma1 -0.99999999   1.000000 0.1000000    FALSE
##     beta1   0.00000001   1.000000 0.8000000     TRUE
##     delta   0.00000000   2.000000 2.0000000    FALSE
##     skew    0.10000000  10.000000 1.0000000    FALSE
##     shape   1.00000000  10.000000 4.0000000    FALSE
##  Index List of Parameters to be Optimized:
##     mu  omega alpha1  beta1 
##      1      2      3      5 
##  Persistence:                  0.9 
## 
## 
## --- START OF TRACE ---
## Selected Algorithm: nlminb 
## 
## R coded nlminb Solver: 
## 
##   0:     401.14756: 0.422684 0.100000 0.100000 0.800000
##   1:     397.77302: 0.423119 0.0784712 0.117250 0.776461
##   2:     394.22730: 0.423811 0.0853960 0.152746 0.774080
##   3:     388.90123: 0.425496 0.0475681 0.196634 0.730584
##   4:     378.53914: 0.431994 0.0632545 0.326203 0.669030
##   5:     378.04144: 0.433101 0.0535171 0.329334 0.660068
##   6:     377.70020: 0.434848 0.0618176 0.339495 0.658468
##   7:     376.83904: 0.442165 0.0573264 0.348791 0.639471
##   8:     375.50496: 0.459347 0.0769041 0.368587 0.614154
##   9:     373.46936: 0.490439 0.0585965 0.440132 0.576606
##  10:     371.50581: 0.493940 0.113706 0.449046 0.481269
##  11:     370.55594: 0.505591 0.134587 0.549549 0.450000
##  12:     368.77601: 0.510938 0.140612 0.603692 0.354362
##  13:     368.59687: 0.536438 0.184854 0.653015 0.289210
##  14:     368.44464: 0.519798 0.180188 0.679111 0.269492
##  15:     368.37530: 0.508456 0.163333 0.682108 0.309846
##  16:     368.36729: 0.512157 0.153097 0.678884 0.311686
##  17:     368.31149: 0.517743 0.154667 0.681063 0.315338
##  18:     368.29293: 0.518128 0.160774 0.689855 0.306405
##  19:     368.26638: 0.523796 0.160757 0.705025 0.298825
##  20:     368.26601: 0.527002 0.157467 0.713185 0.303780
##  21:     368.26243: 0.525675 0.158003 0.716938 0.299825
##  22:     368.26215: 0.524830 0.158616 0.714638 0.299424
##  23:     368.26213: 0.524940 0.158488 0.715163 0.299433
##  24:     368.26213: 0.524940 0.158486 0.715157 0.299439
## 
## Final Estimate of the Negative LLH:
##  LLH:  -984.7483    norm LLH:  -3.260756 
##           mu        omega       alpha1        beta1 
## 5.948372e-03 2.035019e-05 7.151574e-01 2.994392e-01 
## 
## R-optimhess Difference Approximated Hessian Matrix:
##                   mu        omega        alpha1         beta1
## mu     -4.702902e+06   -107748876     -149.7197    -5490.6245
## omega  -1.077489e+08 -96880063296 -1887593.7246 -6832264.8140
## alpha1 -1.497197e+02     -1887594     -108.3218     -189.8692
## beta1  -5.490625e+03     -6832265     -189.8692     -674.7677
## attr(,"time")
## Time difference of 0.005463839 secs
## 
## --- END OF TRACE ---
## 
## 
## Time to Estimate Parameters:
##  Time difference of 0.02631712 secs
library(stargazer)
stargazer_out <- capture.output(stargazer(garch_resid, type = "text"))

plot(garch_resid, which = 2)

predict(garch_resid, n.ahead = 20, plot = TRUE, nx = 40)

##    meanForecast   meanError standardDeviation lowerInterval upperInterval
## 1   0.005948372 0.009434011       0.009434011   -0.01254195    0.02443869
## 2   0.005948372 0.010519024       0.010519024   -0.01466854    0.02656528
## 3   0.005948372 0.011515866       0.011515866   -0.01662231    0.02851905
## 4   0.005948372 0.012445926       0.012445926   -0.01844520    0.03034194
## 5   0.005948372 0.013323374       0.013323374   -0.02016496    0.03206171
## 6   0.005948372 0.014158163       0.014158163   -0.02180112    0.03369786
## 7   0.005948372 0.014957597       0.014957597   -0.02336798    0.03526472
## 8   0.005948372 0.015727224       0.015727224   -0.02487642    0.03677316
## 9   0.005948372 0.016471375       0.016471375   -0.02633493    0.03823167
## 10  0.005948372 0.017193502       0.017193502   -0.02775027    0.03964702
## 11  0.005948372 0.017896416       0.017896416   -0.02912796    0.04102470
## 12  0.005948372 0.018582436       0.018582436   -0.03047253    0.04236928
## 13  0.005948372 0.019253504       0.019253504   -0.03178780    0.04368455
## 14  0.005948372 0.019911267       0.019911267   -0.03307699    0.04497374
## 15  0.005948372 0.020557132       0.020557132   -0.03434287    0.04623961
## 16  0.005948372 0.021192318       0.021192318   -0.03558781    0.04748455
## 17  0.005948372 0.021817884       0.021817884   -0.03681390    0.04871064
## 18  0.005948372 0.022434762       0.022434762   -0.03802295    0.04991970
## 19  0.005948372 0.023043773       0.023043773   -0.03921659    0.05111334
## 20  0.005948372 0.023645648       0.023645648   -0.04039625    0.05229299

2.

garch_gdp <- garchFit(~arma(1,0) + garch(1,1), data = ln_gdp)
## 
## Series Initialization:
##  ARMA Model:                arma
##  Formula Mean:              ~ arma(1, 0)
##  GARCH Model:               garch
##  Formula Variance:          ~ garch(1, 1)
##  ARMA Order:                1 0
##  Max ARMA Order:            1
##  GARCH Order:               1 1
##  Max GARCH Order:           1
##  Maximum Order:             1
##  Conditional Dist:          norm
##  h.start:                   2
##  llh.start:                 1
##  Length of Series:          302
##  Recursion Init:            mci
##  Series Scale:              0.4392655
## 
## Parameter Initialization:
##  Initial Parameters:          $params
##  Limits of Transformations:   $U, $V
##  Which Parameters are Fixed?  $includes
##  Parameter Matrix:
##                        U        V     params includes
##     mu     -237.34255950 237.3426 23.7046605     TRUE
##     ar1      -0.99999999   1.0000  0.9998477     TRUE
##     omega     0.00000100 100.0000  0.1000000     TRUE
##     alpha1    0.00000001   1.0000  0.1000000     TRUE
##     gamma1   -0.99999999   1.0000  0.1000000    FALSE
##     beta1     0.00000001   1.0000  0.8000000     TRUE
##     delta     0.00000000   2.0000  2.0000000    FALSE
##     skew      0.10000000  10.0000  1.0000000    FALSE
##     shape     1.00000000  10.0000  4.0000000    FALSE
##  Index List of Parameters to be Optimized:
##     mu    ar1  omega alpha1  beta1 
##      1      2      3      4      6 
##  Persistence:                  0.9 
## 
## 
## --- START OF TRACE ---
## Selected Algorithm: nlminb 
## 
## R coded nlminb Solver: 
## 
##   0:     1428.9346:  23.7047 0.999848 0.100000 0.100000 0.800000
##   1:     1387.6785:  23.0299 0.971387 0.100245 0.237131 0.869366
##   2:     1193.0956:  18.1405 0.765579 0.100277 0.273371 0.699642
##   3:     775.40674:  10.3310 0.436741 0.100349 0.315291 0.498140
##   4:     195.56443:  11.8920 0.501962 0.101128 0.321865 0.502404
##   5:     195.12381:  11.9253 0.507994 0.0944124 0.321417 0.500743
##   6:     189.56217:  11.8425 0.505179 0.0932191 0.321365 0.500483
##   7:    -18.006333:  6.69093 0.724859 1.00000e-06 0.365012 0.370452
##   8:    -30.564181:  1.48376 0.941613 0.0933016 0.431251 0.173628
##   9:    -44.460553:  1.43546 0.939628 0.0929145 0.431247 0.173582
##  10:    -46.226195:  1.41034 0.941565 0.0921316 0.431748 0.172001
##  11:    -74.550148: -0.0186306  1.00000 0.0905112 0.473104 0.0459620
##  12:    -83.930454: 0.0644286  1.00000 0.0864127 0.383944 1.00000e-08
##  13:    -91.453697: 0.921239 0.963757 0.0812300 0.294772 1.00000e-08
##  14:    -94.964185: 0.877495 0.961966 0.0806434 0.294770 1.00000e-08
##  15:    -98.991341: 0.906721 0.962434 0.0801383 0.292543 1.00000e-08
##  16:    -103.69211: 0.902547 0.961056 0.0761174 0.289428 1.00000e-08
##  17:    -108.56575: 0.976595 0.959264 0.0748041 0.279602 1.00000e-08
##  18:    -123.11338:  1.08891 0.957369 0.0618628 0.263746 1.00000e-08
##  19:    -139.41882:  1.17535 0.951688 0.0594108 0.222177 1.00000e-08
##  20:    -152.49651:  1.38597 0.941706 0.0535008 0.130137 1.00000e-08
##  21:    -162.10711:  1.52051 0.936594 0.0495613 0.0557569 1.00000e-08
##  22:    -171.83997:  1.56263 0.934267 0.0459229 0.0187979 1.00000e-08
##  23:    -189.22345:  1.60638 0.933146 0.0402447 1.00000e-08 1.00000e-08
##  24:    -202.79216:  1.61078 0.932798 0.0363134 1.00000e-08 1.00000e-08
##  25:    -355.96298:  1.64817 0.930277 0.00484575 1.00000e-08 1.00000e-08
##  26:    -367.07929:  1.65744 0.930731 0.00490971 2.49224e-06 3.18970e-07
##  27:    -367.51550:  1.65355 0.930748 0.00497338 0.000578518 1.00000e-08
##  28:    -368.08127:  1.65372 0.930895 0.00500825 0.00177413 1.00000e-08
##  29:    -368.81189:  1.64967 0.930937 0.00504966 0.00417742 1.00000e-08
##  30:    -369.91297:  1.64850 0.931142 0.00509374 0.00899278 1.00000e-08
##  31:    -371.61935:  1.64203 0.931259 0.00515269 0.0186284 1.00000e-08
##  32:    -374.98981:  1.63338 0.931914 0.00518324 0.0378945 1.00000e-08
##  33:    -398.04532:  1.49404 0.937848 0.00278104 0.0551074 1.00000e-08
##  34:    -401.24630:  1.48789 0.937723 0.00310538 0.0551144 1.26653e-06
##  35:    -401.50940:  1.49218 0.938055 0.00331803 0.0551201 2.21606e-06
##  36:    -403.71541:  1.48803 0.937934 0.00335836 0.0551224 2.46493e-06
##  37:    -404.43095:  1.48440 0.938005 0.00349402 0.0551304 3.31699e-06
##  38:    -404.68332:  1.48431 0.938170 0.00353876 0.0551358 3.73823e-06
##  39:    -405.07579:  1.48161 0.938140 0.00354624 0.0552534 4.25868e-05
##  40:    -405.45872:  1.48053 0.938317 0.00356487 0.0555280 0.000131010
##  41:    -405.94176:  1.47758 0.938310 0.00355705 0.0561683 0.000335430
##  42:    -406.58820:  1.47581 0.938514 0.00354331 0.0574569 0.000737521
##  43:    -428.91979:  1.41382 0.941140 0.00240617 0.138523 0.0255593
##  44:    -461.94891:  1.23928 0.948837 0.00157951 0.160800 1.00000e-08
##  45:    -475.64184:  1.17152 0.951175 0.00136678 0.168171 1.00000e-08
##  46:    -490.48326:  1.11875 0.953715 0.00160899 0.160651 1.00000e-08
##  47:    -555.28860: 0.662632 0.973062 0.000419014 0.142130 1.00000e-08
##  48:    -633.11368: 0.444702 0.981589 0.00111893 0.111625 1.00000e-08
##  49:    -694.81958: 0.0177959  1.00000 0.000617734 0.109253 1.00000e-08
##  50:    -706.75117: 0.0132523 0.999806 0.000475365 0.109254 1.00000e-08
##  51:    -709.39412: 0.0165268 0.999854 0.000442713 0.109522 1.00000e-08
##  52:    -709.95247: 0.0170213 0.999771 0.000433177 0.109817 1.00000e-08
##  53:    -709.99305: 0.0178732 0.999744 0.000433870 0.109883 0.000296812
##  54:    -710.46874: 0.0412022 0.998755 0.000442949 0.112002 0.00979886
##  55:    -710.54885: 0.0465064 0.998558 0.000392789 0.114908 0.00616125
##  56:    -711.23315: 0.0485693 0.998458 0.000428453 0.117532 0.00230498
##  57:    -712.50907: 0.0626816 0.997833 0.000403541 0.132961 1.00000e-08
##  58:    -714.54069: 0.0627556 0.997903 0.000401988 0.149614 1.00000e-08
##  59:    -719.18815: 0.0591484 0.998039 0.000316640 0.210073 1.00000e-08
##  60:    -721.53143: 0.0461660 0.998582 0.000325402 0.219099 0.0597793
##  61:    -726.22563: 0.0126821  1.00000 0.000168720 0.290240 0.277194
##  62:    -733.86143: 0.0144481  1.00000 7.30317e-05 0.482574 0.423814
##  63:    -738.16701: 0.0686621 0.997727 0.000167877 0.639768 0.240049
##  64:    -741.03725: 0.0962659 0.996519 0.000123673 0.692593 0.291232
##  65:    -743.39879: 0.126816 0.995267 6.38910e-05 0.744739 0.343103
##  66:    -743.95274: 0.119043 0.995630 7.31711e-05 0.748507 0.343191
##  67:    -743.95887: 0.117321 0.995698 5.93080e-05 0.760053 0.370878
##  68:    -744.04880: 0.117854 0.995673 6.37503e-05 0.762765 0.356126
##  69:    -744.07967: 0.118576 0.995642 6.71348e-05 0.773683 0.343474
##  70:    -744.08732: 0.117982 0.995666 6.82581e-05 0.782368 0.338830
##  71:    -744.09091: 0.117972 0.995667 6.83629e-05 0.792382 0.335120
##  72:    -744.09154: 0.117627 0.995681 6.80988e-05 0.794516 0.336229
##  73:    -744.09163: 0.117731 0.995677 6.79327e-05 0.794143 0.336370
##  74:    -744.09163: 0.117738 0.995676 6.79172e-05 0.794025 0.336447
##  75:    -744.09163: 0.117737 0.995676 6.79157e-05 0.794022 0.336449
## 
## Final Estimate of the Negative LLH:
##  LLH:  -992.5323    norm LLH:  -3.286531 
##           mu          ar1        omega       alpha1        beta1 
## 5.171777e-02 9.956764e-01 1.310462e-05 7.940217e-01 3.364494e-01 
## 
## R-optimhess Difference Approximated Hessian Matrix:
##                   mu           ar1       omega        alpha1         beta1
## mu     -6.435641e+06 -1.478620e+07 -1378343163    -1293.9463    -4269.2164
## ar1    -1.478620e+07 -1.491664e+08   616702290    -6111.5270   -29750.0592
## omega  -1.378343e+09  6.167023e+08 -2476528461 20209090.2424 12238640.6318
## alpha1 -1.293946e+03 -6.111527e+03    20209090     -115.3319     -227.3072
## beta1  -4.269216e+03 -2.975006e+04    12238641     -227.3072     -813.9190
## attr(,"time")
## Time difference of 0.01017094 secs
## 
## --- END OF TRACE ---
## Warning in sqrt(diag(fit$cvar)): NaNs produced
## 
## Time to Estimate Parameters:
##  Time difference of 0.148809 secs
garch_phi <- garch_gdp@fit$coef["ar1"]
garch_mu <- garch_gdp@fit$coef["mu"]
garch_alpha <- garch_mu / (1 - garch_phi)

co_ar1 <- ar1_model$coef

predict(garch_gdp, n.ahead = 20, plot = TRUE, nx = 40)

##    meanForecast   meanError standardDeviation lowerInterval upperInterval
## 1      11.09556 0.008378875       0.008378875      11.07914      11.11199
## 2      11.09931 0.012730661       0.009616130      11.07436      11.12426
## 3      11.10304 0.016682641       0.010846162      11.07034      11.13573
## 4      11.10675 0.020542674       0.012086867      11.06649      11.14701
## 5      11.11045 0.024425765       0.013351323      11.06257      11.15832
## 6      11.11413 0.028391724       0.014649912      11.05848      11.16977
## 7      11.11779 0.032478621       0.015991443      11.05413      11.18145
## 8      11.12144 0.036714502       0.017383778      11.04948      11.19340
## 9      11.12507 0.041122402       0.018834229      11.04447      11.20567
## 10     11.12869 0.045722808       0.020349805      11.03907      11.21830
## 11     11.13229 0.050534994       0.021937392      11.03324      11.23134
## 12     11.13588 0.055577811       0.023603874      11.02695      11.24481
## 13     11.13945 0.060870181       0.025356233      11.02014      11.25875
## 14     11.14300 0.066431443       0.027201619      11.01280      11.27321
## 15     11.14654 0.072281599       0.029147417      11.00487      11.28821
## 16     11.15007 0.078441504       0.031201300      10.99632      11.30381
## 17     11.15358 0.084933030       0.033371276      10.98711      11.32004
## 18     11.15707 0.091779198       0.035665737      10.97719      11.33695
## 19     11.16055 0.099004312       0.038093497      10.96650      11.35459
## 20     11.16401 0.106634073       0.040663837      10.95501      11.37301
plot(garch_gdp, which = 2)