X-Git-Url: https://git.auder.net/img/rock_paper_scissors_lizard_spock.gif?a=blobdiff_plain;ds=sidebyside;f=pkg%2FR%2FJ_Persistence.R;fp=pkg%2FR%2FJ_Persistence.R;h=7a7daef1c4c242e7354a4300574d74892cb2e4bd;hb=ff5df8e310b73883565761ab4b1aa5a0672e9f27;hp=0000000000000000000000000000000000000000;hpb=63ff1ecbd80adfe347faa0d954f526d15f033c22;p=talweg.git diff --git a/pkg/R/J_Persistence.R b/pkg/R/J_Persistence.R new file mode 100644 index 0000000..7a7daef --- /dev/null +++ b/pkg/R/J_Persistence.R @@ -0,0 +1,23 @@ +#' Obtain jump forecast by the Persistence method +#' +#' @inheritParams computeForecast +#' @inheritParams getZeroJumpPredict +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) + index = today - ifelse(same_day,7,1) + repeat + { + { + last_serie_end = tail( data$getSerie(index), 1) + last_tomorrow_begin = data$getSerie(index+1)[1] + index = index - ifelse(same_day,7,1) + }; + if (!is.na(last_serie_end) && !is.na(last_tomorrow_begin)) + return (last_tomorrow_begin - last_serie_end); + if (index < first_day) + return (NA) + } +}