Title: | Likelihood Estimation of Stochastic Volatility Models |
---|---|
Description: | Parameter estimation for stochastic volatility models using maximum likelihood. The latent log-volatility is integrated out of the likelihood using the Laplace approximation. The models are fitted via 'TMB' (Template Model Builder) (Kristensen, Nielsen, Berg, Skaug, and Bell (2016) <doi:10.18637/jss.v070.i05>). |
Authors: | Jens Christian Wahl <[email protected]> |
Maintainer: | Jens Christian Wahl <[email protected]> |
License: | GPL-3 |
Version: | 0.2.0 |
Built: | 2024-11-04 05:51:57 UTC |
Source: | https://github.com/jenswahl/stochvoltmb |
Estimate parameters of a stochastic volatility model with a latent log-volatility following an autoregressive process of order one with normally distributed noise. The following distributions are implemented for the observed process:
Gaussian distribution
t-distribution
Leverage: Gaussian distribution with leverage where the noise of the latent process is correlated with the observational distribution
Skew gaussian distribution
The parameters is estimated by minimizing the negative log-likelihood (nll) and the latent log-volatility is integrated out by applying the Laplace approximation.
estimate_parameters(data, model = "gaussian", opt.control = NULL, ...)
estimate_parameters(data, model = "gaussian", opt.control = NULL, ...)
data |
A vector of observations. |
model |
A character specifying the model. Must be one of the following: "gaussian", "t", "leverage", "skew_gaussian". |
opt.control |
An optional list of parameters for nlminb. |
... |
additional arguments passed to MakeADFun. |
Object of class stochvolTMB
# load data data("spy") # estimate parameters opt <- estimate_parameters(spy$log_return, model = "gaussian") # get parameter estimates with standard error estimates <- summary(opt) # plot estimated volatility with 95 % confidence interval plot(opt, include_ci = TRUE)
# load data data("spy") # estimate parameters opt <- estimate_parameters(spy$log_return, model = "gaussian") # get parameter estimates with standard error estimates <- summary(opt) # plot estimated volatility with 95 % confidence interval plot(opt, include_ci = TRUE)
Logit transformation from the real line to (-1, 1).
logit(x)
logit(x)
x |
double |
double
Displays the estimated latent volatility process over time.
## S3 method for class 'stochvolTMB' plot(x, ..., include_ci = TRUE, plot_log = TRUE, dates = NULL, forecast = NULL)
## S3 method for class 'stochvolTMB' plot(x, ..., include_ci = TRUE, plot_log = TRUE, dates = NULL, forecast = NULL)
x |
A |
... |
Currently not used. |
include_ci |
Logical value indicating if volatility should be plotted with approximately 95% confidence interval. |
plot_log |
Logical value indicating if the estimated should be plotted
on log or original scale. If |
dates |
Vector of length ncol(x$nobs), providing optional dates for labeling the x-axis. The default value is NULL; in this case, the axis will be labeled with numbers. |
forecast |
Integer specifying number of steps to forecast. |
ggplot object with plot of estimated estimated volatility.
Takes a stochvolTMB
object and produces draws from the predictive distribution of the latent volatility
and future log-returns.
## S3 method for class 'stochvolTMB' predict(object, steps = 1L, nsim = 10000, include_parameters = TRUE, ...)
## S3 method for class 'stochvolTMB' predict(object, steps = 1L, nsim = 10000, include_parameters = TRUE, ...)
object |
A |
steps |
Integer specifying number of steps to predict. |
nsim |
Number of draws from the predictive distribution. |
include_parameters |
Logical value indicating if fixed parameters should be simulated from their asymptotic distribution, i.e. multivariate normal with inverse hessian as covariance matrix. |
... |
Not is use. |
List of simulated values from the predictive distribution of the latent volatilities and log-returns.
This function is very time consuming and by default computes the one-step-ahead residual for the last 100 observations. See the function oneStepPredict and the paper in the references for more details.
residuals(object, conditional = 1:(object$nobs - 100), ...)
residuals(object, conditional = 1:(object$nobs - 100), ...)
object |
A |
conditional |
Index vector of observations that are fixed during OSA. By default the residuals of the last 100
observations are calculated. If set to |
... |
Currently not used. |
Vector of one-step-ahead residuals. If the model is correctly specified, these should be standard normal.
This function draws the initial log-volatility (h_t
) from its stationary distribution, meaning that h_0
is drawn from a gaussian distribution with mean zero and standard deviation sigma_h
/ sqrt(1 - phi^2)
.
h_{t+1}
is then simulated from its conditional distribution given h_t
,
which is N(phi*h_t
, sigma_h
). Log-returns (y_t
) is
simulated from its conditional distribution given the latent process h
. If model
= "gaussian",
then y_t
given h_t
is gaussian with mean zero and standard deviation equal to
sigma_y*exp(h_t / 2)
. Heavy tail returns can be obtained by simulating from
the t-distribution by setting model
= "t". How heavy of a tail is specified by the degree of freedom
parameter df
. Note that the observations are scaled by sqrt((df-2)/2)
so that the error term has
variance equal to one. Asymmetric returns are obtained from the "skew_gaussian" model. How asymmetric is governed by
the skewness parameter alpha
. The so called leverage model, where we allow for correlation between
log-returns and volatility can be simulated by setting model
to "leverage" and specifying the
correlation parameter rho
.
sim_sv( param = list(phi = 0.9, sigma_y = 0.4, sigma_h = 0.2, df = 4, alpha = -2, rho = -0.7), nobs = 1000L, seed = NULL, model = "gaussian" )
sim_sv( param = list(phi = 0.9, sigma_y = 0.4, sigma_h = 0.2, df = 4, alpha = -2, rho = -0.7), nobs = 1000L, seed = NULL, model = "gaussian" )
param |
List of parameters. This includes the standard deviation of the observations, |
nobs |
Length of time series. |
seed |
Seed to reproduce simulation. |
model |
Distribution of error term. |
data.table with columns y
(observations) and h
(latent log-volatility).
Sampling is done on the scale the parameters were estimated. The standard deviations are simulated on log-scale and the persistence is simulated on logit scale. The same is true for the correlation parameter in the leverage model.
simulate_parameters(object, nsim = 1000)
simulate_parameters(object, nsim = 1000)
object |
A |
nsim |
Number of simulations. |
matrix of simulated values.
A dataset containing the prices and log-returns of the S&P500 from 2005 to 2018
spy
spy
A data frame with 3522 rows and 3 variables:
date
price, in US dollars
logarithmic return
...
Extract parameters, transformed parameters and latent log volatility along with standard error, z-value and p-value
## S3 method for class 'stochvolTMB' summary(object, ..., report = c("all", "fixed", "transformed", "random"))
## S3 method for class 'stochvolTMB' summary(object, ..., report = c("all", "fixed", "transformed", "random"))
object |
A |
... |
Currently not used. |
report |
Parameters to report with uncertainty estimates. Can be any subset of "fixed", "transformed" or "random" (see summary.sdreport). "fixed" report the parameters on the scale they were estimated, for example are all standard deviations estimated on log scale. "transformed" report all transformed parameters, for example estimated standard deviations transformed from log scale by taking the exponential. Lastly, "random" report the estimated latent log-volatility. |
data.table
with parameter estimates, standard error, z-value and approximated p-value.
Calculate quantiles based on predictions from the predictive distribution
## S3 method for class 'stochvolTMB_predict' summary(object, ..., quantiles = c(0.025, 0.975), predict_mean = TRUE)
## S3 method for class 'stochvolTMB_predict' summary(object, ..., quantiles = c(0.025, 0.975), predict_mean = TRUE)
object |
A |
... |
Not used. |
quantiles |
A numeric vector specifying which quantiles to calculate. |
predict_mean |
bool. Should the mean be predicted? |
A list of data.table
s. One for y
, h
and h_exp
.