loelschlaeger / fHMM

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

Error when running examples #92

Closed MHJS1958 closed 1 month ago

MHJS1958 commented 1 month ago

When running this example from your introduction:

library("fHMM")
dax <- download_data(symbol = "^GDAXI")
controls <- set_controls(
  states      = 3,
  sdds        = "t",
  file        = dax,
  date_column = "Date",
  data_column = "Close",
  logreturns  = TRUE,
  from        = "2000-01-01",
  to          = "2022-12-31"
)
data <- prepare_data(controls)
summary(data)
model <- fit_model(data)

The execution stops with this error-message:

"'test_numeric_vector' is not an exported object from 'namespace:oeli'" 

I cannot find a hint to solve this error, so can you please help ?

loelschlaeger commented 1 month ago

Please verify that you have the latest version of ⁣{fHMM} (which is 1.3.1) and {oeli} (which is 0.5.2) installed and try it again.

MHJS1958 commented 1 month ago

Thank you very much! I already have fHMM version 1.3.1, but upgrading oeli helped. However, I do not get the same results as you do on the same dataset as yours. The estimates are different and “Some confidence bounds could not be computed.” (15 missing), and then of course the figures look different!

Best regards

Michael.

loelschlaeger commented 1 month ago

It seems like the optimization did not converge properly. Please adapt your code as follows and try again:

library("fHMM")
dax <- download_data(symbol = "^GDAXI")
controls <- set_controls(
  states      = 3,
  sdds        = "t",
  file        = dax,
  date_column = "Date",
  data_column = "Close",
  logreturns  = TRUE,
  from        = "2000-01-01",
  to          = "2022-12-31",
  runs        = 100,            # increases the number of numerical optimization runs
  iterlim     = 300,            # increases the iteration limit for the optimizer
  gradtol     = 1e-6,           # decreases the gradient tolerance for the optimizer
  steptol     = 1e-6            # decreases the tolerated step length for the optimizer
)
data <- prepare_data(controls)
summary(data)

library("doSNOW")
library("parallel")
detectCores()

model <- fit_model(data, seed = 1, ncluster = 10)  # using parallel optimization to save computation time