Time-Series Forecasting – How to Convert Differenced Forecast Back to Original Level: Detailed Guide

forecastingmachine learningrtime series

I am using R and I need an easier way to produce forecasts of data at the original level based on forecasts using differenced data.

The situation, in more detail, is this: I am using several different models (including SVM and a few others) to forecast a time series. My models are based on differenced data since the original data is not stationary. Now I have a vector of predicted values for each model, but all the forecasts are for the differenced data. How can I get forecasts of the original data before it's differenced?

In other words, if I have forecasts of returns, how do I automatically get the forecasts of stock prices of the same period in R? I know the hard-coded way to do it, but I am looking for an easier way. In testing situations like rolling windows with different forecast horizons, things could be trickier I believe. To be more specific, if the window is rolling with horizon 7 (days), then $\hat{y}_{t+1}$ until $\hat{y}_{t+7}$ is easy to calculate by Glen's answer below. However, after we roll the window once we will be standing at time $t+7$, where we have both $y_{t+7}$ and $\hat{y}_{t+7}$. I want to calculate $\hat{y}_{t+8}$ as $y_{t+7}+\hat{z}_{t+8}$ and $\hat{y}_{t+9}$ as $y_{t+7}+\hat{z}_{t+8}+\hat{z}_{t+9}$, and so on. So, for $\hat{y}_{t+8}$ to $\hat{y}_{t+14}$ the value $y_{t+7}$ needs to be used and this could go on until the end of the dataset. Is there any R function I can use to make this calculation conveniently?

Best Answer

The usual approach to the point forecasts is to cumulatively add the difference-forecasts to the last cumulative observation. If $z$ are the differenced data and $y$ the original, then:

$\hat{y}_{t+1}=y_t+\hat{z}_{t+1}$

$\hat{y}_{t+2}=\hat{y}_{t+1}+\hat{z}_{t+2}=y_t+\hat{z}_{t+1}+\hat{z}_{t+2}$

and so on. The cumulative sums of the $\hat{z}$ values are easy, and adding $y_t$ is also easy. Details of what to do in R would depend on the specific model (e.g. if you fitted an ARMA to the differences, just specify the corresponding ARIMA to the original and predict that).

On your second question, you have more data, so you have to calculate new parameter estimates anyway. Since you have new parameter estimates you'd just recalculate forecasts the same way as before, but with those 7 additional observations. In some circumstances the parameter updates can be computed in terms of the old estimates and the data (e.g. state-space models), but for many models you just recompute everything like you did with the previous forecasts.