Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

period="m" not work properly when fitting HHMM model #93

Closed
dongsen86 opened this issue Aug 1, 2024 · 2 comments · Fixed by #94
Closed

period="m" not work properly when fitting HHMM model #93

dongsen86 opened this issue Aug 1, 2024 · 2 comments · Fixed by #94
Assignees
Labels
bug something isn't working

Comments

@dongsen86
Copy link

In your package example 3 (your code below), i.e. unemp_spx_model_3_2, period="m" is masked by default horizon value c(NA,30) ,so the fine scale dimension is 30 not "m", T-star is a list (30,30,30.........), not as expected like (19,20,22,23,......). If I set horizon=c(NA,NA), period="m"(or "w" "q" "y") works well, T-star is computed as expected, prepare_data() also works well, but error "Error in do_one(nmeth) : NA/NaN/Inf in foreign function call (arg 1)" is reported due to NA value existed in fhmm model data.

This issue also occurs when I try to replicate your paper " Detecting bearish and bullish markets in financial time series using hierarchical hidden Markov models"(Statistical Modelling 2023; 23(2): 107–126). In section "3.2 DeutscheBank", 5250 daily DAX data should be merged by month to 256 coarse scale observations (as presented in section "3.3 Simulation study"), but since period="m" not work, the coarse scale observation is reduce to 175(5250/30), or "Error in do_one(nmeth) : NA/NaN/Inf in foreign function call (arg 1)" is reported when period="m" works (horizon=c(NA,NA)), so the result can not be replicated (when the fine scale dimension is 30 (even 22) not "m", the result is significantly different from the result in the paper).

Thank you very much if you can solve this issue.

Example 3: Multiple data streams ----------------------------------------

define and set controls

contr_hhmm <- list(
hierarchy = TRUE, states = c(3, 2),
sdds = c("t", "t"),
period = "m", #not work when horizon is default
data = list(
file = list(unemp, spx),
data_column = c("rate_diff", "Close"),
date_column = c("date", "Date"),
from = "1970-01-01", to = "2020-01-01",
logreturns = c(FALSE, TRUE)),
fit = list(runs = 50, iterlim = 1000, gradtol = 1e-6, steptol = 1e-6))
contr_hhmm <- set_controls(contr_hhmm)

prepare data

data_hhmm <- prepare_data(contr_hhmm)

fit the model

unemp_spx_model_3_2 <- fit_model(data_hhmm, seed = 1, ncluster = 25) ####report error "Error in do_one(nmeth) : NA/NaN/Inf in foreign function call (arg 1)" when horzion=(NA,NA) and period="m" works

@dongsen86 dongsen86 added the bug something isn't working label Aug 1, 2024
@loelschlaeger loelschlaeger self-assigned this Aug 1, 2024
@loelschlaeger
Copy link
Owner

Thanks for making us aware of this issue, I will check it ASAP and come back to you then.

@loelschlaeger loelschlaeger linked a pull request Aug 5, 2024 that will close this issue
loelschlaeger referenced this issue Aug 5, 2024
* Fixed a bug around the `period` control.

* Fixed date conversion to `character()`.

* refitted models
@loelschlaeger
Copy link
Owner

Fixed the issue, available soon as version 1.4.0 on CRAN. Thanks again, @dongsen86 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants