The package fHMM can model empirical and simulated data.
You have to options to provide fHMM with empirical data:
You can save your data in a csv-file in a folder named data under the path path, where path needs to correspond to path specified in controls.
You can download daily prices of your preferred stock from https://finance.yahoo.com/ via
download_data(name, symbol, from, to, path)where
name is your personal identifier for the stock,
symbol is the stock’s symbol that has to match the official symbol on https://finance.yahoo.com,
from and to define the time interval (in format "YYYY-MM-DD"),
path is the path where the data gets saved and needs to correspond to path specified in controls.
For example, the call
download_data(name = "dax", symbol = "^GDAXI", from = "2000-01-01", to = Sys.Date(), path = ".")downloads the 21st century daily data of the Deutscher Aktienindex into the folder data in the current working directory (because path = ".").
Historical events can be highlighted in the visualization of the decoded, empirical time series by passing a named list events with elements dates (a vector of dates) and names (a vector of names for the events) to fit_hmm.
For example, passing
events = list(
dates = c("2001-09-11","2008-09-15","2020-01-27"),
names = c("9/11 terrorist attack","Bankruptcy of Lehman Brothers","First COVID-19 case in Germany")
)to fit_hmm highlights three important historical events in the decoded time series.
If you do not have empirical data at hand or simply want to conduct a simulation experiment, fHMM can simulate data from a hidden Markov model for you. If you do not specify the data parameter in the model’s controls, data gets simulated for you.
You can specify the model coefficients by passing the list sim_par in thetaList format (see the vignette model parameters) to fit_hmm. Otherwise, the parameters are randomly drawn from -1 to 1. Setting scale_par(x,y) in controls scales these values by x and y on the coarse scale and on the fine scale, respectively.