7
$\begingroup$

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}]}]

enter image description here

Any help?

$\endgroup$
  • 3
    $\begingroup$ Hi Revious, have you asked this before? Or do I have some deja vu? $\endgroup$ – Carl Lange Oct 30 '19 at 15:47
  • $\begingroup$ the title has nothing to do with question and there is no failure reported. $\endgroup$ – Gosia Nov 5 '19 at 19:52
  • $\begingroup$ @CarlLange: yes, but no one answered, so I deleted it.. $\endgroup$ – Revious Nov 7 '19 at 23:26
  • 2
    $\begingroup$ 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. $\endgroup$ – C. E. Nov 8 '19 at 8:40
  • 3
    $\begingroup$ 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. $\endgroup$ – C. E. Nov 8 '19 at 8:42
8
$\begingroup$

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

Load the data:

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}]}]

enter image description here

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}:

enter image description here

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!

$\endgroup$
  • $\begingroup$ Thank you very much. May I ask you what the "@" syntax means? I'm trying to understand this part: TimeSeriesResample@TimeSeries[Values@Normal@ds] $\endgroup$ – Revious Nov 8 '19 at 13:39
  • 2
    $\begingroup$ Ah, it's the prefix operator, which is equivalent to: TimeSeriesResample[TimeSeries[Values[Normal[ds]]]] - so f@x === f[x]. $\endgroup$ – Carl Lange Nov 8 '19 at 14:27
  • $\begingroup$ Thanks again!!! $\endgroup$ – Revious Nov 8 '19 at 14:51
-2
$\begingroup$

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"].

$\endgroup$
  • 1
    $\begingroup$ 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 $\endgroup$ – Revious Nov 7 '19 at 23:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.