1 #' Persistence Forecaster
3 #' Look for the most recent similar day in the past, and return its corresponding curve.
4 #' "Similar day" means "same day in the week".
6 #' @format R6 class, inherits Forecaster
7 #' @alias F_Persistence
9 PersistenceForecaster = R6::R6Class("PersistenceForecaster",
13 predictShape = function(data, today, memory, horizon, ...)
15 # Return centered last (similar) day curve, avoiding NAs until memory is run
16 first_day = max(1, today-memory)
17 same_day = ifelse(hasArg("same_day"), list(...)$same_day, TRUE)
18 # If 'same_day', get the last known future of similar day: -7 + 1 == -6
19 index = today - ifelse(same_day,6,0)
23 last_serie = data$getCenteredSerie(index)[1:horizon]
24 index = index - ifelse(same_day,7,1)
26 if (!any(is.na(last_serie)))
28 if (index < first_day)