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

feat: infer business-day frequency #36

Merged
merged 3 commits into from
Oct 18, 2024
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
14 changes: 13 additions & 1 deletion R/infer_frequency.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ infer_frequency <- function(df, freq){
}
dates_diff <- diff(dates)
dates_table <- table(dates_diff)
mode <- as.numeric(names(which.max(dates_table)))
sorted_dates <- sort(dates_table, decreasing = TRUE)
mode <- as.numeric(names(sorted_dates[1]))
if(length(sorted_dates) > 1){
mode2 <- as.numeric(names(sorted_dates[2])) # second most frequent value
}else{
mode2 <- NA
}

freq_list = list(
list(alias = "Y", value = c(365,366)),
Expand All @@ -52,6 +58,12 @@ infer_frequency <- function(df, freq){
}
}

if(!is.na(mode2) && freq == "D") { # check if daily is business-day
if(mode2 == 3) {
freq <- "B"
}
}

message(paste0("Frequency chosen: ", freq))
return(freq)

Expand Down
4 changes: 1 addition & 3 deletions vignettes/special-topics.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ The frequency parameter is crucial when working with time series data because it
| Second-level | s |
| Business day | B |

In this table, QS and MS stand for quarter and month start, while QE and ME stand for quarter and month end. Hourly and subhourly frequencies can be preceded by an integer, such as "6h", "10min" or "30s". **Only the aliases "min" and "S" are allowed for minute and second-level frequencies**.
In this table, QS and MS stand for quarter and month start, while QE and ME stand for quarter and month end. Hourly and subhourly frequencies can be preceded by an integer, such as "6h", "10min" or "30s". **Only the aliases "min" and "s" are allowed for minute and second-level frequencies**.

The default value of the frequency parameter is `NULL`. When this parameter is not specified, `nixtlar` will attempt to determine the frequency of your data.

Expand All @@ -90,8 +90,6 @@ fcst <- nixtlar::nixtla_client_forecast(df, h = 8, level = c(80,95)) # freq = "h
# infer the frequency when `freq` is not specified
```

**Currently, `nixtlar` can't infer business day frequency, so you must set it directly using `freq="B"`.**

```{r, include=FALSE}
options(original_options)
end_vignette()
Expand Down
Loading