Fits a stochastic volatility model to a univariate time series of returns.
SV.mcmc(y, nmcmc = 1000, burnin = 100, init = NULL, hyper = NULL, tuning = NULL,
sigma_MH = NULL, npart = NULL, mcmseed = NULL)
Returned invisibly:
vector of sampled state AR parameter
vector of sampled state error stnd deviation
vector of sampled observation error scale
matrix of sampled log-volatility
values of the input arguments
single time series of returns
number of iterations for the MCMC procedure
number of iterations to discard for the MCMC procedure
initial values of (phi, sigma, beta) - default is c(0.9, 0.5, .1)
hyperparameters for bivariate normal distribution of (phi, sigma); user inputs (mu_phi, mu_q, sigma_phi, sigma_q, rho) -
default is c(0.9, 0.5, 0.075, 0.3, -0.25)
tuning parameter - default is .03
covariance matrix used for random walk Metropolis; it will be scaled by tuning
in the script - default is
matrix(c(1,-.25,-.25,1), nrow=2, ncol=2)
number of particles used in particle filter - default is 10
seed for mcmc - default is 90210
D.S. Stoffer
The log-volatility process is \(x_t\) and the returns are \(y_t\). The SV model is $$x_t = \phi x_{t-1} + \sigma w_t \qquad y_t = \beta \exp\{\frac{1}{2} x_t\}\epsilon_t$$ where \(w_t\) and \(\epsilon_t\) are independent standard normal white noise.
The model is fit using a technique described in the paper listed below (in the Source section) where the state
parameters \((\phi, \sigma)\) are sampled simultaneously with a bivariate normal prior specified
in the arguments init
and hyper
.
Two graphics are returned: (1) the three parameter traces with the posterior mean highlighted, their ACFs [with effective sample sizes (ESS)], and their histograms with the .025, .5, and .975 quantiles displayed, and (2) the log-volatility posterior mean along with corresponding .95 credible intervals.
You can find demonstrations of astsa capabilities at FUN WITH ASTSA.
The most recent version of the package can be found at https://github.com/nickpoison/astsa/.
In addition, the News and ChangeLog files are at https://github.com/nickpoison/astsa/blob/master/NEWS.md.
The webpages for the texts and some help on using R for time series analysis can be found at https://nickpoison.github.io/.
SV.mle
if (FALSE) {
#-- A minimal example --##
myrun <- SV.mcmc(sp500w) # results in object myrun - don't forget it
str(myrun) # an easy way to see the default input options
}
Run the code above in your browser using DataLab