| 1 | #' Obtain jump forecast by the Persistence method |
| 2 | #' |
| 3 | #' @inheritParams computeForecast |
| 4 | #' @inheritParams getZeroJumpPredict |
| 5 | #' |
| 6 | getPersistenceJumpPredict = function(data, today, memory, horizon, params, ...) |
| 7 | { |
| 8 | #return gap between end of similar day curve and first day of tomorrow (in the past) |
| 9 | first_day = max(1, today-memory) |
| 10 | same_day = ifelse(hasArg("same_day"), list(...)$same_day, TRUE) |
| 11 | realtime = ifelse(hasArg("realtime"), list(...)$realtime, FALSE) |
| 12 | index = today - ifelse(same_day,7,1) |
| 13 | repeat |
| 14 | { |
| 15 | { |
| 16 | last_serie_end = tail( data$getSerie(index), 1) |
| 17 | last_tomorrow_begin = data$getSerie(index+1,hat=(realtime && index+1==today))[1] |
| 18 | index = index - ifelse(same_day,7,1) |
| 19 | }; |
| 20 | if (!is.na(last_serie_end) && !is.na(last_tomorrow_begin)) |
| 21 | return (last_tomorrow_begin - last_serie_end); |
| 22 | if (index < first_day) |
| 23 | return (NA) |
| 24 | } |
| 25 | } |