svsample_roll {stochvol} | R Documentation |
Rolling Estimation of Stochastic Volatility Models
Description
svsample_roll
performs rolling window estimation based on svsample.
A convenience function for backtesting purposes.
Usage
svsample_roll(
y,
designmatrix = NA,
n_ahead = 1,
forecast_length = 500,
n_start = NULL,
refit_every = 1,
refit_window = c("moving", "expanding"),
calculate_quantile = c(0.01),
calculate_predictive_likelihood = TRUE,
keep_draws = FALSE,
parallel = c("no", "multicore", "snow"),
n_cpus = 1L,
cl = NULL,
...
)
svtsample_roll(
y,
designmatrix = NA,
n_ahead = 1,
forecast_length = 500,
n_start = NULL,
refit_every = 1,
refit_window = c("moving", "expanding"),
calculate_quantile = c(0.01),
calculate_predictive_likelihood = TRUE,
keep_draws = FALSE,
parallel = c("no", "multicore", "snow"),
n_cpus = 1L,
cl = NULL,
...
)
svlsample_roll(
y,
designmatrix = NA,
n_ahead = 1,
forecast_length = 500,
n_start = NULL,
refit_every = 1,
refit_window = c("moving", "expanding"),
calculate_quantile = c(0.01),
calculate_predictive_likelihood = TRUE,
keep_draws = FALSE,
parallel = c("no", "multicore", "snow"),
n_cpus = 1L,
cl = NULL,
...
)
svtlsample_roll(
y,
designmatrix = NA,
n_ahead = 1,
forecast_length = 500,
n_start = NULL,
refit_every = 1,
refit_window = c("moving", "expanding"),
calculate_quantile = c(0.01),
calculate_predictive_likelihood = TRUE,
keep_draws = FALSE,
parallel = c("no", "multicore", "snow"),
n_cpus = 1L,
cl = NULL,
...
)
Arguments
y |
numeric vector containing the data (usually log-returns), which
must not contain zeros. Alternatively, |
designmatrix |
regression design matrix for modeling the mean. Must
have |
n_ahead |
number of time steps to predict from each time window. |
forecast_length |
the time horizon at the end of the data set that is used for backtesting. |
n_start |
optional the starting time point for backtesting.
Computed from |
refit_every |
the SV model is refit every |
refit_window |
one of |
calculate_quantile |
vector of numbers between 0 and 1.
These quantiles are predicted using |
calculate_predictive_likelihood |
boolean. If |
keep_draws |
boolean. If |
parallel |
one of |
n_cpus |
optional positive integer, the number of CPUs to be used in case of
parallel computations. Defaults to |
cl |
optional so-called SNOW cluster object as implemented in package
|
... |
Any extra arguments will be forwarded to
|
Details
Functions svtsample_roll
, svlsample_roll
, and svtlsample_roll
are
wrappers around svsample_roll
with convenient default values for the SV
model with t-errors, leverage, and both t-errors and leverage, respectively.
Value
The value returned is a list object of class svdraws_roll
holding a list item for every time window. The elements of these list items are
indices |
a list object containing two elements: |
quantiles |
the input parameter |
refit_every |
the input parameter |
predictive_likelihood |
present only if |
predictive_quantile |
present only if |
fit |
present only if |
prediction |
present only if |
To display the output, use print
and summary
. The
print
method simply prints a short summary of the setup;
the summary
method displays the summary statistics
of the backtesting.
Note
The function executes svsample
(length(y) - arorder - n_ahead - n_start + 2) %/% refit_every
times.
See Also
svsim
, specify_priors
, svsample
Examples
# Simulate from the true model
sim <- svsim(200)
# Perform rolling estimation using the vanilla SV
# model and default priors
roll <- svsample_roll(sim, draws = 5000, burnin = 2000,
keep_draws = TRUE,
forecast_length = 10,
n_ahead = 1, refit_every = 1,
refit_window = "moving",
calculate_predictive_likelihood = TRUE,
calculate_quantile = c(0.01, 0.05))
# Perform rolling estimation by making use
# of two CPU cores, advanced priors, and multiple
# chains with pre-set initial values. Let us combine
# that with an AR(2) specification
prior_beta <- sv_multinormal(c(1,0,-1), rbind(c(1, 0, 0.1),
c(0, 0.3, -0.04),
c(0.1, -0.04, 0.1)))
priorspec <- specify_priors(rho = sv_beta(4, 4),
latent0_variance = sv_constant(1),
beta = prior_beta,
nu = sv_exponential(0.05))
startpara <- list(list(mu = -9, phi = 0.3),
list(mu = -11, sigma = 0.1, phi = 0.95),
list(phi = 0.99))
roll <- svsample_roll(sim, draws = 5000, burnin = 2000,
designmatrix = "ar2",
priorspec = priorspec,
startpara = startpara,
parallel = "snow", n_cpus = 2,
n_chains = 3,
keep_draws = TRUE,
forecast_length = 10,
n_ahead = 1, refit_every = 1,
refit_window = "expanding",
calculate_predictive_likelihood = TRUE,
calculate_quantile = c(0.01, 0.05))