svsim
is used to produce realizations of a stochastic volatility (SV)
process.
svsim(len, mu = -10, phi = 0.98, sigma = 0.2, nu = Inf, rho = 0)
length of the simulated time series.
level of the latent log-volatility AR(1) process. The defaults
value is -10
.
persistence of the latent log-volatility AR(1) process. The
default value is 0.98
.
volatility of the latent log-volatility AR(1) process. The
default value is 0.2
.
degrees-of-freedom for the conditional innovations distribution.
The default value is Inf
, corresponding to standard normal
conditional innovations.
correlation between the observation and the increment of the
log-volatility. The default value is 0
, corresponding to the basic
SV model with symmetric “log-returns”.
The output is a list object of class svsim
containing
vector of length len
containing the simulated data,
usually interpreted as “log-returns”.
vector of length
len
containing the simulated instantaneous volatilities.
These are \(e^{h_t/2}\) if nu == Inf
, and they are
\(e^{h_t/2} \sqrt{\tau_t}\) for finite nu
.
The initial volatility exp(h_0/2)
,
drawn from the stationary distribution of the latent AR(1) process.
a named list with five elements mu
, phi
,
sigma
, nu
, and rho
, containing
the corresponding arguments.
vector of the latent state space \(h_t\) for \(t > 0\).
initial element of the latent state space \(h_0\).
vector of length len
containing the simulated auxiliary
variables for the Student-t residuals when nu
is finite. More precisely,
\(\tau_t\sim\text{Gamma}^{-1}(\text{shape}=\nu/2, \text{rate}=\nu/2-1)\).
This function draws an initial log-volatility h_0
from the stationary
distribution of the AR(1) process defined by phi
, sigma
, and mu
.
Then the function jointly simulates the log-volatility series
h_1,...,h_n
with the given AR(1) structure, and the “log-return” series
y_1,...,y_n
with mean 0 and standard deviation exp(h/2)
.
Additionally, for each index i
, y_i
can be set to have a conditionally heavy-tailed
residual (through nu
) and/or to be correlated with (h_{i+1}-h_i)
(through rho
, the so-called leverage effect, resulting in asymmetric “log-returns”).
The function generates the “log-returns” by
y <- exp(-h/2)*rt(h, df=nu)
. That means that in the case of nu < Inf
the (conditional) volatility is sqrt(nu/(nu-2))*exp(h/2)
, and that corrected value
is shown in the print
, summary
and plot
methods.
To display the output use print
, summary
and plot
. The
print
method simply prints the content of the object in a moderately
formatted manner. The summary
method provides some summary statistics
(in %), and the plot
method plots the the simulated 'log-returns'
y
along with the corresponding volatilities vol
.
## Simulate a highly persistent SV process of length 500
sim <- svsim(500, phi = 0.99, sigma = 0.1)
print(sim)
#>
#> Simulated time series consisting of 500 observations.
#>
#> Parameters: level of latent variable mu = -10
#> persistence of latent variable phi = 0.99
#> standard deviation of latent variable sigma = 0.1
#> degrees of freedom parameter nu =Inf
#> leverage effect parameter rho =0
#>
#> Simulated initial volatility:
#>
#> Simulated volatilities:
#> [1] 0.015907069 0.016193497 0.017179078 0.016866800 0.015833470 0.015842958
#> [7] 0.016825366 0.017735585 0.018833324 0.019691748 0.020804049 0.020911755
#> [13] 0.019121696 0.019056433 0.019873982 0.020637770 0.019461271 0.019649044
#> [19] 0.018832389 0.018654884 0.017243205 0.016866332 0.017323483 0.016657508
#> [25] 0.017504286 0.018505460 0.017247198 0.017700566 0.018778357 0.017003188
#> [31] 0.016683387 0.016841123 0.017746707 0.017742363 0.017148342 0.016940584
#> [37] 0.015315130 0.014858431 0.015074745 0.013743255 0.014223835 0.013876409
#> [43] 0.011984397 0.011688812 0.012572206 0.013212553 0.011987267 0.011636264
#> [49] 0.010952586 0.011139929 0.010347756 0.010946268 0.010780958 0.010750832
#> [55] 0.010725502 0.009866819 0.009540662 0.009614348 0.009471144 0.009504632
#> [61] 0.009815671 0.010459158 0.010664889 0.010223718 0.010195123 0.009820834
#> [67] 0.009618836 0.009147073 0.009550042 0.010111706 0.010268613 0.009971045
#> [73] 0.010460348 0.010681344 0.011227781 0.011376839 0.010886376 0.009914172
#> [79] 0.009429624 0.009358801 0.009005871 0.009234405 0.009473038 0.009337662
#> [85] 0.009371118 0.009360765 0.009008895 0.009089946 0.008658796 0.008266164
#> [91] 0.008980955 0.009370295 0.008994249 0.008573450 0.009003462 0.009821916
#> [97] 0.009316496 0.009303706 0.008814199 0.009085555
#> [ reached 'max' / getOption("max.print") -- omitted 400 entries ]
#>
#> Simulated data (usually interpreted as 'log-returns'):
#> [1] -3.969030e-03 -1.215136e-02 -2.706969e-03 -2.374154e-02 -7.290831e-03
#> [6] 1.046361e-02 1.794292e-02 5.212101e-02 -6.175532e-03 3.533751e-02
#> [11] 1.605891e-02 -1.021839e-02 -1.242957e-02 -2.476756e-02 -3.517744e-03
#> [16] -1.495995e-02 -1.755270e-02 -3.763230e-02 -1.895578e-03 1.180033e-02
#> [21] -1.858776e-02 3.087943e-04 -1.880178e-02 5.300126e-03 -6.032260e-03
#> [26] 5.349748e-03 -7.704827e-03 -5.462076e-03 -5.316698e-03 -3.614345e-02
#> [31] -4.153305e-03 7.543184e-03 4.464773e-03 1.518142e-02 3.315657e-02
#> [36] -4.142350e-02 -6.195167e-03 4.746447e-03 8.493743e-03 -9.886793e-03
#> [41] -1.148955e-02 2.115346e-03 2.654128e-02 1.994909e-03 1.121060e-02
#> [46] 2.440846e-02 -1.124319e-02 1.746895e-02 2.072201e-04 -1.118960e-02
#> [51] -5.397190e-03 -5.441076e-03 -8.536594e-03 -1.396120e-02 9.030751e-05
#> [56] 8.995379e-03 1.277140e-02 -5.363889e-03 2.587980e-03 6.414431e-03
#> [61] -6.682063e-03 -1.192983e-02 -1.920092e-02 -4.221218e-03 -1.789951e-02
#> [66] -5.777159e-03 2.208995e-03 -1.482384e-02 -1.009700e-02 1.980647e-03
#> [71] 9.737758e-03 1.653016e-02 -1.494304e-02 8.712350e-04 1.553118e-03
#> [76] 1.296252e-03 -7.962888e-03 6.037010e-03 -1.310788e-02 1.093777e-02
#> [81] -8.060470e-03 4.650313e-03 9.637966e-03 -8.665575e-03 -2.699718e-03
#> [86] -4.945736e-03 -5.367568e-03 1.086371e-02 -2.116018e-03 -4.693009e-03
#> [91] 2.011409e-04 -1.094738e-02 -3.264564e-03 8.078598e-03 9.516503e-03
#> [96] 1.835326e-02 8.309279e-03 1.022609e-03 3.816490e-03 1.112855e-03
#> [ reached 'max' / getOption("max.print") -- omitted 400 entries ]
summary(sim)
#>
#> Simulated time series consisting of 500 observations.
#>
#> Parameters: level of latent variable mu = -10
#> persistence of latent variable phi = 0.99
#> standard deviation of latent variable sigma = 0.1
#> degrees of freedom parameter nu = Inf
#> leverage effect parameter rho = 0
#>
#> Simulated initial volatility (in %): 1.6412
#>
#> Summary of simulated volatilities (in %):
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 0.5490 0.7119 0.8128 0.9117 0.9961 2.0912
#>
#> Summary of simulated data (in %):
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> -4.142351 -0.583748 -0.018901 -0.005966 0.577108 5.212101
plot(sim)
## Simulate an SV process with leverage
sim <- svsim(200, phi = 0.94, sigma = 0.15, rho = -0.6)
print(sim)
#>
#> Simulated time series consisting of 200 observations.
#>
#> Parameters: level of latent variable mu = -10
#> persistence of latent variable phi = 0.94
#> standard deviation of latent variable sigma = 0.15
#> degrees of freedom parameter nu =Inf
#> leverage effect parameter rho =-0.6
#>
#> Simulated initial volatility:
#>
#> Simulated volatilities:
#> [1] 0.009703500 0.010022098 0.010501716 0.008882753 0.008183094 0.007942060
#> [7] 0.007516569 0.007819044 0.007897037 0.007802039 0.008159595 0.009360950
#> [13] 0.008470274 0.008031672 0.009391579 0.008871742 0.009194121 0.009772812
#> [19] 0.008089427 0.007556203 0.007699186 0.007774771 0.007711596 0.008210184
#> [25] 0.008371405 0.009404426 0.009762090 0.008885701 0.007751540 0.007789072
#> [31] 0.007484955 0.008649647 0.008741126 0.007917881 0.007412780 0.007767126
#> [37] 0.007962480 0.008247743 0.008636282 0.009640990 0.008924358 0.009193979
#> [43] 0.008439178 0.008140419 0.007673452 0.007669002 0.008261266 0.007820852
#> [49] 0.008514471 0.008448413 0.008730144 0.008121128 0.008356181 0.008371849
#> [55] 0.008111253 0.008885874 0.009185775 0.008573316 0.008133314 0.007135916
#> [61] 0.006822723 0.006581159 0.007087249 0.006958187 0.006787221 0.006906403
#> [67] 0.007583221 0.007918690 0.008019944 0.008095877 0.008328218 0.009196445
#> [73] 0.008657464 0.008608132 0.007815417 0.008269744 0.008113261 0.008582650
#> [79] 0.007809957 0.006710307 0.007049800 0.007264336 0.007580632 0.007977967
#> [85] 0.007827850 0.007863885 0.007588011 0.007030945 0.007663257 0.007610451
#> [91] 0.008357320 0.007779638 0.007751282 0.008232950 0.009125877 0.008652853
#> [97] 0.007990447 0.008039084 0.007595469 0.007362902
#> [ reached 'max' / getOption("max.print") -- omitted 100 entries ]
#>
#> Simulated data (usually interpreted as 'log-returns'):
#> [1] 9.436547e-04 -2.360620e-02 5.903689e-03 8.579462e-03 3.542240e-03
#> [6] 2.380605e-03 -6.239023e-03 -7.515571e-04 -1.837936e-03 -1.252597e-02
#> [11] -7.835953e-03 1.815418e-02 -1.013761e-03 -1.044752e-02 1.327759e-03
#> [16] 9.569685e-03 5.213755e-03 1.812641e-02 4.410174e-04 -4.128435e-03
#> [21] -1.597301e-02 -7.823126e-03 -5.207362e-03 -9.920093e-03 -1.323487e-02
#> [26] 4.577616e-03 4.391776e-03 -5.548474e-03 -4.035377e-03 4.014632e-03
#> [31] -7.478271e-04 -2.460593e-03 1.159910e-02 1.004549e-02 1.257747e-03
#> [36] -7.304583e-03 -6.881658e-03 -2.007032e-03 -7.247942e-03 4.799292e-03
#> [41] 8.976654e-03 1.588182e-02 5.980156e-03 1.207733e-03 4.094558e-03
#> [46] -1.919329e-03 -3.408738e-04 -1.126864e-02 -7.084734e-03 -8.004682e-03
#> [51] 1.092655e-02 4.076029e-04 5.053734e-03 3.273430e-03 -1.102271e-02
#> [56] 5.652853e-04 -1.067616e-02 5.417791e-03 1.359848e-02 5.153905e-03
#> [61] 1.123964e-02 6.339751e-03 -5.283219e-03 -6.310941e-03 -4.281266e-03
#> [66] -1.356626e-02 6.542819e-03 -6.995614e-03 -6.585203e-04 1.820212e-04
#> [71] 1.572947e-04 9.714666e-04 -1.228683e-02 1.840981e-02 8.644541e-03
#> [76] -1.053495e-02 1.042914e-02 -2.990235e-03 1.921724e-02 -5.019629e-03
#> [81] 2.668696e-03 -3.636292e-03 -5.809581e-03 -8.453075e-03 -9.982781e-03
#> [86] -3.618157e-03 -4.300613e-03 -2.429510e-03 4.209342e-05 -2.889963e-03
#> [91] 3.377921e-05 5.366702e-03 -7.045191e-03 -4.675417e-03 7.943945e-03
#> [96] 1.372171e-02 -7.427816e-04 -6.042386e-03 7.623050e-03 -3.982789e-03
#> [ reached 'max' / getOption("max.print") -- omitted 100 entries ]
summary(sim)
#>
#> Simulated time series consisting of 200 observations.
#>
#> Parameters: level of latent variable mu = -10
#> persistence of latent variable phi = 0.94
#> standard deviation of latent variable sigma = 0.15
#> degrees of freedom parameter nu = Inf
#> leverage effect parameter rho = -0.6
#>
#> Simulated initial volatility (in %): 0.9949426
#>
#> Summary of simulated volatilities (in %):
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 0.5375 0.7485 0.8104 0.8141 0.8854 1.1188
#>
#> Summary of simulated data (in %):
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> -2.81587 -0.67627 -0.07965 -0.09634 0.48629 2.05180
plot(sim)
## Simulate an SV process with conditionally heavy-tails
sim <- svsim(250, phi = 0.91, sigma = 0.05, nu = 5)
print(sim)
#>
#> Simulated time series consisting of 250 observations.
#>
#> Parameters: level of latent variable mu = -10
#> persistence of latent variable phi = 0.91
#> standard deviation of latent variable sigma = 0.05
#> degrees of freedom parameter nu =5
#> leverage effect parameter rho =0
#>
#> Simulated initial volatility:
#>
#> Simulated volatilities:
#> [1] 0.007117304 0.003124488 0.004099299 0.006894685 0.003398688 0.004263595
#> [7] 0.004122176 0.004513049 0.004788633 0.004554743 0.009622520 0.006077362
#> [13] 0.003548397 0.008747726 0.005504351 0.004424414 0.005798857 0.004911596
#> [19] 0.005147055 0.004338344 0.007084922 0.004598163 0.004613729 0.005144067
#> [25] 0.005803849 0.005333018 0.004468676 0.013496884 0.004062223 0.003476179
#> [31] 0.005424856 0.004258867 0.003363024 0.003984611 0.003526481 0.006103780
#> [37] 0.005961445 0.008764194 0.004306725 0.009634816 0.018578918 0.003888194
#> [43] 0.005096594 0.007794913 0.005265252 0.004708854 0.005852598 0.010273163
#> [49] 0.009495415 0.010638201 0.003680086 0.005832722 0.005314855 0.004614270
#> [55] 0.004059608 0.003331623 0.004206021 0.004490159 0.003587506 0.006015633
#> [61] 0.003742721 0.004783929 0.004428409 0.004708123 0.008279515 0.008322414
#> [67] 0.006129627 0.005151068 0.003701416 0.003673100 0.005775463 0.005499252
#> [73] 0.006740831 0.004618683 0.012584694 0.003608858 0.005932499 0.008801510
#> [79] 0.007950287 0.008358306 0.007657283 0.004097484 0.005319485 0.003985723
#> [85] 0.008957878 0.007721676 0.008349785 0.008042774 0.003890334 0.003960035
#> [91] 0.002881378 0.004664967 0.005983061 0.004224835 0.004575135 0.004992448
#> [97] 0.004200940 0.006820723 0.006228872 0.010929963
#> [ reached 'max' / getOption("max.print") -- omitted 150 entries ]
#>
#> Simulated data (usually interpreted as 'log-returns'):
#> [1] 1.221232e-02 -1.712724e-03 -4.378564e-03 1.484838e-03 -1.834531e-03
#> [6] 3.913578e-03 7.306117e-03 5.451776e-03 -2.638818e-03 -1.668017e-03
#> [11] -9.495726e-03 -6.869796e-03 -3.206065e-03 1.191037e-03 -5.849334e-03
#> [16] -6.564598e-04 -5.656470e-04 -4.020850e-03 6.154094e-03 -9.224553e-03
#> [21] 9.735579e-03 5.695014e-04 5.457701e-04 1.203832e-03 -9.404973e-03
#> [26] 4.307254e-04 1.847334e-03 5.399886e-03 -4.950877e-03 -1.124842e-03
#> [31] 8.829133e-03 -5.091649e-03 -2.643414e-04 9.226418e-04 -7.469575e-04
#> [36] -1.468715e-03 -8.994753e-03 -5.194405e-03 -1.443015e-03 5.120418e-03
#> [41] -2.783532e-02 -2.408150e-03 -3.615306e-03 2.794873e-03 -5.603209e-04
#> [46] 1.348216e-03 -1.114131e-02 -3.447357e-03 -3.041226e-03 -4.963826e-03
#> [51] 9.706121e-04 4.880160e-04 -4.817528e-03 2.983846e-03 2.785203e-03
#> [56] -1.179717e-03 -1.257322e-03 6.196002e-03 4.284977e-03 -9.693352e-03
#> [61] -1.350533e-03 -5.656021e-04 3.985322e-03 -3.368650e-03 -1.429626e-03
#> [66] 2.317280e-03 -4.048001e-03 -6.046355e-03 7.748354e-05 -1.951043e-03
#> [71] -1.427238e-03 -1.099385e-02 -5.297270e-03 8.980021e-03 2.031050e-02
#> [76] -2.717464e-03 1.383248e-02 -6.890779e-03 -1.062643e-03 1.352003e-03
#> [81] 2.751582e-04 2.431401e-04 4.522979e-04 -2.567620e-03 1.601748e-02
#> [86] 1.574892e-02 8.972956e-03 -5.121634e-03 -1.897857e-03 -9.320091e-03
#> [91] -1.135918e-03 -4.829697e-03 1.887612e-03 2.275794e-03 -4.510480e-03
#> [96] -4.778371e-03 2.904833e-04 1.077729e-02 1.972570e-03 -8.639840e-03
#> [ reached 'max' / getOption("max.print") -- omitted 150 entries ]
summary(sim)
#>
#> Simulated time series consisting of 250 observations.
#>
#> Parameters: level of latent variable mu = -10
#> persistence of latent variable phi = 0.91
#> standard deviation of latent variable sigma = 0.05
#> degrees of freedom parameter nu = 5
#> leverage effect parameter rho = 0
#>
#> Simulated initial volatility (in %): 0.6380607
#>
#> Summary of simulated volatilities (in %):
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 0.2881 0.4498 0.5596 0.6382 0.7421 3.7613
#>
#> Summary of simulated data (in %):
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> -2.783532 -0.399493 -0.026350 0.004763 0.370979 2.576650
plot(sim)