Skip to contents

Simulates univariate GARCH/APARCH time series.

Usage

garchSim(spec = garchSpec(), n = 100, n.start = 100, extended = FALSE)

Arguments

spec

a specification object of class "fGARCHSPEC" as returned by garchSpec. See also below for further details.

n

length of the output series, an integer value, by default n=100.

n.start

length of ‘burn-in’ period, by default 100.

extended

logical parameter specifying what to return. If FALSE, return the univariate GARCH/APARCH time series. If TRUE, return a multivariate time series containing also the volatility and conditional innovations time series.

Details

garchSim simulates an univariate GARCH or APARCH time series process as specified by argument spec. The default model specifies Bollerslev's GARCH(1,1) model with normally distributed innovations.

spec is an object of class "fGARCHSPEC" as returned by the function garchSpec. It comes with a slot @model which is a list of just the numeric parameter entries. These are recognized and extracted for use by the function garchSim.

One can estimate the parameters of a GARCH process from empirical data using the function garchFit and then simulate statistically equivalent GARCH processes with the same set of model parameters using the function garchSim.

Value

the simulated time series as an objects of class "timeSeries" with attribute "spec" containing the specification of the model.

If extended is TRUE, then the time series is multivariate and contains also the volatility, sigma, and the conditional innovations, eps.

Note

An undocumented feature (so, it should not be relied on) is that the returned time series is timed so that the last observation is the day before the date when the function is executed. This probably should be controlled by an additional argument in garchSim.

Author

Diethelm Wuertz for the Rmetrics R-port

See also

Examples

## garchSpec -
   spec = garchSpec()
   spec
#> 
#> Formula: 
#>  ~ garch(1, 1)
#> Model:
#>  omega: 1e-06
#>  alpha: 0.1
#>  beta:  0.8
#> Distribution: 
#>  norm
#> Presample: 
#>   time          z     h y
#> 1    0 -0.1207184 1e-05 0

## garchSim -
   # Simulate a "timeSeries" object:
   x = garchSim(spec, n = 50)
   class(x)
#> [1] "timeSeries"
#> attr(,"package")
#> [1] "timeSeries"
   print(x) 
#> GMT 
#>                    garch
#> 2024-03-11 -2.911226e-03
#> 2024-03-12  2.777206e-03
#> 2024-03-13  2.293454e-03
#> 2024-03-14 -5.724560e-03
#> 2024-03-15 -5.579287e-03
#> 2024-03-16 -3.053223e-03
#> 2024-03-17 -5.901101e-03
#> 2024-03-18  1.982989e-03
#> 2024-03-19  2.311324e-04
#> 2024-03-20  1.591033e-03
#> 2024-03-21 -1.844240e-03
#> 2024-03-22  2.327273e-03
#> 2024-03-23 -2.810579e-03
#> 2024-03-24  4.083679e-03
#> 2024-03-25 -1.981109e-03
#> 2024-03-26 -2.736583e-03
#> 2024-03-27 -3.197631e-03
#> 2024-03-28 -2.687408e-03
#> 2024-03-29 -4.503115e-04
#> 2024-03-30 -9.716603e-04
#> 2024-03-31  1.665776e-03
#> 2024-04-01 -2.800591e-03
#> 2024-04-02  1.205845e-03
#> 2024-04-03  8.911127e-04
#> 2024-04-04 -3.355605e-03
#> 2024-04-05  6.375044e-04
#> 2024-04-06  6.992214e-03
#> 2024-04-07  2.302707e-03
#> 2024-04-08 -2.773734e-05
#> 2024-04-09 -6.103604e-03
#> 2024-04-10 -2.646679e-03
#> 2024-04-11  9.828453e-04
#> 2024-04-12  2.199372e-03
#> 2024-04-13 -1.669151e-03
#> 2024-04-14  4.976765e-04
#> 2024-04-15  1.773448e-03
#> 2024-04-16  4.240135e-04
#> 2024-04-17  2.872468e-03
#> 2024-04-18 -4.483632e-03
#> 2024-04-19  4.522951e-03
#> 2024-04-20 -5.253080e-03
#> 2024-04-21  1.227027e-03
#> 2024-04-22  5.491888e-03
#> 2024-04-23 -2.600418e-03
#> 2024-04-24  2.780861e-03
#> 2024-04-25  3.701203e-03
#> 2024-04-26  6.088748e-03
#> 2024-04-27 -1.635551e-03
#> 2024-04-28  1.800426e-03
#> 2024-04-29  5.328106e-03
   
## More simulations ...

   # Default GARCH(1,1) - uses default parameter settings
   spec = garchSpec(model = list())
   garchSim(spec, n = 10)
#> GMT 
#>                    garch
#> 2024-04-20  1.106146e-03
#> 2024-04-21  4.758933e-03
#> 2024-04-22 -4.830058e-03
#> 2024-04-23 -1.673998e-03
#> 2024-04-24  4.252527e-03
#> 2024-04-25  1.028559e-03
#> 2024-04-26 -1.439446e-03
#> 2024-04-27  6.829775e-05
#> 2024-04-28  5.870645e-03
#> 2024-04-29  3.393152e-03
   
   # ARCH(2) - use default omega and specify alpha, set beta=0!
   spec = garchSpec(model = list(alpha = c(0.2, 0.4), beta = 0))
   garchSim(spec, n = 10)
#> GMT 
#>                    garch
#> 2024-04-20  0.0057975767
#> 2024-04-21 -0.0011834665
#> 2024-04-22  0.0017927422
#> 2024-04-23 -0.0008625608
#> 2024-04-24  0.0010001187
#> 2024-04-25  0.0030832726
#> 2024-04-26 -0.0018462440
#> 2024-04-27 -0.0023798962
#> 2024-04-28  0.0008704696
#> 2024-04-29  0.0007833472
   
   # AR(1)-ARCH(2) - use default mu, omega
   spec = garchSpec(model = list(ar = 0.5, alpha = c(0.3, 0.4), beta = 0))
   garchSim(spec, n = 10)
#> GMT 
#>                    garch
#> 2024-04-20 -0.0064929453
#> 2024-04-21 -0.0034116707
#> 2024-04-22 -0.0007531555
#> 2024-04-23 -0.0022603821
#> 2024-04-24 -0.0018410996
#> 2024-04-25 -0.0006229702
#> 2024-04-26 -0.0003279921
#> 2024-04-27  0.0012915726
#> 2024-04-28  0.0019140520
#> 2024-04-29  0.0005515873
   
   # AR([1,5])-GARCH(1,1) - use default garch values and subset ar[.]
   spec = garchSpec(model = list(mu = 0.001, ar = c(0.5,0,0,0,0.1)))
   garchSim(spec, n = 10)
#> GMT 
#>                    garch
#> 2024-04-20  0.0032399130
#> 2024-04-21  0.0022705751
#> 2024-04-22 -0.0002870203
#> 2024-04-23 -0.0011077627
#> 2024-04-24 -0.0031293745
#> 2024-04-25 -0.0017970990
#> 2024-04-26  0.0037490018
#> 2024-04-27  0.0057034846
#> 2024-04-28  0.0036035562
#> 2024-04-29  0.0039249405
   
   # ARMA(1,2)-GARCH(1,1) - use default garch values
   spec = garchSpec(model = list(ar = 0.5, ma = c(0.3, -0.3)))  
   garchSim(spec, n = 10)
#> GMT 
#>                    garch
#> 2024-04-20  0.0043355134
#> 2024-04-21  0.0017659100
#> 2024-04-22 -0.0001591027
#> 2024-04-23  0.0019475098
#> 2024-04-24 -0.0010304484
#> 2024-04-25 -0.0030496409
#> 2024-04-26  0.0052197228
#> 2024-04-27  0.0022934947
#> 2024-04-28  0.0044816948
#> 2024-04-29  0.0024859766
   
   # GARCH(1,1) - use default omega and specify alpha/beta
   spec = garchSpec(model = list(alpha = 0.2, beta = 0.7))
   garchSim(spec, n = 10)
#> GMT 
#>                    garch
#> 2024-04-20 -0.0021716014
#> 2024-04-21 -0.0010676195
#> 2024-04-22 -0.0030764296
#> 2024-04-23 -0.0037004641
#> 2024-04-24  0.0004573765
#> 2024-04-25  0.0018448483
#> 2024-04-26 -0.0021326537
#> 2024-04-27  0.0010830056
#> 2024-04-28 -0.0026793967
#> 2024-04-29  0.0014976260
   
   # GARCH(1,1) - specify omega/alpha/beta
   spec = garchSpec(model = list(omega = 1e-6, alpha = 0.1, beta = 0.8))
   garchSim(spec, n = 10)
#> GMT 
#>                    garch
#> 2024-04-20  0.0017863687
#> 2024-04-21  0.0008059858
#> 2024-04-22  0.0032089856
#> 2024-04-23  0.0038018231
#> 2024-04-24  0.0022089156
#> 2024-04-25 -0.0007191500
#> 2024-04-26 -0.0004469074
#> 2024-04-27  0.0006013883
#> 2024-04-28 -0.0019554465
#> 2024-04-29 -0.0010905864
   
   # GARCH(1,2) - use default omega and specify alpha[1]/beta[2]
   spec = garchSpec(model = list(alpha = 0.1, beta = c(0.4, 0.4)))
   garchSim(spec, n = 10)
#> GMT 
#>                    garch
#> 2024-04-20  0.0019340643
#> 2024-04-21  0.0000668850
#> 2024-04-22  0.0010577411
#> 2024-04-23 -0.0016142765
#> 2024-04-24  0.0006535521
#> 2024-04-25  0.0008639688
#> 2024-04-26  0.0026345660
#> 2024-04-27 -0.0010614920
#> 2024-04-28 -0.0011161853
#> 2024-04-29  0.0004583598
   
   # GARCH(2,1) - use default omega and specify alpha[2]/beta[1]
   spec = garchSpec(model = list(alpha = c(0.12, 0.04), beta = 0.08))
   garchSim(spec, n = 10)
#> GMT 
#>                    garch
#> 2024-04-20 -8.562066e-05
#> 2024-04-21 -2.033166e-03
#> 2024-04-22 -9.540200e-04
#> 2024-04-23  3.912605e-04
#> 2024-04-24 -1.887491e-03
#> 2024-04-25 -1.231150e-04
#> 2024-04-26  1.352201e-03
#> 2024-04-27  7.294251e-04
#> 2024-04-28  2.526151e-03
#> 2024-04-29  4.799199e-04
   
   # snorm-ARCH(1) - use defaults with skew Normal
   spec = garchSpec(model = list(beta = 0, skew = 0.8), cond.dist = "snorm")
   garchSim(spec, n = 10)
#> GMT 
#>                    garch
#> 2024-04-20 -7.485606e-04
#> 2024-04-21  8.914988e-04
#> 2024-04-22 -5.381224e-04
#> 2024-04-23  2.703609e-04
#> 2024-04-24 -6.094172e-04
#> 2024-04-25  1.043383e-03
#> 2024-04-26  4.731667e-04
#> 2024-04-27  1.054015e-03
#> 2024-04-28 -5.737206e-04
#> 2024-04-29 -7.588362e-05
   
   # sged-GARCH(1,1) - using defaults with skew GED
   model = garchSpec(model = list(skew = 0.93, shape = 3), cond.dist = "sged")
   garchSim(model, n = 10)
#> GMT 
#>                    garch
#> 2024-04-20 -0.0002272700
#> 2024-04-21  0.0027759594
#> 2024-04-22  0.0013211663
#> 2024-04-23  0.0015949448
#> 2024-04-24  0.0020719752
#> 2024-04-25  0.0031343476
#> 2024-04-26  0.0020836428
#> 2024-04-27 -0.0020425228
#> 2024-04-28 -0.0002816032
#> 2024-04-29 -0.0011687944
   
   # Taylor Schwert GARCH(1,1) - this belongs to the family of APARCH Models
   spec = garchSpec(model = list(delta = 1))
   garchSim(spec, n = 10)
#> GMT 
#>                    garch
#> 2024-04-20 -4.009875e-06
#> 2024-04-21 -7.730200e-06
#> 2024-04-22  9.493940e-06
#> 2024-04-23  1.129811e-06
#> 2024-04-24  1.523020e-05
#> 2024-04-25 -1.575024e-06
#> 2024-04-26 -7.708138e-06
#> 2024-04-27 -1.477749e-06
#> 2024-04-28 -8.557498e-06
#> 2024-04-29 -5.101195e-06
   
   # AR(1)-t-APARCH(2, 1) - a little bit more complex specification ...
   spec = garchSpec(model = list(mu = 1.0e-4, ar = 0.5, omega = 1.0e-6, 
       alpha = c(0.10, 0.05), gamma = c(0, 0), beta = 0.8, delta = 1.8, 
       shape = 4, skew = 0.85), cond.dist = "sstd")
   garchSim(spec, n = 10)
#> GMT 
#>                    garch
#> 2024-04-20  0.0001359655
#> 2024-04-21  0.0005524952
#> 2024-04-22  0.0018123402
#> 2024-04-23 -0.0079753569
#> 2024-04-24 -0.0187944795
#> 2024-04-25 -0.0103353483
#> 2024-04-26 -0.0088322302
#> 2024-04-27 -0.0128158606
#> 2024-04-28  0.0044420012
#> 2024-04-29  0.0004834796

   garchSim(spec, n = 10, extended = TRUE)
#> GMT 
#>                    garch       sigma        eps
#> 2024-04-20 -0.0039057370 0.001831888 -2.6544277
#> 2024-04-21 -0.0030935270 0.002266588 -0.5473682
#> 2024-04-22 -0.0025168619 0.002376449 -0.4502931
#> 2024-04-23  0.0011837586 0.002230510  1.0500689
#> 2024-04-24  0.0015200149 0.002207861  0.3750850
#> 2024-04-25  0.0023305544 0.002124541  0.6921715
#> 2024-04-26  0.0008536017 0.002035029 -0.2022946
#> 2024-04-27 -0.0004914010 0.001923368 -0.5293849
#> 2024-04-28  0.0009323699 0.001827788  0.5898224
#> 2024-04-29 -0.0062338241 0.001766998 -3.8483397