knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "fHMM-" )
The {fHMM}
package allows for multiple hidden Markov model specifications, including different data transformations, state-dependent distributions, and a hierarchical model structure. This vignette^[This vignette was build using R r paste(R.Version()[c("major", "minor")], collapse = ".")
with the {fHMM}
r utils::packageVersion("fHMM")
package.] outlines what and how specifications are possible.
We first load the package via the familiar library()
call:
library("fHMM")
set_controls
functionThe {fHMM}
philosophy is to start the modeling process by setting all data, model, and estimation specifications. This is done by defining a named list
of controls and passing it to the set_controls()
function. The function checks the specifications and returns an fHMM_controls
object which stores all specifications and thereby provides required information for other {fHMM}
functionalities.
For demonstration, we list example specifications using data from the Deutscher Aktienindex DAX^[The download_data()
function is explained in the vignette on data management.] [@jan92]:
dax <- download_data(symbol = "^GDAXI") head(dax)
The following lines of code specify a 3-state HMM with state-dependent t-distributions on the data in the file dax.csv. The dates are provided in the column called Date and the data in the column called Close. The logreturns = TRUE
line transforms the index data to log-returns. The runs = 50
line sets the number of numerical optimization runs to 50.
controls <- list( states = 3, sdds = "t", data = list(file = dax, date_column = "Date", data_column = "Close", logreturns = TRUE), fit = list(runs = 50) ) set_controls(controls)
The following specifies a 2-state HMM with state-dependent Gamma distributions, where the expectation values for state 1 and 2 are fixed to 0.5 and 2, respectively. The model will be fitted to 500 data points (horizon = 500
), that are going to be simulated from this model specification.
controls <- list( states = 2, sdds = "gamma(mu = 0.5|2)", horizon = 500 ) set_controls(controls)
Specifying hierarchical HMMs is analogously, except that new parameters can be specified (for example period
, see below) and some parameters now can be specified for both hierarchies.
controls <- list( hierarchy = TRUE, horizon = c(100, 10), sdds = c("t(df = 1)", "t(df = Inf)"), period = "m" ) set_controls(controls)
The help page of the set_controls()
function provides an overview of all possible specifications, it can be accessed via help("set_controls", package = "fHMM")
.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.