The {fHMM}
package allows for multiple hidden Markov
model specifications, including different data transformations,
state-dependent distributions, and a hierarchical model structure. This
vignette1
outlines what and how specifications are possible.
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 DAX2 (Janßen and Rudolph 1992):
download_data(symbol = "^GDAXI", file = "dax.csv")
#> Download successful.
#> * symbol: ^GDAXI
#> * from: 1987-12-30
#> * to: 2023-02-13
#> * path: C:\Users\Lennart\AppData\Local\Temp\Rtmp42gnFG\Rbuild186c5f42744c\fHMM\vignettes\dax.csv
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.
<- list(
controls states = 3,
sdds = "t",
data = list(file = "dax.csv",
date_column = "Date",
data_column = "Close",
logreturns = TRUE),
fit = list(runs = 50)
)set_controls(controls)
#> fHMM controls:
#> * hierarchy: FALSE
#> * data type: empirical
#> * number of states: 3
#> * sdds: t()
#> * number of runs: 50
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.
<- list(
controls states = 2,
sdds = "gamma(mu = 0.5|2)",
horizon = 500
)set_controls(controls)
#> fHMM controls:
#> * hierarchy: FALSE
#> * data type: simulated
#> * number of states: 2
#> * sdds: gamma(mu = 0.5|2)
#> * number of runs: 100
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.
<- list(
controls hierarchy = TRUE,
horizon = c(100, 10),
sdds = c("t(df = 1)", "t(df = Inf)"),
period = "m"
)set_controls(controls)
#> fHMM controls:
#> * hierarchy: TRUE
#> * data type: simulated
#> * number of states: 2 2
#> * sdds: t(df = 1) t(df = Inf)
#> * number of runs: 100
The help page of the set_controls()
function provides an
overview of all possible specifications.
?set_controls
set_controls | R Documentation |
controls
|
A Either none, all, or selected parameters can be specified. Unspecified parameters are set to default values (see the values in brackets below).
If
|
x
|
An object of class |
…
|
Currently not used. |