loelschlaeger / fHMM

Hidden Markov models for finance
https://loelschlaeger.de/fHMM/
GNU General Public License v3.0
16 stars 8 forks source link

Error in check_controls(controls): File './data/x.csv' not found. #51

Closed filippocuscito29 closed 3 years ago

filippocuscito29 commented 3 years ago

Hi,

I am trying to fit an hhmm on copper data, however, after

fit_hmm(controls, events)

the following error pops up:

Error in check_controls(controls): File './data/x.csv' not found.

Thank you in advance for the support.

loelschlaeger commented 3 years ago

How did you specify your controls? Please provide a minimal reproducible example.

filippocuscito29 commented 3 years ago

Here is the code:

download_data(name = "Copper", symbol = "HG=F", path = ".")

controls = list(path = ".", id = "HHMM_3_2_COPPER_t", model = "hhmm", states = c(3,2), sdds = c("t", "t"), horizon = c(30, "w"), data = list("source" = c("coarse", "fine"), "column" = c("Close", "Close"), "cs_transform" = function(x) (tail(x,1)-head(x,1))/head(x,1), "log_returns" = c(FALSE, TRUE), "truncate" = c("2000-01-01", NA)), fit = list("runs" = 100))

events = list(dates = c("2008-07-01"), names = ("73 days to Lehman crash"))

fit_hmm(controls, events)

Looking forward to hearing from you. I really do not understand what I am getting wrong.

loelschlaeger commented 3 years ago

You misspecified controls$data$source. You need the name of the .csv file with your data there. The following worked for me:

install.packages("fHMM")
library("fHMM")
download_data(name = "Copper", symbol = "HG=F", path = ".")
controls = list(path = ".", 
                id = "HHMM_3_2_COPPER_t", 
                model = "hhmm", states = c(3,2), 
                sdds = c("t", "t"), 
                horizon = c(30, "w"), 
                data = list("source" = c("copper.csv", "copper.csv"), 
                            "column" = c("Close", "Close"), 
                            "cs_transform" = function(x) (tail(x,1)-head(x,1))/head(x,1), 
                            "log_returns" = c(FALSE, TRUE), 
                            "truncate" = c("2000-01-01", NA)), 
                fit = list("runs" = 100))
events = list(dates = c("2008-07-01"), names = ("73 days to Lehman crash"))
fit_hmm(controls, events)