X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=pkg%2FR%2FJ_Persistence.R;h=9e56742680a3db4702cb535a98f5aabdadbcfded;hb=3ddf1c12af0c167fe7d3bb59e63258550270cfc5;hp=4d3abd2b100f595e1d329733614acc534cb25aca;hpb=72b9c50162bcdcf6c99fbb8b2ec6ea9ba98379cb;p=talweg.git diff --git a/pkg/R/J_Persistence.R b/pkg/R/J_Persistence.R index 4d3abd2..9e56742 100644 --- a/pkg/R/J_Persistence.R +++ b/pkg/R/J_Persistence.R @@ -1,20 +1,26 @@ -#' Obtain jump forecast by the Persistence method +#' getPersistenceJumpPredict +#' +#' Analog of the PersistenceForecaster: predict the jump after last observed value either +#' by re-applying the last jump between similar day and its follower (if argument +#' "same_day" is TRUE), or by re-using the very last observed jump (when "same_day" = +#' FALSE). #' #' @inheritParams computeForecast #' @inheritParams getZeroJumpPredict #' +#' @aliases J_Persistence +#' getPersistenceJumpPredict = function(data, today, memory, horizon, params, ...) { #return gap between end of similar day curve and first day of tomorrow (in the past) first_day = max(1, today-memory) same_day = ifelse(hasArg("same_day"), list(...)$same_day, TRUE) - realtime = ifelse(hasArg("realtime"), list(...)$realtime, FALSE) index = today - ifelse(same_day,7,1) repeat { { last_serie_end = tail( data$getSerie(index), 1) - last_tomorrow_begin = data$getSerie(index+1,hat=(realtime && index+1==today))[1] + last_tomorrow_begin = head( data$getSerie(index+1), 1) index = index - ifelse(same_day,7,1) }; if (!is.na(last_serie_end) && !is.na(last_tomorrow_begin))