# TimeSeriesForecast Forecasts

I am trying to make sure I understand how TimeSeriesForecast works. I apologize in advance for the basic nature of this question. I am using Mathematica 10.

I create a TimeSeries in a stock like GE, containing O/H/L/C prices and from there estimate a vector autoregression (ARMA) model using some in-sample data. I now want to produce 1-step ahead forecasts, period by period, for the out of sample data. The code I have listed below does this and produces the results as shown.

I want to make 100% sure that the forecast produced for period n are the forecast OHLC prices for period n, and not the forecast prices produced at period n for period n+1. So below, is the first set of forecast prices the forecast for period 8325, or the forecasts produced in period 8325 for period 8326?

Whats confusing me is the with ISend = 8325, I get:

GE["Path"][[ISend + 1]]
(* {8325, {20.4819, 20.5104, 20.1867, 20.32}} *)


i.e it seems that the TimeSeries variable GE somehow "lags" by 1 period.

Forecasting code

ISend
(* 8325 *)

n = 1;

forecasts =
Flatten[Table[
TimeSeriesForecast[eproc,
TimeSeriesWindow[GE, {ISend - 3 + i, ISend - 2 + i}], {n},
Method -> "Covariance"]["Path"], {i, 1, 386}], 1];

Take[forecasts, 5]

(* {{8325, {19.8498, 19.8257, 19.3094,
19.6899}}, {8326, {20.711, 20.7849, 20.3424,
21.2416}}, {8327, {20.142, 20.4853, 20.1133,
20.2042}}, {8328, {20.1565, 20.2824, 20.009,
20.0737}}, {8329, {20.0761, 20.1621, 19.96, 20.0177}}} *)

• I too am interested in the new time series functionality in version 10. Can you provide a data set so we can work with the same data ? – Steve Jul 19 '14 at 20:45

Since there are no data accompanying the question there can be no definitive answer; I can speculate though that what seems to be a shifted index in GE["Path"][[ISend + 1]] has to do with how the TimeSeries was constructed in the first place.

Consider the output after evaluating the following example:

ts = TimeSeries[{0.5, 0.75, 0.9}];

ts["Path"]

{{0, 0.5}, {1, 0.75}, {2, 0.9}}


Since no time specification is present in the construction of ts, the time stamps seem to automatically be set to be equal to what Range[0, Length[ts["Values"]]-1] evaluates to ie {0, 1, 2}.

The confusion is probably due to the fact that entries from #["Times"] in a TimeSeries object are not like indexes in Part. The former can be zero-based while the later cannot. Using offsets for time signatures is different than using offsets for Part.

In the present case, the rolling-window estimation can be performed with MovingMap:

(* expand the previous example a bit *)
ts = TimeSeries[{0.5, 0.75, 0.9, 0.15, 0.135, 0.155, 0.175, 0.195, 0.215,  0.465, 0.71}];

(* here, f is applied on each successively obtained sub-sample *)
MovingMap[f, ts, Quantity[5, "Events"]]["Path"]

{
{4, f[{0.5, 0.75, 0.9, 0.15, 0.135}]},
{5, f[{0.75, 0.9, 0.15, 0.135, 0.155}]},
{6, f[{0.9, 0.15, 0.135, 0.155, 0.175}]},
{7, f[{0.15, 0.135, 0.155, 0.175, 0.195}]},
{8, f[{0.135, 0.155, 0.175, 0.195, 0.215}]},
{9, f[{0.155, 0.175, 0.195, 0.215, 0.465}]},
{10, f[{0.175, 0.195, 0.215, 0.465, 0.71}]}
}


Assuming a window 5 "Events" wide, MovingMap can produce estimates for each time based on the history specified by the window (current time inclusive). Different specifications can be also accommodated (see documentation).

PS. I can't really tell about v.10 but in v.11.3, multi-valued time series (eg ts = TimeSeries[{{0.97, 0.5}, {1.22, 0.75}, {0.935, 0.465}, {1.18, 0.71}}, Automatic, ValueDimension s -> 2]) are not supported in something like TimeSeriesForecast[TimeSeriesModelFit[ts], {1}] (it produces a TimeSeriesModelFit::mvtsni message with text "The data TimeSeries[] is not scalar-valued. Multivariate support is not currently implemented.")