This function sets and validates the specification of controls for model estimation with the {fHMM} package.
Usage
set_controls(controls = NULL)
# S3 method for fHMM_controls
print(x, ...)
Arguments
- controls
A
list
of controls, see below.Either none, all, or selected parameters can be specified. Unspecified parameters are set to default values (see the values in brackets below).
If
hierarchy = TRUE
, parameters marked with a(*)
must be avector
of length 2, where the first entry corresponds to the coarse-scale and the second entry to the fine-scale layer.hierarchy
(FALSE
): Alogical
, set toTRUE
for an hierarchical HMM.states
(*)
(2
): Aninteger
, the number of states of the underlying Markov chain.sdds
(*)
("t(df = Inf)"
): Acharacter
, specifying the state-dependent distribution. One of"t"
(the t-distribution), or"gamma"
(the gamma distribution), or"lnorm"
(the log-normal distribution). You can fix the parameters (meanmu
, standard deviationsigma
, degrees of freedomdf
) of these distributions via, e.g.,"t(df = Inf)"
or"gamma(mu = 0, sigma = 1)"
. To fix different values of a parameter for different states, separate by "|", e.g."t(mu = -1|1)"
.horizon
(*)
(100
): Anumeric
, specifying the length of the time horizon. The first entry ofhorizon
is ignored ifdata
is specified.period
("m"
): Only relevant ifhierarchy = TRUE
andhorizon[2] = NA
. In this case, acharacter
which specifies a flexible, periodic fine-scale time horizon and can be one of"w"
for a week,"m"
for a month,"q"
for a quarter,"y"
for a year.
data
(NA
): Alist
of controls specifying the data. Ifdata = NA
, data gets simulated (default). Otherwise:file
(*)
: Either:A
data.frame
, which must have a column nameddate_column
(with dates) anddata_column
(with financial data). Ifhierarchy = TRUE
, thisdata.frame
is used for both the coarse- and the fine-scale layer. To have different data sets for theses layers,file
can be alist
of twodata.frame
.A
character
, the path to a .csv-file with financial data, which must have a column nameddate_column
(with dates) anddata_column
(with financial data).
date_column
(*)
("Date"
): Acharacter
, the name of the column infile
with dates. Can beNA
in which case consecutive integers are used as time points.data_column
(*)
("Close"
): Acharacter
, the name of the column infile
with financial data.from
(NA
): Acharacter
of the format"YYYY-MM-DD"
, setting a lower data limit. No lower limit iffrom = NA
. Ignored ifcontrols$data$date_column
isNA
.to
(NA
): Acharacter
of the format"YYYY-MM-DD"
, setting an upper data limit. No upper limit iffrom = NA
. Ignored ifcontrols$data$date_column
isNA
.logreturns
(*)
(FALSE
): Alogical
, ifTRUE
the data is transformed to log-returns.merge
(function(x) mean(x)
): Only relevant ifhierarchy = TRUE
. In this case, afunction
with one argumentx
, which merges a numeric vector of fine-scale datax
into one coarse-scale observation. For example,merge = function(x) mean(x)
defines the mean of the fine-scale data as the coarse-scale observation,merge = function(x) mean(abs(x))
for the mean of the absolute values,merge = function(x) sum(abs(x))
for the sum of the absolute values,merge = function(x) (tail(x,1)-head(x,1))/head(x,1)
for the relative change of the first to the last fine-scale observation.
fit
: Alist
of controls specifying the model fitting:runs
(100
): Aninteger
, setting the number of randomly initialized optimization runs from which the best one is selected as the final model.origin
(FALSE
): Alogical
, ifTRUE
the optimization is initialized at the true parameter values. Only for simulated data. Iforigin = TRUE
, this setsrun = 1
andaccept = 1:5
.accept
(1:3
): Aninteger
(vector), specifying which optimization runs are accepted based on the output code ofnlm
.gradtol
(1e-6
): A positivenumeric
value, passed on tonlm
.iterlim
(200
): A positiveinteger
, passed on tonlm
.print.level
(0
): One of0
,1
, and2
to control the verbosity of the optimization, passed on tonlm
.steptol
(1e-6
): A positivenumeric
value, passed on tonlm
.
- x
An object of class
fHMM_controls
.- ...
Currently not used.
Examples
### HMM controls for simulation
controls <- list(
states = 2,
sdds = "t(mu = 0)",
fit = list("runs" = 50)
)
set_controls(controls)
#> fHMM controls:
#> * hierarchy: FALSE
#> * data type: simulated
#> * number of states: 2
#> * sdds: t(mu = 0)
#> * number of runs: 50
### HMM controls with empirical data
data <- download_data("^GDAXI", file = NULL)
controls <- list(
states = 3,
sdds = "lnorm",
data = list(
"file" = data,
"date_column" = "Date",
"data_column" = "Adj.Close"
)
)
set_controls(controls)
#> fHMM controls:
#> * hierarchy: FALSE
#> * data type: empirical
#> * number of states: 3
#> * sdds: lnorm()
#> * number of runs: 100
### HMM controls with empirical data from .csv-file
controls <- list(
states = 4,
sdds = "t",
data = list(
"file" = system.file("extdata", "dax.csv", package = "fHMM"),
"date_column" = "Date",
"data_column" = "Close",
"logreturns" = TRUE
)
)
set_controls(controls)
#> fHMM controls:
#> * hierarchy: FALSE
#> * data type: empirical
#> * number of states: 4
#> * sdds: t()
#> * number of runs: 100
### HHMM controls for simulation
controls <- list(
hierarchy = TRUE,
states = c(3, 2)
)
set_controls(controls)
#> fHMM controls:
#> * hierarchy: TRUE
#> * data type: simulated
#> * number of states: 3 2
#> * sdds: t() t()
#> * number of runs: 100
### HHMM controls with empirical data
controls <- list(
hierarchy = TRUE,
states = c(3, 2),
sdds = c("t", "t"),
data = list(
"file" = list(dax, vw),
"date_column" = c("Date", "Date"),
"data_column" = c("Close", "Close"),
"logreturns" = c(TRUE, TRUE)
)
)
set_controls(controls)
#> fHMM controls:
#> * hierarchy: TRUE
#> * data type: empirical
#> * number of states: 3 2
#> * sdds: t() t()
#> * number of runs: 100