Plateau detection

Issue #4 resolved
Former user created an issue

Hi!

Thanks for your great work. I have some date which does not have a peak but several plateaus (consecutive peaks with the same value). Is there a possibility to detect them with your functions?

Comments (11)

  1. Lucas Hermann Negri repo owner

    Hi,

    Currently no, as peakutils.indexes will not detect plateaus (with exact same values). I think this is a needed feature, and may be added.

  2. Lucas Hermann Negri repo owner

    It was. Can you share the data and the exact code snippet use to generate this plot?

  3. Nathan Gilford

    The data is real-time 1-minute ticks of EURUSD forex charts, using closing prices to draw the line graph. The data is collected through the Oanda API, but should be the same for any real-time source.

    import peakutils
    from peakutils.peak import indexes
    import matplotlib.pyplot as plt
    
    col1 = df.index.values
    col2 = df['rates']
    pkin = peakutils.indexes(col2, thres=0.05, min_dist=1)
    plt.plot(col1, col2, lw=0.4)
    plt.plot(col1[pkin], col2[pkin], 'ro')
    plt.show()
    
  4. Nathan Gilford

    Here is an example, I've managed to export it all as a csv, but I'm unsure if that is necessary?

    ind.  rates
    ...     ...
    24  1.16305
    25  1.1631
    26  1.1631
    27  1.1631
    28  1.163
    

    As you can see index 25, 26, 27 in this example all have the same closing rate. I have an above average rate of repeating numbers because I take the close rates from bullish candlesticks and the open rate from bearish ones for a very specific purpose; normally I don't think forex data would have this many repeats, but they're still likely to happen.

    What this looks like graphed is:

    Screen Shot 2017-11-09 at 2.08.15 PM.png

  5. Lucas Hermann Negri repo owner

    From the data points you suplied:

    import peakutils as pu
    import peakutils.plot as p
    import numpy as np
    
    data = np.array([1.16305, 1.1631, 1.1631, 1.1631, 1.163])
    x = np.arange(len(data))
    ind = pu.indexes(data, thres=0.05, min_dist=1)
    p.plot(x, data, ind)
    p.plt.show()
    

    fig.png

  6. Bastien BRETEAU

    Works fine for me with version 1.1.0 even with a plateau with 3 consecutives indexes with the exact same value.

    peakutils.png

    Thank you for that very usefull library by the way!

  7. Nathan Gilford

    Oh I see. It was not an issue with peakutils, but my fault as a beginner to python. While I thought imports always brought in the newest version of a module that was not the case, but chasing down the version and updating fixed the issue right away for me. Thank you so much for your help!

  8. Lucas Hermann Negri repo owner

    I'm glad that it is working now. Special thanks to Christophe Vestri for implementing the plateau detection.

  9. Log in to comment