Learn R Programming

pmhtutorial (version 1.0.0)

sm_sv: Bootstrap particle filter for state estimate in a simple stochastic volatility model

Description

Estimates the filtered state and the log-likelihood for a stochastic volatility model of the form \(x_t = \mu + \phi ( x_{t-1} - \mu ) + \sigma_v v_t\) and \(y_t = \exp(x_t/2) e_t\), where \(v_t\) and \(e_t\) denote independent standard Gaussian random variables, i.e. \(N(0,1)\).

Usage

sm_sv(y, mu, phi, sigmav, nPart, T)

Arguments

y

Observations from the model for \(t=1,...,T\).

mu

The mean of the log-volatility process \(\mu\).

phi

The persistence of the log-volatility process \(\phi\).

sigmav

The standard deviation of the log-volatility process \(\sigma_v\).

nPart

The number of particles to use in the filter.

T

The number of observations.

Value

The function returns a list with the elements:

  • xh: The estimate of the filtered state at time \(t=1,...,T\).

  • ll: The estimate of the log-likelihood.

References

Dahlin, J. & Schoen, T. B. "Getting started with particle Metropolis-Hastings for inference in nonlinear dynamical models." pre-print, arXiv:1511.01707, 2015.

Examples

Run this code
# NOT RUN {
## Get the data
library("Quandl")
d <- Quandl("NASDAQOMX/OMXS30", start_date="2012-01-02", 
            end_date="2014-01-02", type="zoo")
y <- as.numeric(100 * diff(log(d$"Index Value")))

## Estimate the filtered state
xhatf <- sm_sv(y, mu=-0.10, phi=0.97, sigmav=0.15, nPart=500, 
               T=500 )$xh

## Plot the data and the log-volatility estimate
par(mfrow=c(2,1))
plot(y, type="l", xlab="time", ylab="log-returns")
plot(xhatf, type="l", xlab="time", ylab="estimate of log-volatility")
# }

Run the code above in your browser using DataLab