save current state
[talweg.git] / pkg / R / J_Persistence.R
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 index = today - ifelse(same_day,7,1)
12 repeat
13 {
14 {
15 last_serie_end = tail( data$getSerie(index), 1)
16 last_tomorrow_begin = head( data$getSerie(index+1), 1)
17 index = index - ifelse(same_day,7,1)
18 };
19 if (!is.na(last_serie_end) && !is.na(last_tomorrow_begin))
20 return (last_tomorrow_begin - last_serie_end);
21 if (index < first_day)
22 return (NA)
23 }
24 }