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

## default garch model
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.2367119 1e-05 0

x <- garchSim(spec, n = 50)
class(x)
#> [1] "timeSeries"
#> attr(,"package")
#> [1] "timeSeries"
print(x) 
#> GMT 
#>                    garch
#> 2025-09-24  2.293456e-03
#> 2025-09-25 -5.724565e-03
#> 2025-09-26 -5.579291e-03
#> 2025-09-27 -3.053226e-03
#> 2025-09-28 -5.901105e-03
#> 2025-09-29  1.982991e-03
#> 2025-09-30  2.311325e-04
#> 2025-10-01  1.591034e-03
#> 2025-10-02 -1.844241e-03
#> 2025-10-03  2.327274e-03
#> 2025-10-04 -2.810580e-03
#> 2025-10-05  4.083680e-03
#> 2025-10-06 -1.981109e-03
#> 2025-10-07 -2.736583e-03
#> 2025-10-08 -3.197632e-03
#> 2025-10-09 -2.687409e-03
#> 2025-10-10 -4.503116e-04
#> 2025-10-11 -9.716605e-04
#> 2025-10-12  1.665777e-03
#> 2025-10-13 -2.800591e-03
#> 2025-10-14  1.205845e-03
#> 2025-10-15  8.911127e-04
#> 2025-10-16 -3.355606e-03
#> 2025-10-17  6.375045e-04
#> 2025-10-18  6.992215e-03
#> 2025-10-19  2.302708e-03
#> 2025-10-20 -2.773734e-05
#> 2025-10-21 -6.103605e-03
#> 2025-10-22 -2.646679e-03
#> 2025-10-23  9.828453e-04
#> 2025-10-24  2.199372e-03
#> 2025-10-25 -1.669151e-03
#> 2025-10-26  4.976765e-04
#> 2025-10-27  1.773448e-03
#> 2025-10-28  4.240135e-04
#> 2025-10-29  2.872468e-03
#> 2025-10-30 -4.483632e-03
#> 2025-10-31  4.522951e-03
#> 2025-11-01 -5.253080e-03
#> 2025-11-02  1.227027e-03
#> 2025-11-03  5.491889e-03
#> 2025-11-04 -2.600418e-03
#> 2025-11-05  2.780861e-03
#> 2025-11-06  3.701203e-03
#> 2025-11-07  6.088748e-03
#> 2025-11-08 -1.635551e-03
#> 2025-11-09  1.800426e-03
#> 2025-11-10  5.328106e-03
#> 2025-11-11  1.903535e-03
#> 2025-11-12 -3.040495e-03
   
## More simulations ...

## Default GARCH(1,1) - uses default parameter settings
spec <- garchSpec(model = list())
garchSim(spec, n = 10)
#> GMT 
#>                    garch
#> 2025-11-03 -4.830059e-03
#> 2025-11-04 -1.673998e-03
#> 2025-11-05  4.252527e-03
#> 2025-11-06  1.028559e-03
#> 2025-11-07 -1.439446e-03
#> 2025-11-08  6.829775e-05
#> 2025-11-09  5.870646e-03
#> 2025-11-10  3.393152e-03
#> 2025-11-11  3.205573e-03
#> 2025-11-12 -2.040141e-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
#> 2025-11-03  0.0017927422
#> 2025-11-04 -0.0008625608
#> 2025-11-05  0.0010001187
#> 2025-11-06  0.0030832726
#> 2025-11-07 -0.0018462440
#> 2025-11-08 -0.0023798962
#> 2025-11-09  0.0008704696
#> 2025-11-10  0.0007833472
#> 2025-11-11 -0.0003016249
#> 2025-11-12 -0.0005002815

## 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
#> 2025-11-03 -0.0007531555
#> 2025-11-04 -0.0022603821
#> 2025-11-05 -0.0018410996
#> 2025-11-06 -0.0006229702
#> 2025-11-07 -0.0003279921
#> 2025-11-08  0.0012915726
#> 2025-11-09  0.0019140520
#> 2025-11-10  0.0005515873
#> 2025-11-11  0.0004785214
#> 2025-11-12  0.0002537728

## 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
#> 2025-11-03 -0.0002870178
#> 2025-11-04 -0.0011077595
#> 2025-11-05 -0.0031293703
#> 2025-11-06 -0.0017970960
#> 2025-11-07  0.0037490015
#> 2025-11-08  0.0057034834
#> 2025-11-09  0.0036035560
#> 2025-11-10  0.0039249403
#> 2025-11-11  0.0025426208
#> 2025-11-12  0.0014967001

## 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
#> 2025-11-03 -0.0001591027
#> 2025-11-04  0.0019475104
#> 2025-11-05 -0.0010304485
#> 2025-11-06 -0.0030496416
#> 2025-11-07  0.0052197237
#> 2025-11-08  0.0022934952
#> 2025-11-09  0.0044816955
#> 2025-11-10  0.0024859770
#> 2025-11-11  0.0005256349
#> 2025-11-12  0.0007577916

## 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
#> 2025-11-03 -0.0030764300
#> 2025-11-04 -0.0037004645
#> 2025-11-05  0.0004573765
#> 2025-11-06  0.0018448485
#> 2025-11-07 -0.0021326538
#> 2025-11-08  0.0010830056
#> 2025-11-09 -0.0026793968
#> 2025-11-10  0.0014976261
#> 2025-11-11 -0.0023784895
#> 2025-11-12  0.0007910640

## 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
#> 2025-11-03  0.0032089890
#> 2025-11-04  0.0038018266
#> 2025-11-05  0.0022089174
#> 2025-11-06 -0.0007191505
#> 2025-11-07 -0.0004469077
#> 2025-11-08  0.0006013886
#> 2025-11-09 -0.0019554474
#> 2025-11-10 -0.0010905869
#> 2025-11-11  0.0007800873
#> 2025-11-12 -0.0034663114

## 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
#> 2025-11-03  0.0010577379
#> 2025-11-04 -0.0016142721
#> 2025-11-05  0.0006535505
#> 2025-11-06  0.0008639670
#> 2025-11-07  0.0026345611
#> 2025-11-08 -0.0010614903
#> 2025-11-09 -0.0011161837
#> 2025-11-10  0.0004583592
#> 2025-11-11  0.0023333481
#> 2025-11-12 -0.0037440396

## 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
#> 2025-11-03 -0.0009540200
#> 2025-11-04  0.0003912605
#> 2025-11-05 -0.0018874914
#> 2025-11-06 -0.0001231150
#> 2025-11-07  0.0013522007
#> 2025-11-08  0.0007294251
#> 2025-11-09  0.0025261514
#> 2025-11-10  0.0004799199
#> 2025-11-11 -0.0020227883
#> 2025-11-12 -0.0008739593

## 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
#> 2025-11-03 -0.0005238778
#> 2025-11-04  0.0004031428
#> 2025-11-05  0.0009646549
#> 2025-11-06  0.0010711402
#> 2025-11-07  0.0001962504
#> 2025-11-08 -0.0007422212
#> 2025-11-09 -0.0005590742
#> 2025-11-10  0.0006256405
#> 2025-11-11 -0.0002550782
#> 2025-11-12  0.0003393966

## 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
#> 2025-11-03  0.0013291707
#> 2025-11-04  0.0016032978
#> 2025-11-05  0.0020813099
#> 2025-11-06 -0.0029451222
#> 2025-11-07 -0.0016848480
#> 2025-11-08 -0.0020145022
#> 2025-11-09 -0.0002782589
#> 2025-11-10  0.0015856048
#> 2025-11-11  0.0029872444
#> 2025-11-12  0.0033366976

## 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
#> 2025-11-03 -1.575025e-06
#> 2025-11-04 -7.708141e-06
#> 2025-11-05 -1.477750e-06
#> 2025-11-06 -8.557501e-06
#> 2025-11-07 -5.101197e-06
#> 2025-11-08  9.565472e-06
#> 2025-11-09 -8.507530e-07
#> 2025-11-10  4.646833e-06
#> 2025-11-11 -5.793243e-06
#> 2025-11-12  6.106456e-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
#> 2025-11-03 0.001434469
#> 2025-11-04 0.002922677
#> 2025-11-05 0.002206212
#> 2025-11-06 0.002961086
#> 2025-11-07 0.004310860
#> 2025-11-08 0.001242425
#> 2025-11-09 0.001137885
#> 2025-11-10 0.002214825
#> 2025-11-11 0.008865429
#> 2025-11-12 0.015609584

garchSim(spec, n = 10, extended = TRUE)
#> GMT 
#>                    garch       sigma         eps
#> 2025-11-03  0.0023363781 0.001656053  1.10505200
#> 2025-11-04  0.0009580534 0.001676312 -0.18501074
#> 2025-11-05 -0.0017466545 0.001641064 -1.41717868
#> 2025-11-06 -0.0008666182 0.001723989 -0.05411341
#> 2025-11-07 -0.0005399831 0.001705201 -0.12120216
#> 2025-11-08 -0.0019883909 0.001606889 -1.13162697
#> 2025-11-09 -0.0037203874 0.001636257 -1.72722977
#> 2025-11-10 -0.0007738262 0.001836876  0.53698088
#> 2025-11-11 -0.0052309638 0.001862567 -2.65442772
#> 2025-11-12 -0.0007040583 0.002313670  0.78292205