Skip to contents

Generates shocks driven by a Cox-Ingersoll-Ross (square-root) stochastic variance process, Euler-Maruyama discretized, for use as sim_psy1(..., e = sim_vol_cir(...)).

Usage

sim_vol_cir(
  n,
  kappa = 0.03,
  theta = 0.25,
  xi = 0.1,
  sigma0_sq = theta,
  seed = NULL
)

Arguments

n

Number of innovations to generate.

kappa, theta, xi

Positive CIR parameters (mean-reversion speed, long-run variance, vol-of-vol).

sigma0_sq

Non-negative starting variance. Defaults to theta.

seed

An object specifying if and how the random number generator (rng) should be initialized. Either NULL or an integer will be used in a call to set.seed before simulation. If set, the value is saved as "seed" attribute of the returned value. The default, NULL, will not change rng state, and return .Random.seed as the "seed" attribute. Results are reproducible across the parallel and non-parallel option when the same seed is used.

Value

A numeric vector of length n.

Details

$$d\sigma^2(r) = \kappa(\theta - \sigma^2(r))dr + \xi\sigma(r)dB(r)$$

discretized over n steps of r in \([0, 1]\), with variance reflected at zero if a step would take it negative. Default parameters (\(\kappa=0.03\), \(\theta=0.25\), \(\xi=0.1\)) match Harvey, Leybourne & Zu (2019)'s robustness design, "representative of Bollerslev and Zhou (2002)".

References

Harvey, D.I., Leybourne, S.J. & Zu, Y. (2019). "Testing explosive bubbles with time-varying volatility." Econometric Reviews, 38(10), 1131-1151.

See also

Examples

sim_vol_cir(199, seed = 1)
#>   [1]  0.205987356 -0.189689995  0.204056300  0.836760778  0.795004781
#>   [6] -0.166196633 -1.141081285  1.251459377  0.335976136  0.273748433
#>  [11] -0.006761588  0.260126532 -0.084048984  0.214181382 -0.200604067
#>  [16] -0.692191057  0.498870406  0.767401466 -0.156929028 -0.640667816
#>  [21]  0.329654725 -0.023093742 -0.900052202  0.001107622 -0.323000038
#>  [26] -0.175477623 -0.594991013  0.926614335 -0.168429318 -0.813912001
#>  [31]  0.100258326  0.135066518 -0.505582926 -1.485546708 -0.329226292
#>  [36]  0.290458463 -0.030318427 -0.049702776  0.283795823 -0.604998689
#>  [41]  0.562225617 -0.002736307  0.361527836  0.531110409  0.115217600
#>  [46] -0.450874375  0.593803936 -1.023852553 -0.280348815 -0.131465509
#>  [51] -0.085936079  0.529331575  0.070364056  0.210809074 -0.035783352
#>  [56] -0.128482408  0.365683134  0.601126992 -1.251343888  0.299390368
#>  [61]  0.195700426 -0.225686359  0.504558734 -0.207456991 -0.151570396
#>  [66]  0.454797629  0.913287760  0.141685714 -0.223681822 -0.630657217
#>  [71] -0.178095863 -0.507204854 -0.139085533  0.212690473 -0.456576439
#>  [76]  1.408060004  0.083082130  0.600094395 -1.215430942  0.393633068
#>  [81] -0.696451207  0.484824784  0.209660360 -0.216303098  0.695680044
#>  [86] -0.369852550 -0.306917092 -0.532928868 -0.354985988  0.503386051
#>  [91]  0.231389001  0.534331814 -0.209044586  0.203217679  0.132437789
#>  [96] -0.781589933  0.978082192  0.073330296  0.416008606  0.514830420
#> [101] -0.027170270 -0.163647113  0.478349043 -0.557181217  1.049880885
#> [106] -0.203418215  0.887392672  0.815075089  0.044984502  0.308318434
#> [111] -0.562972422  0.176755082  0.569366567  0.054554543 -0.249003707
#> [116] -0.359078903 -0.019619302  0.582709567 -0.263291456 -0.066042628
#> [121] -0.705469009  0.268571486  0.716803656  0.819312982  0.445352888
#> [126] -1.021433231  0.264535957  0.250203313 -0.193800461  0.093080351
#> [131] -0.470728789  0.370186908 -0.177586808 -0.854813379 -0.198192064
#> [136]  0.737409093 -0.178830744  0.391213611  0.503599717  0.002329976
#> [141] -0.186551130 -0.276848690  0.389620603 -0.553920945  0.127837440
#> [146] -0.149163407 -1.160927164 -0.732488058  0.476309591 -0.098584281
#> [151]  0.409308853  0.964757314  0.753255231  0.345365554  0.192501509
#> [156] -0.096655978  0.785010735  0.298736189 -0.585416992 -0.076871879
#> [161] -0.960381333 -0.098017438 -1.299119879  0.663410641 -0.322861748
#> [166] -0.217486940 -0.086956379  0.313860185  0.344315080  0.287992242
#> [171] -0.290740273 -0.703349082 -0.200694342  0.143933744 -0.426052356
#> [176] -0.035552436 -0.602884744 -0.004313205  0.067829593 -0.077317874
#> [181] -0.087575294  0.934503489  0.406740793  0.593664355 -0.488296134
#> [186]  0.087224801  0.612270709 -0.030258536 -1.134137717  0.183143129
#> [191] -1.005416030 -0.427614512  0.699837697  0.323807977  0.577387608
#> [196]  0.160844875 -0.057378231 -0.486141104  0.832029629