This function sets and checks the specification of controls for the fHMM package.
Arguments
- controls
A list of controls. Either none, all, or selected parameters can be specified. Unspecified parameters are set to default values (the values in brackets). If
hierarchy = TRUE
, parameters with a(*)
must be a vector of length 2, where the first entry corresponds to the coarse-scale and the second entry to the fine-scale layer.hierarchy
(FALSE
): A boolean, set toTRUE
for an hierarchical HMM.states
(*)
(2
): The number of states of the underlying Markov chain.sdds
(*)
("t(df = Inf)"
): Specifying the state-dependent distribution, one of"t"
, or"gamma"
(the gamma distribution), or"lnorm"
(the log-normal distribution). You can fix the parameters (meanmu
, standard deviation \ codesigma, degrees of freedomdf
) of these distributions, e.g."t(df = Inf)"
or"gamma(mu = 0, sigma = 1)"
, respectively. To fix different values of one parameter for different states, separate by "|", e.g."t(mu = -1|1)"
.horizon
(*)
(100
): A numeric, 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_integer_
. In this case, it 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
): A list of controls specifying the data. Ifdata = NA
, data gets simulated. Otherwise:file
(*)
: 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"
): A character, the name of the column infile
with dates. Can beNA_character_
in which case consecutive integers are used as time points.data_column
(*)
("Close"
): A character, the name of the column infile
with financial data.from
(NA_character_
): A character of the format"YYYY-MM-DD"
, setting a lower data limit. No lower limit iffrom = NA_character_
. Ignored ifcontrols$data$date_column
isNA
.to
(NA_character_
): A character of the format"YYYY-MM-DD"
, setting an upper data limit. No upper limit iffrom = NA_character_
. Ignored ifcontrols$data$date_column
isNA_character_
.logreturns
(*)
(FALSE
): A boolean, ifTRUE
the data is transformed to log-returns.merge
(function(x) mean(x)
): Only relevant ifhierarchy = TRUE
. In this case, a function, 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) (abs(x))
for the sum of 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
: A list of controls specifying the model fitting:runs
(100
): An integer, setting the number of optimization runs.origin
(FALSE
): A boolean, 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
): An integer (vector), specifying which optimization runs are accepted based on the output code ofnlm
.gradtol
(1e-6
): A positive numeric value, passed on tonlm
.iterlim
(200
): A positive integer, passed on tonlm
.print.level
(0
): One of0
,1
, and2
, passed on tonlm
.steptol
(1e-6
): A positive numeric value, passed on tonlm
.
Examples
### HMM controls
controls <- list(
states = 2,
sdds = "t(mu = 0, sigma = 1, df = 1)",
horizon = 400,
fit = list("runs" = 50)
)
set_controls(controls)
#> fHMM controls:
#> * hierarchy: FALSE
#> * data type: simulated
#> * number of states: 2
#> * sdds: t(mu = 0, sigma = 1, df = 1)
#> * number of runs: 50
### HHMM controls
controls <- list(
hierarchy = TRUE
)
set_controls(controls)
#> fHMM controls:
#> * hierarchy: TRUE
#> * data type: simulated
#> * number of states: 2 2
#> * sdds: t() t()
#> * number of runs: 100