# Why TimeSeries forecasts the future value poorly?

On a bank account there are many recurring entrance and expenses.

I've managed to import some sample data and to plot it.

I can see that there is a quite clear recurring trend (one wage is coming on 22 of the month and another on 27th of every month and many payments happen in the first days of the month).

What could help me in creating a forecast FutureMoney[today, futureDay, actualAmount]

ClearAll[f];
ClearAll[file1];
f = DateString[{#, {"Day", "/", "Month", "/", "Year"}}] &
file1 = Import["C:\\Users\\Utente\\Documents\\1.csv"];
data1 = file1[[2 ;;, {1, 2}]];
data = MapAt[f, data1, {All, 1}];
tsm = TimeSeriesModelFit[data];
DateListPlot[{tsm["TemporalData"], TimeSeriesForecast[tsm, {30}]}] Any help?

• Hi Revious, have you asked this before? Or do I have some deja vu? Oct 30, 2019 at 15:47
• the title has nothing to do with question and there is no failure reported. Nov 5, 2019 at 19:52
• @CarlLange: yes, but no one answered, so I deleted it.. Nov 7, 2019 at 23:26
• Naively using some kind of time forecasting method might not be the best approach. What about creating a histogram over money withdrawn or inserted into the account on day x? That could be a good start. If the 22nd och 27th is on a weekend that can change the pattern, so then in those cases move the money deposit to the next weekday instead. It's always good to start by implementing a simple baseline so that you know if the fancy methods you might try later add any real benefit. Otherwise you'll end up using neural networks for problems that can be solved with linear interpolation. Nov 8, 2019 at 8:40
• You need to devise a way to test your predictions as well. Typically, you would train on the first 3/4 of the data, say, and then predict the last 1/4. Then you would compare your prediction with your last 1/4 of real data (the so-called ground truth.) You would use some kind of distance measurement, such as the point-wise euclidean distance, and track that measurement over all of your different attempts. Nov 8, 2019 at 8:42

To get output that looks a bit more reasonable, modify the second parameter to TimeSeriesModelFit.

ds = SemanticImport["https://textbin.net/raw/ikfqPWq6Iy"]

ts = TimeSeriesResample@TimeSeries[Values@Normal@ds]


Now, we can get output that has the repetition you were expecting with, for instance, an "ARMA" (auto-regressive moving-average) model:

tsm = TimeSeriesModelFit[ts, {"ARMA", {100, 5}}];
DateListPlot[{tsm["TemporalData"], TimeSeriesForecast[tsm, {160}]}] Modifying the parameters of the model (above, I picked 100 and 5 for the autoregressive order and moving average order respectively) will give different output. For instance, here's {20,30}: There's a large list of models and their parameters in the documentation for TimeSeriesModelFit.

I'm not qualified to give you a good explanation of these different models or their parameters, but I hope this is a good start for you!

• Thank you very much. May I ask you what the "@" syntax means? I'm trying to understand this part: TimeSeriesResample@TimeSeries[Values@Normal@ds] Nov 8, 2019 at 13:39
• Ah, it's the prefix operator, which is equivalent to: TimeSeriesResample[TimeSeries[Values[Normal[ds]]]] - so f@x === f[x]. Nov 8, 2019 at 14:27

forecast = TimeSeriesForecast[tsm, {30}] returns a TimeSeries object, so you can see what the value is on a given date by forecast[date_DateObject] or print all the values forecast["Values"].

• it seems a very weird forecast, the timeseries is cyclic on a 30 days period and this is the forecast i.imgur.com/MMVsqPl.png Nov 7, 2019 at 23:31