Original link:tecdat.cn/?p=20015 

 

This paper will explain the different models of univariate and multivariate financial time series, especially the conditional mean and conditional covariance matrices, and volatility models.

Average model

This section discusses the conditional mean model.

Iid model

Let’s start with a simple IID model. The IID model assumes that logarithmic return rate XT is an N-dimensional Gaussian time series:

The sample estimators of the mean and covariance matrices are the sample means, respectively

And sample covariance matrix

We start by generating data, familiarizing ourselves with the process and ensuring that the estimation process gives the right results (i.e., integrity checks). Then use real market data and fit different models.

Let’s generate the synthetic IID data and estimate the mean and covariance matrices:

X < -rmvnorm (n = T, mean = mu, Sigma = sigma) # Sample estimation (sample mean and sample covariance matrix) MU_sm < -colmeans (X) Sigma_scm < -cov (X) # error norm "2") # > [1] 2.44 norm (Sigma_scm - Sigma, "F") # > [1] of 70.79Copy the code

Now, let’s do it again for a different number of observations T:

X < -rmvnorm (n = T_max, mean = mu, Sigma = sigma) # Now iterate over a subset of the sample for (T_ in T_sweep) {# Sample estimation mu_sm < -colmeans (X_) Sigma_scm < -cov (X_) # Calculation error error_mu_vs_T <- c(error_mu_vs_T, norm(mu_sm - mu, "2")) error_Sigma_vs_T <- c(error_Sigma_vs_T, norm(Sigma_scm - Sigma, "F") # plot(T_sweep, error_mu_vs_T, main = "mu estimated error ",Copy the code

Plot (T_sweep, error_Sigma_vs_T main = "Error in Sigma estimation ", ylab =" error"Copy the code

Univariate ARMA model

The ARMA (p, q) model on logarithmic yield XT is

Where WT is a white noise sequence with a mean of zero and variance of σ2. The parameters of the model are the coefficients ϕ I, θ I, and the noise variance σ2.

Please note that the ARIMA (P, D, Q) model is the ARMA (P, Q) model with time difference divided into order D. Therefore, if we replace logarithmic prices with xt, then the previous logarithmic return model is actually the ARIMA (P, 1, Q) model, because once logarithmic prices are different, we get a logarithmic return.

rugarchGenerate the data

We will use the Rugarch package to generate univariate ARMA data, estimate parameters, and make predictions.

First, we need to define the model:

# specified with the given coefficient and the parameters of AR (1) the Model # # > > * -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - * # > * ARFIMA Model Spec * # > *----------------------------------* #> Conditional Mean Dynamics #> ------------------------------------ #> Mean Model : ARFIMA(1,0,0) #> Include Mean: TRUE #> #> Conditional Distribution #> ------------------------------------ #> Distribution : norm #> Includes Skew : FALSE #> Includes Shape : FALSE #> Includes Lambda : FALSE #> Level Fixed Include Estimate LB UB #> mu 0.01 1 1 0 NA NA #> ar1-0.90 1 1 0 NA NA #> MA 0.00 00 NA NA #> Arfima 0.00 00 0 NA NA #> archM 0.00 00 NA NA #> mxreg 0.00 00 NA NA #> Alpha 0.00 00 0 NA NA #> beta 0.00 00 0 NA NA #> gamma 0.00 00 NA NA #> eTA1 0.00 00 0 NA NA #> eta2 0.00 00 0 NA NA #> delta 0.00 00 0 NA NA #> lambda 0.00 00 0 NA NA #> Vxreg 0.00 00 0 NA NA #> Skew 0.00 00 0 NA NA #> Shape 0.00 00 0 NA NA 00 0 NA NA #> xi 0.00 00 NA NA fixed. Pars #> $mu #> [1] 0.01 #> #> $ar1 #> [1] -0.9 #> #> $sigma #> [1] 0.2 true_params #> mu ar1 sigma #> 0.01-0.90 0.20Copy the code

Then, we can generate time series:

Plot (synth_log_returns, main = "ARMA model logarithmic yields "plot(synth_log_prices, Main = "Logarithmic price of ARMA model"Copy the code

The ARMA model

Now, we can estimate the parameters (which we already know) :

Arfimaspec (mean. Model = list(armaOrder = c(1,0), Include. Mean = TRUE) #> mu ar1 sigma #> 0.0083-0.8887 0.1987 #> mu ar1 sigma #> 0.01-0.90 0.20Copy the code

We can also study the influence of sample number T on parameter estimation error:

# loop for (T_ in T_sweep) {estim_coeffs_vs_T < -rbind (estim_coeffs_vs_T, coef(arma_fit)) error_coeffs_vs_T <- rbind(error_coeffs_vs_T, Matplot (T_sweep, estim_coeffs_vs_T, main = "Estimated ARMA coefficient ", xlab = "T", Ylab = value,Copy the code

Matplot (T_sweep, 100*error_coeffs_vs_T, main = "Estimated relative error of ARMA coefficient ", xlab = "T", ylab =" error (%)",Copy the code

First, the real μ is almost zero, so the relative error can appear unstable. After T = 800 samples, the other coefficients are well estimated.

ARMATo predict

For a sanity check, we will now compare the results of two packages Forecast and Rugarch:

Model = list(armaOrder = c(1,0), include.mean = TRUE), fixed. Pars = list(mu = 0.005, Arfima (arma_fixed_spec, arma_fixed_spec, Spec (mean.model = list(armaOrder = c(1,0), Include. mean = TRUE) # use package "forecast" to fit models #> ARIMA(1,0,0) with non-zero mean #> #> Coefficients: #> ar1 mean #> -0.8982 0.0036 #> s.e. 0.0139 0.0017 #> #> Sigma ^2 Estimated as 0.01004: Log likelihood=881.6 #> AIC=-1757.2 AICc=-1757.17 BIC=-1742.47 # Comparison model coefficient #> AR1 Intercept Sigma #> -0.898181148 0.003574781 0.100222964 #> mu ar1 sigma #> 0.003605805-0.898750138 0.100199956Copy the code

Indeed, both packages give the same results.

ARMA model selection

In previous experiments, we assumed that we knew the order of the ARMA model, that is, p = 1 and Q = 0. In practice, the order is unknown, so different combinations of orders must be tried. The higher the order, the better the fit, but this will inevitably lead to overfitting. Many methods have been developed to penalize increased complexity to avoid overfitting, e.g. AIC, BIC, SIC, HQIC, etc.

AR MA Mean ARFIMA BIC converged #> 1 0 1 0-0.38249098 1 #> 2 1 1 0 -0.37883157 1 #> 3 2 0 1 0 0 0 0.37736340 1 #> 4 1 2 1 0 -0.37503980 1 #> 5 2 1 0 -0.37459177 1 #> 63 0 1 0 -0.37164609 1 #> 71 3 1 0 -0.37143480 1 # > 8 2 2 1 0-0.37107841-1 # > 3 1 1 0-0.36795491-1 # > 10 2, 3, 1 0-0.36732669-1 # > 11 3 2 1 0-0.36379209 1 # > 3 3 1 0-0.36058264-1 # > 13 1 0 0 3-0.11875575-1 # 14 1 0 0 2 > 0.02957266 1 # > 15 1 0 0 1 0.39326050 1 # > 16 1 0 0 0 1 # select armaOrder #> AR MA #> 1 0Copy the code

In this case, the order is correctly detected because the number of observations T = 1000 is large enough. Conversely, if you try to use T = 200, the detected order is p = 1 and q = 3.

ARMA model to predict

Once you estimate the ARMA model parameters ϕ I ^ I and θ^j, you can use the model to predict future values. For example, the prediction of XT based on past information is

And the prediction error will be xt-x ^ t = wt (assuming the parameter has been estimated), with a variance of σ2. The software package Rugarch makes it easy to predict out-of-sample data:

# Estimate model (excluding out of sample) COEF (ARMA_FIT) #> MU ar1 Sigma #> 0.007212069-0.898745183 0.200400119 # The entire out of sample predicted logarithmic benefit forecast_log_returns <- xts(arma_fore@forecast$seriesFor[1, ], Prev_log_price < -head (tail(synth_log_prices, out_of_SAMPLE +1), Plot (cbind(" FITTED "= FITTED (ARma_fit), cbind("forecast" = forecast_log_prices) Main = "log price forecast ", legend. Loc = "topleft")Copy the code

Multivariate VARMA model

The VARMA (p, q) model on logarithmic yield XT is

Wt is a white noise sequence with zero mean and covariance matrix σ W. The parameters of the model are the vector/matrix coefficients ϕ0, φ I, θ J and the noise covariance matrix σ W.

 

To compare

Let’s load the S&P500 first:

Head (SP500_index_prices) #> SP500 #> 2012-01-03 1277.06 #> 2012-01-05 1281.06 #> Logreturns_trn <- logreturns[1:T_trn] Logreturns_tst < -logreturns [-c(1:T_trn)] # plot {logreturns, addEventLines(XTS (" training ")Copy the code

Now, we use the training data (i.e., for t = 1… , Ttrnt = 1… , Ttrn) to fit different models (note that out-of-sample data out.sample = T_tst is excluded by indication). In particular, we will consider the IID model, the AR model, the ARMA model, and some ARCH and GARCH models (cross-difference modeling will be studied in more detail later).

Iid_fit #> MU Sigma #> 0.0005712982 0.0073516993 mean(Logreturns_trN) #> [1] 0.0005681388 Sd (LogreturNS_trN) #> [1] 0.007360208 # fit AR (1) coEF (AR_FIT) #> MU AR1 Sigma #> 0.0005678014-0.0220185181 ARMA (2,2) coef(arma_fit) #> mu ar1 ar2 ma1 ma2 sigma #> 0.00223304 0.0268612636 0.9095552008 ARCH (1) + ARCH (1) coef(ARCH_fit) #> mu ar1 ma1 omega alpha1 #> Fit ARMA (0,0) +ARCH (10) model coef(long_arch_fit) #> mu Omega alpha1 alpha2 alpha3 alpha4 alpha5 #> 7.490786E-04 2.452099e-05 6.888561E-02 7.207551E-02 1.419938E-01 1.909541E-02 3.082806E-02 #> alpha6 alpha7 alpha8 alpha9 Alpha10 #> 4.026539E-02 3.050040E-07 9.260183E-02 1.150128E-01 Coef (GARCH_fit) #> MU ar1 MA1 omega alpha1 beta1 #> 6.660346E-04 9.664597E-01 1.000000 e+00 e-06 e-01 e-01 7.470725 1.257786 7.066506Copy the code

We use different models to predict logarithmic returns:

Forecast (IID_FIT, n.ahead = 1, N.oll = T_tst - 1) dates_out_of_SAMPLE) # AR (1) forecast(AR_fit, n.ahead = 1, N.oll = T_tst - 1) dates_out_of_sample) # ARMA (2,2) forecast(arma_fit, n.ahead = 1, N.oll = T_tst - 1) dates_out_of_SAMPLE) # Use ARMA (1,1) + ARCH (1) forecast(ARCH_fit, n.ahead = 1, N.oll = t_tst-1) dates_out_of_sample) # ARMA (0,0) +ARCH (10) model forecast(long_arch_fit, n.ahead = 1, N.oll = T_tst - 1) dates_out_of_SAMPLE) # ARMA (1,1) +GARCH (1,1) forecast(Garch_fit, n.ahead = 1, n.roll = T_tst - 1) dates_out_of_sample)Copy the code

We can calculate the prediction errors (in sample and out of sample) of different models:

Print (error_var) #> in-sample out-of-sample #> iID 5.417266e-05 8.975710e-05 AR(1) 5.414645e-05 9.006139e-05 ARMA(1,1) + ARCH(1) 5.415836E-05 8.983266E-05 #> ARCH(10) 5.417266E-05 8.975710e-05 #> ARMA(1,1) + GARCH(1,1) 5.339071e-05 9.244012e-05Copy the code

It can be observed that the in-sample error tends to decrease as the model complexity increases (due to higher degrees of freedom of fitting data), although the difference is negligible. What really matters is the out of sample error: we can see that increasing the complexity of the model may yield poor results. In terms of error in predicting returns, it seems that the simplest IID model is sufficient.

Finally, let’s show some graphs of the out-of-sample error:

Plot (error, main = "Out of sample error of profit prediction of different models ",Copy the code

Note that since we did not re-fit the model, the error increases over time (especially for ARCH modeling).

Scroll window comparison

Let’s start by comparing the concepts of static and rolling predictions with a simple example:

ARMA (2,2) < -spec (mean.model = list(armaOrder = c(2,2), Ar_static_fit < -fit (spec = spec, data = logreturns, Modelroll < -aroll (spec = spec, data = logreturns, n.ahead = 1, Cbind ("static forecast" = ar_static_fore_logreturns, main = "use ARMA (2,2) model to forecast", Plot (error_logreturns, col = c("black", "red"), LWD = 2, main = "ARMA (2,2) model prediction error ", legend.loc = "topleft")Copy the code

We can clearly observe the effect of the scrolling window process on the time series.

Now we can redo all predictions for all models on a scrolling window basis:

Roll (IID_spec, data = Logreturns, n.ahead = 1, forecast. Length = T_t # AR (1) roll(AR_spec, Data = logreturns, n.ahead = 1, forecast. Length = T_tst, # ARMA (2,2) model roll(arma_spec, data = logreturns, N.ahead = 1, forecast. Length = T_tst, # ARMA (1,1) + ARCH (1) Model roll(arch_spec, data = Logreturns, n.ahead = 1, forecast. Length = T_tst, # ARMA (1,1) + ARCH (1) model roll(arch_spec, data = Logreturns, Forecast. Length = T_tst, refit. Every = 50, refit. Win # ARMA (0,0) + ARCH (10) model roll(long_arch_spec, data = logreturns, n.ahead = 1, forecast.length = T_tst, refit.every = 50, # ARMA (1,1) + GARCH (1,1) Roll (Garch_spec, data = Logreturns, n.ahead = 1, forecast. Length = T_tst, refit.every = 50, refit.windowCopy the code

Let’s look at the prediction error in the rolling base case:

Print (rolling_error_var) #> in-sample out-of-sample #> iID 5.417266E-05 8.974166E-05 #> AR(1) 5.414645e-05 9.038057E-05 #> ARMA(1,1) + ARCH(1) 5.415836e-05 8.991902e-05 #> ARCH(10) 5.417266e-05 ARMA(1,1) + GARCH(1,1) 5.339071e-05 8.895682e-05Copy the code

And some charts:

Plot (error_logreturns, main = "Rolling prediction error of different models ", legend. Loc = "topleft"Copy the code

We see that all models now fit the time series. In addition, we did not find any significant differences between models.

We can finally compare the static error with the rolling error:

barplot(rbind(error_var[, "out-of-sample"], rolling_error_var[, "out-of-sample"]) col = c("darkblue", "darkgoldenrod"), Legend = c(" static ", "static "),Copy the code

We can see that rolling predictions are necessary in some cases. So, in fact, we need to make rolling forecast improvements on a regular basis.

Variance model

ARCH and GARCH models

The ARCH (m) model of log return residual WT is

Where zT is a white noise sequence with zero mean and constant variance, and the conditional variance σ2t is modeled as

Where, m is the model order, ω> 0, α I ≥0 is the parameter.

The GARCH (M, S) model extends the ARCH model with recursive terms over σ2t:

The parameters ω> 0, α I ≥0 and βj≥0 need to satisfy the stability of ∑mi =1α I + ∑ Sj =1 βj≤1.

rugarchGenerate the data

First, we need to define the model:

# specified with the given coefficient and the parameters of the GARCH Model # # > > * -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - * # > * GARCH Model Spec * # > *---------------------------------* #> #> Conditional Variance Dynamics #> ------------------------------------ #> GARCH Model: sGARCH(1,1) #> Variance Targeting: FALSE #> #> Conditional Mean Dynamics #> ------------------------------------ #> Mean Model : ARFIMA(1,0,0) #> Include Mean: TRUE #> garch-in-mean: FALSE #> #> Conditional Distribution #> ------------------------------------ #> Distribution : norm #> Includes Skew : FALSE #> Includes Shape : FALSE #> Includes Lambda : FALSE #> Level Fixed Include Estimate LB UB #> mu 0.005 1 1 0 NA NA #> ar1-0.900 1 1 0 NA NA #> MA 0.000 00 NA NA #> Arfima 0.000 00 NA NA #> ARCHM 0.000 00 NA NA #> mxreg 0.000 00 NA NA #> omega 0.001 1 1 0 NA NA #> alpha1 0.300 1 0 NA NA #> beta1 0.650 1 0 NA NA #> gamma 0.000 00 NA NA #> eta1 0.000 00 NA NA #> eta2 0.000 00 NA NA #> eta1 0.000 00 NA NA #> eta1 0.000 00 NA NA #> eta2 0.000 00 NA NA #> delta 0.000 000 NA NA #> lambda 0.000 000 NA NA #> vxreg 0.000 000 NA NA #> Skew 0.000 000 NA NA #> shape 0.000 0 0 0 # NA NA > ghlambda 0.000 0 0 0 # 0.000 0 0 0 > xi NA NA NA NA # # $mu > > [1] 0.005 # # # $ar1 > > > [1] - 0.9 # > True_params #> mu ar1 omega alpha1 beta1 #> 0.005-0.900 0.001 0.300 0.650Copy the code

Then, we can generate the yield time series:

#> num [1:2000, 1] 0.167-0.217 # plot(synth_log_returns, Main = "Logarithmic return of GARCH model ", LWD = 1.5) lines(Synth_volatilityCopy the code

GARCH

Now, we can estimate the parameters:

Model = list(armaOrder = c(1,0) #> mu ar1 omega alpha1 beta1 #> 0.0036510100-0.8902333595 0.0008811434 0.2810460728 0.6717486402 #> MU ar1 omega alpha1 beta1 #> 0.005-0.900 0.001 0.300 0.650 # coefficient error #> mu ar1 omega alpha1 beta1 #> 0.0013489900 0.0097666405 0.0001188566 0.0189539272 0.0217486402Copy the code

We can also study the influence of sample number T on parameter estimation error:

# loop for (T_ in T_sweep) {garch_fit error_coeffs_vs_T < -rbind (error_coeffs_vs_T, abs((coef(garch_fit) - true_params)/true_params)) estim_coeffs_vs_T <- rbind(estim_coeffs_vs_T, Coef (garch_fit) # plot matplot(T_sweep, 100*error_coeffs_vs_T, main = "Estimated relative error of GARCH coefficient ", xlab = "T", ylab =" error (%)",Copy the code

Real ω is almost zero, so the error is very volatile. As for the other coefficients, as in the case of ARMA, the estimate of μ is indeed poor (relative error over 50%), while the other coefficients seem to be well estimated after T = 800 samples.

GARCH results comparison

As a health check, we will now compare the results of two software packages, fGarch and Rugarch:

Garch_spec # Generate data of length 1000 garch_fixed_spec (garch_fixed_spec, N.sim = 1000)@path$# Specify and fit the model using the "rugarch" package rugarch_fit < -ugarchfit (spec = garch_spec, GarchFit (formula = ~ garch(1, 1), data = x, Trace = FALSE) #> mu omega alpha1 beta1 #> 0.09749904 0.01395109 0.13510445 0.73938595 #> mu omega alpha1 beta1 Print (head(fGarch_fi #> [1] 0.3513549 0.3254788 0.3037747 Print (head(Rugar #> [1]) print(head(rugar #> [1]) print(rugar #> [1]Copy the code

Indeed, both packages give the same results.

userugarchPackage for GARCH prediction

Once the parameters of the GARCH model are estimated, the model can be used to predict future values. For example, the one-step prediction of conditional variance based on past information is

Given omega ^ / (1-∑mi =1α^ I -∑sj =1β^ j). The software package Rugarch makes it easy to predict out-of-sample data:

# Estimation model, Out of sample GARCH_fit COef (GARCH_FIT) #> Mu ar1 omega alpha1 beta1 #> 0.0034964331-0.8996287630 0.0006531088 0.3058756796 Plot (cbind("fitted" = FITTED (garch_fit), Main = "synthetic logarithmic revenue forecast ", legend. Loc = "topleft")Copy the code

Plot (Cbind (" FITTED volatility" = sigma(GARch_fit), main = "fitted volatility", legend. Loc = "topleft")Copy the code

Different methods for

Let’s load the S&P500 first:

Head (SP500_index_prices) #> SP500 #> 2008-01-02 1447.16 #> 2008-01-03 1447.16 #> 2008-01-04 1411.63 #> X_trn < -x [1:T_trn] X_TST < -x [-c(1:T_trn)] # Plot {plot(x, main = "revenue" addEventLines(XTS (" training ", inCopy the code

constant

Let’s start with constants:

Plot (cbind(SQRT (var_constant), x_trn) main = "constant ")Copy the code

Moving average

Now, let’s use the moving average of squared returns:

Plot (cbind(SQRT (var_t), x_trn), main = "Envelope based on simple rolling mean square (timeslot =20)Copy the code

EWMA

Index Weighted Moving Average (EWMA) :

Note that this can also be modeled as an ETS (A, N, N) state-space model:

Plot (cbind(std_t, x_trn), main = "envelope based on square EWMA ")Copy the code

Multiplication ETS

We can also try different variations of the ETS model. For example, the multiplicative noise version ETS (M, N, N) with a state space model:

Plot (cbind(std_t, x_trn), col = c("red", "black") main = "square ETS (M, N, N) envelope"Copy the code

ARCH

Now we can use more complex ARCH modeling:

Plot (cbind(std_t, x_trn), col = c("red", "black") main = "ARCH(5) ")Copy the code

GARCH

We can upgrade the model to GARCH:

Plot (cbind(std_t, x_trn), col = c("red", "black") main = "GARCH (1,1)"Copy the code

SV random volatility

Finally, we can use random volatility modeling:

Or, equivalently,

Plot (cbind(std_t, x_trn), col = c("red", "black"), main = "Envelope analysis based on random volatility ")Copy the code

To compare

Now, we can compare the errors in the variance estimates for each method over the out-of-sample period:

#> MA EWMA ETS(M,N,N) ARCH(5) GARCH(1,1) SV #> 2.204965e-05 7.226188e-06 3.284057e-06 7.879039e-05 6.496545e-06 6.705059E-06 barplot(error_all, main = "Error in estimation of out-of-sample square difference"Copy the code

Scroll window comparison

Scroll window comparison of six methods: MA, EWMA, ETS (MNN), ARCH (5), GARCH (1,1), and SV.

Len_tst < -40 for (I in seq(lookback, t-len_tst, by = len_tst)) { # MA var_t <- roll_meanr(x_trn^2, n = 20, fill = NA) var_fore <- var(x_trn/sqrt(var_t), na.rm = TRUE) * tail(var_t, 1) error_ma <- c(error_ma, abs(var_fore - var_tst)) # EWMA error_ewma <- c(error_ewma, abs(var_fore - var_tst)) # ETS(M,N,N) error_ets_mnn <- c(error_ets_mnn, abs(var_fore - var_tst)) # ARCH error_arch <- c(error_arch, abs(var_fore - var_tst)) # GARCH error_garch <- c(error_garch, abs(var_fore - var_tst)) # SV error_sv <- c(error_sv, Abs (var_fore - var_tst))} barplot(error_all, main = "",Copy the code

Multivariate GARCH model

For illustrative purposes, we will consider only the constant conditional dependence (CCC) and dynamic conditional dependence (DCC) models, as they are the most popular. The logarithmic return residual wt is modeled as

Where zT is an IID white noise sequence with zero mean and constant covariance matrix II. The conditional covariance matrix sigma T is modeled as

Dt = Diag (σ1, t… , σN, t) is the normalized noise vector C, the covariance matrix ηt= c-1wt (that is, it contains diagonal elements equal to 1).

Basically, using this model, the diagonal matrix Dt contains a set of univariate GARCH models, and then the matrix C contains some correlations between sequences. The main disadvantage of this model is that the matrix C is constant. To overcome this problem, DCC is proposed as

Where Ct contains diagonal elements equal to 1. To enforce diagonal elements equal to 1, Engle models them as

Qt has arbitrary diagonal elements and follows the model

We will generate data, estimate parameters and forecast.

Start by loading the multi-etf data:

  • SPDR S&P 500 ETF
  • 20 + year Treasury ETF
  • IEF: 7-10 year Treasury ETF
Prices < -xts () head(prices) #> SPY TLT IEF #> 2013-01-02 127.8779 99.85183 93.65224 #> 2013-01-03 127.5890 98.49886 93.17085 #> 2013-01-04 128.1493 98.88306 93.21463 #> 2013-01-07 127.7991 98.92480 93.26714 #> 2013-01-08 Plot (log(prices) main = "log prices of three ETFs ", legend.loc = "topleft")Copy the code

First, we define the model:

Ugarch_spec specifies DCC model REPLICATE (multispec(spec, n = 3)).Copy the code

Next, we fit the model:

# # # estimation model > > * -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - * # > * DCC GARCH Fit * # > * -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- * # # > > Distribution: mvnorm #> Model: DCC(1,1) #> No. Parameters: 44 #> [VAR GARCH DCC UncQ] : [30+9+2+3] #> No. 3 #> No. Obs. : 1007 #> log-likelihood: 12198.4 #> av.log-likelihood: # # # 12.11 > > Optimal Parameters > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- # > Estimate Std. Error t value Pr (> | | t) # > [SPY]. Omega 0.000004 0.000000 11.71585 0.000000 # [TLT]. Omega 0.000001 0.000001 0.93156 0.351563 #> [TLT]. Alpha1 0.019716 0.010126 1.94707 0.051527 #>. Beta1 0.963760 0.006434 149.79210 0.000000 #> [IEF]. Omega 0.000000 0.000001 0.46913 0.638979 [IEF]. Alpha1 0.031741 0.023152 1.37097 0.170385 #> [IEF]. Beta1 0.937777 0.016498 56.84336 0.000000 #> [Joint] DCCA1 0.033573 0.014918 2.25044 0.024421 #> [Joint] DCCB1 0.859787 0.079589 10.80278 0.000000 #> #> Information Criteria #> -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - # # > > Akaike - 24.140 # > Bayes theorem 23.925 # > Shibata - 24.143 # > kerri Hannan Quinn - # # # > > > 24.058 Elapsed Time: 0.8804049Copy the code

We can plot time-varying correlations:

# Dim (dCC_cor) #> [1] 3 3 1007 # Plot (corr_t main = "corr_t main ", legend. Loc = "left")Copy the code

We see a very high and fairly stable correlation between the two yield ETFs. The correlation with SPY is small and fluctuates in the range of less than zero.

 


Most welcome insight

1. Har-rv-j and recursive neural network (RNN) hybrid model predict and trade high frequency volatility of large stock indexes

2. Har-rv model based on mixed data sampling (MIDAS) regression in R language predicts GDP growth

3. Realization of volatility: ARCH model and HAR-RV model

4. Arma-egarch model of R language and integrated prediction algorithm are used to predict the actual volatility of SPX

5. VaR comparison of GARCH (1,1), MA and historical simulation method

6.R language multivariate COPULA GARCH model time series prediction

7. VAR fitting and prediction based on ARMA-GARCH process for R language

8. Matlab prediction of Arma-GARCH conditional mean and variance models

9. ARIMA + GARCH trading strategy for S&P500 stock index in R language