How to find tops and bottoms in time series?

后端 未结 3 1770
醉酒成梦
醉酒成梦 2021-02-03 15:04

At first, this question can sound really stupid, but it is not in fundamental. Maybe, it can seem like unresolvable exactly by any algorithm, but I pretend to say it is.

相关标签:
3条回答
  • 2021-02-03 15:33

    You'll usually start with a moving average -- that is, averaging the N most recent points, where the degree of smoothing is roughly proportional to N (i.e., as yoy average more points, your result gets smoother).

    Then you can take the differences between each averaged point and the next. Where the difference changes sign, you have a minimum or maximum (where it goes from positive to negative, you have a maximum, from negative to positive, a minimum).

    0 讨论(0)
  • 2021-02-03 15:35

    I might not fully understand but why can't you just take the lowest point for a specific time range? Most data providers do provide high/low of the day, can you not just store it and then simply get the lowest value for time range x?

    By extending the range of your study you remove the small ups/downs. This is what I typically do. Another way is, you can use averages of the last X days to smooth out the results(moving averages) but then you'll lose accuracy(degree is dependent on range..if its a 2-3 days moving average than its not as bad a 2 year moving average).

    EDIT: sorry, I miss understood, you are trying to find the range. Well if you have the data then why not find the lowest point(s) first and then go to the next day and figure out the % change, then the next, etc..and overwrite the day when you find a higher range. You'll need to add some more logic later(such as %down from that peak or something) otherwise you'll report will typically take the stock's ipo and take its all that high and say thats a single period.

    0 讨论(0)
  • 2021-02-03 15:49
    1. You could perform a smoothing or lowpass filtering operation first, and find the locations of the local minima/maxima from the smoothed data. Then get the values of the minima and the maxima from the original data.

    2. You could use a normal maximum/minimum filter, which finds all turning points, then filter the list of turning points by threshold.

    3. I think what you really want to do is remove the "long-term variation" from the signal and look only at the "short term variation". This is can be done using the empirical mode decomposition. See Sec 2.3.2 of my thesis. (Alernately, Google around for "Empirical Mode Decomposition", "EMD", or "Hilbert-Huang Transform".)

    Here's the EMD in action:

    enter image description here

    Notice the increasing generality as the EMD algorithm extracts components of the signal, starting at "most detailed" and ending with "most general trend". (Note there are apparently nine components - only a few are shown.)

    0 讨论(0)
提交回复
热议问题