Peak Detection in Time Series

后端 未结 6 1744
栀梦
栀梦 2021-02-01 07:59

I\'m currently working on a little project in which I want to compare two time-series. The similarity measure is really vague, they are considered to be similar if the two time

6条回答
  •  遥遥无期
    2021-02-01 08:43

    You seem to simply look for slope inversion (from positive to negative and vice versa). A rough java algo could be (not tested):

    List points = ... //all the points in your curve
    List extremes = new ArrayList ();
    double previous = null;
    double previousSlope = 0;
    
    for (Point p : points) {
        if (previous == null) { previous = p; continue; }
        double slope = p.getValue() - previous.getValue();
        if (slope * previousSlope < 0) { //look for sign changes
            extremes.add(previous);
        }
        previousSlope = slope;
        previous = p;
    }
    

    Finally, a good way to measure similarity is correlation. In your case, I would look at % move correlation (in other words, you want your 2 series to go up or down at the same time) - that's typically what is done in finance where you calculate the correlation between 2 assets returns for example:

    • create 2 new series with the % move for each point of the 2 series
    • calculate the correlation between those 2 series

    You can read more about returns correlations here for example. In summary, if your values are:

    Series 1  Series 2
     100        50
     98         49
     100        52
     102        54
    

    The "returns" series will be:

    Series 1  Series 2
     -2.00%     -2.00%
     +2.04%     +6.12%
     +2.00%     +3.85%
    

    And you calculate the correlation of those 2 returns series (in this example: 0.96) to get a measure of how much the 2 curves look alike. You might want to adjust the result for variance (i.e. if one shape has a much wider range than the other).

提交回复
热议问题