2

I have the amount of earnings over a period of time (per day one value of how much a company earned for specific projects).

The normal behaviors is that the earnings from day to day are approximately around the same value, let say 20K (small deviations are ok). I want to build an alarm system that will fire once the trend of the earnings decreases. There might be two consecutive days outliers when the earnings fall to around 15K but I am not interested in that. I am interested if there is a real decreasing or increasing trend over 4-6 days.

What would be the best approach to do it?

Example data of a decreasing trend:

12.02 900
13.02 870
14.02 880
15.02 890
16.02 810
17.02 800
18.02 790
19.02 740
20.02 700
21.02 650
22.02 600
Anni
  • 123
  • Have you considered a moving average? – Fabio Somenzi Mar 04 '17 at 16:54
  • Yes, i did. But in the end I will get the moving average but how ahould I compare them? Take the global average of all moving averages and fire the alarm if a moving average of some block is twice less than the global aveage, for instance? – Anni Mar 04 '17 at 17:34
  • The moving average "filters out the high-frequency noise," so to speak. What you do with the average is a separate question that admits more than one answer. You could compare the moving average to the global average, or to a reference value, or combine these two criteria in various ways. If you have enough data, either real or synthetic, you may run several versions of your test and see which are most effective at detecting real problems and avoiding false alarms. – Fabio Somenzi Mar 04 '17 at 17:48

1 Answers1

0

I would do a simple least squares fit to the data in the last $n$ days (4-6 or whatever interval), and calculate the change from the slope. If the changes is greater than say twice the normal deviations, you have an increasing behavior. If the change is smaller than minus twice the small deviations for each day, you have a decreasing behavior. You can put your limit at three times, or whatever.

Take a look at https://en.wikipedia.org/wiki/Linear_trend_estimation

Andrei
  • 37,370
  • What do you mean under "calculate the change from the slope"? I mean after fitting LS to the last 4 days I will get a kind of straight line with intercept, slopes and can calculate the residuals. How can I calculate the change from the slope? Or you mean I chould find the difference of the slopes from LS of the last 4 days and from LS of the previous days? – Anni Mar 04 '17 at 19:05
  • Say your variable is $y$ and the time is $t$, the equation of the line is $y(t)=at+b$, then $y(t)-y(t-n)=an$. If $an$ is greater than some threshold that you choose in terms of standard deviations, you say that $y$ is increasing – Andrei Mar 04 '17 at 19:54
  • What do I do with single outliers? y=c(600,610,590,600,580,620,1000,580,581) Due to them it will seem as if there is an increasing trend. – Anni Mar 05 '17 at 10:07
  • You need to decide what is an outlier, in terms of the standard deviations, and how to deal with them. For example, you can say that outliers are everything further that 100 from the median. Then just eliminate them when you do your calculation – Andrei Mar 05 '17 at 15:40