Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
^renv$
^renv\.lock$
..Rcheck
^.*\.Rproj$
^\.Rproj\.user$
Expand All @@ -14,9 +12,7 @@ LICENSE
docs/
vignettes/figs/
^vignettes/.*cache
^CRAN-RELEASE$
^cran-comments\.md$
^CRAN-SUBMISSION$
^sticker$
^development_packages\.R$
^fit_models\.R$
^doc$
10 changes: 5 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: fHMM
Type: Package
Title: Fitting Hidden Markov Models to Financial Data
Version: 1.4.2
Version: 1.4.3
Authors@R: c(
person(given = "Lennart",
family = "Oelschl\U00E4ger",
Expand All @@ -11,12 +11,12 @@ Authors@R: c(
person(given = "Timo",
family = "Adam",
role = "aut",
email = "ta59@st-andrews.ac.uk",
email = "timo.adam@uni-bielefeld.de",
comment = c(ORCID = "0000-0001-9079-3259")),
person(given = "Rouven",
family = "Michels",
role = "aut",
email = "r.michels@uni-bielefeld.de",
email = "rouven.michels@tu-dortmund.de",
comment = c(ORCID = "0000-0002-5433-6197")))
Description: Fitting (hierarchical) hidden Markov models to financial data
via maximum likelihood estimation. See Oelschläger, L. and Adam, T.
Expand All @@ -43,7 +43,7 @@ Imports:
httr,
jsonlite,
MASS,
oeli (>= 0.3.0),
oeli (>= 0.7.6),
padr,
pracma,
progress,
Expand All @@ -63,7 +63,7 @@ Suggests:
testthat (>= 3.0.0),
tseries
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
RoxygenNote: 7.3.3
VignetteBuilder: knitr
Config/testthat/edition: 3
LazyData: true
Expand Down
10 changes: 9 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# fHMM 1.4.3

* Improved documentation of input types and input checks.

* Small documentation fixes.

* Removed renv.

# fHMM 1.4.2

* Let `download_data()` fail gracefully with an informative message if the Yahoo Finance resource is not available or has changed.
Expand All @@ -10,7 +18,7 @@

* Removed stale import of `oeli::check_date()`.

* Updated `download_data()` to confirm with new Yahoo Finance API.
* Updated `download_data()` to work with the new Yahoo Finance API.

# fHMM 1.4.0

Expand Down
14 changes: 8 additions & 6 deletions R/compare_models.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ compare_models <- function(...) {

### check if models are of class "fHMM_model"
for (i in seq_len(length(models))) {
if (!inherits(models[[i]],"fHMM_model")) {
stop(
paste0("Input '", model_names[i], "' is not of class 'fHMM_model'."),
call. = FALSE
)
}
oeli::input_check_response(
check = if (inherits(models[[i]], "fHMM_model")) {
TRUE
} else {
paste0("Input '", model_names[i], "' is not of class 'fHMM_model'.")
},
var_name = model_names[i]
)
}

### check if data is the same for each model
Expand Down
8 changes: 4 additions & 4 deletions R/compute_T_star.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
#' This helper function computes lengths of fine-scale chunks in the
#' hierarchical case.
#'
#' @param horizon
#' @param horizon \[`integer(2)`\]\cr
#' The element \code{controls$horizon}, i.e., an integer vector of length 2,
#' where the second entry can be \code{NA_integer_}.
#' @param period
#' @param period \[`character(1)`\]\cr
#' The element \code{controls$period}, i.e. one of \code{"w"},
#' \code{"m"}, \code{"q"}, or \code{"y"}.
#' @param dates
#' @param dates \[`NULL` | `character()`\]\cr
#' A \code{character} vector of dates of empirical fine-scale data (if any).
#' By default, \code{dates = NULL}.
#' @param seed
#' @param seed \[`NULL` | `integer(1)`\]\cr
#' Set a seed for the simulation of flexible chunk lengths.
#' By default, \code{seed = NULL} (i.e., no seed).
#'
Expand Down
36 changes: 25 additions & 11 deletions R/compute_ci.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
#' This helper function computes confidence intervals for the estimates of an
#' \code{\link{fHMM_model}} object using the inverse Fisher information.
#'
#' @param x
#' @param x \[`fHMM_model`\]\cr
#' An object of class \code{\link{fHMM_model}}.
#'
#' @param alpha
#' A \code{numeric} between 0 and 1, the alpha level for the confidence interval.
#' By default, \code{alpha = 0.05}, which computes a 95% confidence interval.
#' @param alpha \[`numeric(1)`\]\cr
#' The alpha level for the confidence interval. Must be between 0 and 1.
#' By default, \code{alpha = 0.05}, which computes a 95 percent confidence
#' interval.
#'
#' @return
#' A \code{list} containing the following elements:
Expand All @@ -24,12 +25,25 @@
compute_ci <- function(x, alpha = 0.05) {

### check inputs
if (!inherits(x,"fHMM_model")) {
stop("Input 'x' must be an 'fHMM_model' object.", call. = FALSE)
}
if (!is.numeric(alpha) || length(alpha) != 1 || alpha <= 0 || alpha >= 1) {
stop("Input 'alpha' must be a numeric between 0 and 1.", call. = FALSE)
}
oeli::input_check_response(
check = if (inherits(x, "fHMM_model")) {
TRUE
} else {
"Input 'x' must be an 'fHMM_model' object."
},
var_name = "x"
)
oeli::input_check_response(
check = if (
checkmate::test_number(alpha, lower = 0, upper = 1) &&
alpha > 0 && alpha < 1
) {
TRUE
} else {
"Input 'alpha' must be a numeric between 0 and 1."
},
var_name = "alpha"
)

### compute confidence intervals using the inverse Hessian approach
inverse_fisher <- x$inverse_fisher
Expand All @@ -41,7 +55,7 @@ compute_ci <- function(x, alpha = 0.05) {
### if negative variance, replace by NA_real_
bad_inverse_fisher <- which(
!vapply(
inverse_fisher, checkmate::test_number, logical(1), na.ok = FALSE,
inverse_fisher, checkmate::test_number, logical(1), na.ok = FALSE,
finite = TRUE, lower = 0
)
)
Expand Down
28 changes: 19 additions & 9 deletions R/compute_residuals.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#' This function computes (pseudo-) residuals of an \code{\link{fHMM_model}}
#' object.
#'
#' @param x
#' @param x \[`fHMM_model`\]\cr
#' An object of class \code{\link{fHMM_model}}.
#' @param verbose
#' @param verbose \[`logical(1)`\]\cr
#' Set to \code{TRUE} (default) to print progress messages.
#'
#' @return
Expand All @@ -20,13 +20,23 @@

compute_residuals <- function(x, verbose = TRUE) {

### check input
if (!inherits(x,"fHMM_model")) {
stop("'x' must be of class 'fHMM_model'.", call. = FALSE)
}
if (!isTRUE(verbose) && !isFALSE(verbose)) {
stop("'verbose' must be either TRUE or FALSE.", call. = FALSE)
}
### check inputs
oeli::input_check_response(
check = if (inherits(x, "fHMM_model")) {
TRUE
} else {
"'x' must be of class 'fHMM_model'."
},
var_name = "x"
)
oeli::input_check_response(
check = if (checkmate::test_flag(verbose)) {
TRUE
} else {
"'verbose' must be either TRUE or FALSE."
},
var_name = "verbose"
)
if (is.null(x$decoding)) {
warning(
paste(
Expand Down
8 changes: 4 additions & 4 deletions R/data_and_models.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
#' @description
#' A pre-computed HMM on closing prices of the DAX from 2000 to 2022
#' with two hidden states and normal state-dependent distributions for
#' demonstration purpose.
#' demonstration purposes.
#'
#' @usage data("dax_model_2n")
#'
Expand Down Expand Up @@ -150,7 +150,7 @@
#' @description
#' A pre-computed HMM on closing prices of the DAX from 2000 to 2022
#' with three hidden states and state-dependent t-distributions for
#' demonstration purpose.
#' demonstration purposes.
#'
#' @usage data("dax_model_3t")
#'
Expand Down Expand Up @@ -193,7 +193,7 @@
#' A pre-computed HHMM with monthly averaged closing prices of the
#' DAX from 2010 to 2022 on the coarse scale, Volkswagen AG stock data on the
#' fine scale, two hidden fine-scale and coarse-scale states, respectively, and
#' state-dependent t-distributions for demonstration purpose.
#' state-dependent t-distributions for demonstration purposes.
#'
#' @usage data("dax_vw_model")
#'
Expand Down Expand Up @@ -235,7 +235,7 @@
#' @description
#' A pre-computed HHMM with monthly unemployment rate in the US on the coarse
#' scale using 3 states and S&P 500 index data on the fine scale using 2 states
#' from 1970 to 2020 for demonstration purpose.
#' from 1970 to 2020 for demonstration purposes.
#'
#' @usage data("unemp_spx_model_3_2")
#'
Expand Down
Loading
Loading