# Time Series Forecast: Convert differenced forecast back to before difference level

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?

• There's something unclear about your circumstances; you may be aware of important details that we aren't. Why is $y_{t+7}$ needed? – Glen_b Dec 4 '14 at 14:58
• @Glen_b Because using rolling window with horizon $h=7$ we get new information step by step, at time $t+7$, we already know $y_{t+7}$, so I believe it makes more sense to calculate $\hat{y}_{t+8}$ as $y_{t+7}+\hat{z}_{t+8}$ rather than $y_{t+1}+\hat{z}_{t+1}+...+\hat{z}_{t+8}$. – svmflower Dec 4 '14 at 15:15
• @Glen_b Thank you for clearing things up, I think I know how to proceed now. – svmflower Dec 4 '14 at 15:41
• I moved the comment to my answer. – Glen_b Dec 4 '14 at 15:48

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).