new version, persistence -7 days
[talweg.git] / R / J_Persistence.R
diff --git a/R/J_Persistence.R b/R/J_Persistence.R
new file mode 100644 (file)
index 0000000..744b42a
--- /dev/null
@@ -0,0 +1,22 @@
+#' Obtain jump forecast by the Persistence method
+#'
+#' @inheritParams getForecast
+#' @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)
+       index = today-7
+       repeat
+       {
+               {
+                       last_similar_serie_end = tail( data$getCenteredSerie(index), 1)
+                       last_similar_tomorrow_begin = data$getCenteredSerie(index+1)[1]
+                       index = index - 7
+               };
+               if (!is.na(last_similar_serie_end) && !is.na(last_similar_tomorrow_begin))
+                       return (last_similar_tomorrow_begin - last_similar_serie_end);
+               if (index < first_day)
+                       return (NA)
+       }
+}