如何从已经平滑的图形中去除噪声

How to remove noise from already smoothed graph

def check_for_double_top_bot(symbol, time_frame):
 ticker_df = download_binance_candles(symbol, time_frame)
 y_filtered = savgol_filter(ticker_df["Close"], 11, 1)

 x = np.linspace(0, len(ticker_df), len(ticker_df)+1)

 data = y_filtered

 min_max = np.diff(np.sign(np.diff(data))).nonzero()[0] + 1  # local min & max
 l_min = (np.diff(np.sign(np.diff(data))) > 0).nonzero()[0] + 1  # local min
 l_max = (np.diff(np.sign(np.diff(data))) < 0).nonzero()[0] + 1  # local max

 print(min_max, l_max, l_min)
 plt.plot(x[l_min], data[l_min], "o", label="min", color='r')  # minima
 plt.plot(x[l_max], data[l_max], "o", label="max", color='b')
 plt.plot(y_filtered, color='black', label='EURUSD')
 plt.show()

我现在有这段代码可以在加密货币图表上找到转折点,但是,这条线似乎并没有完全平滑,因为我仍然收到大量噪音。

current smoothed image

是否有另一个过滤器可用于进一步平滑它以消除影响我寻找最大值和最小值的方式的小噪声?

曲线不能改变太多,因为转折点尽可能保持不变很重要。我主要是在寻找一种方法来减少当前曲线的“锯齿状”数量。

what it should look like

如您所见,由于残留的小噪音,存在不必要的转折点

更新:

正如下面答案中所建议的那样,我已经尝试了这段代码并且运行良好。

ticker_df = download_binance_candles(symbol, "5m")
s = np.random.normal(size=200).cumsum()
print(s)

kwargs = dict(distance=5, prominence=2)
imax, propmax = find_peaks(s, **kwargs)
imin, propmin = find_peaks(-s, **kwargs)

plt.plot(s)
plt.scatter(x=imax, y=s[imax], c='b')
plt.scatter(x=imin, y=s[imin], c='r')
print(imax, imin)
plt.show()

giving this result

以及这些最大值和最小值:[ 12 25 54 67 79 90 97 105 124 133 148 177 190] [ 21 28 33 63 72 85 94 100 115 141 151 185]

然而,当我使用我的 pandas 系列时,它无法计算出任何最大值或最小值。即使转换为 np.array.

ticker_df = download_binance_candles(symbol, "5m")
s = ticker_df["High"].values
print(s)

kwargs = dict(distance=5, prominence=2)
imax, propmax = find_peaks(s, **kwargs)
imin, propmin = find_peaks(-s, **kwargs)

plt.plot(s)
plt.scatter(x=imax, y=s[imax], c='b')
plt.scatter(x=imin, y=s[imin], c='r')
print(imax, imin)
plt.show()

giving this without maxima or minima

[][]

制成dataframes的CSV是这样的:

Date,Open,High,Low,Close,Volume,Adj Close,21 Day MA,21 Day STD,Upper Band,Lower Band
2021-08-15 10:05:00,0.09595,0.09625,0.09593,0.09621,618373,0.09621
2021-08-15 10:10:00,0.09623,0.09637,0.09601,0.09637,591335,0.09637
2021-08-15 10:15:00,0.09636,0.09649,0.09628,0.09631,330937,0.09631
2021-08-15 10:20:00,0.09634,0.09634,0.09604,0.09617,434572,0.09617
2021-08-15 10:25:00,0.09619,0.09650,0.09611,0.09627,673191,0.09627
2021-08-15 10:30:00,0.09626,0.09664,0.09609,0.09664,665751,0.09664
2021-08-15 10:35:00,0.09664,0.09673,0.09643,0.09663,884939,0.09663
2021-08-15 10:40:00,0.09670,0.09701,0.09662,0.09694,499309,0.09694
2021-08-15 10:45:00,0.09694,0.09706,0.09678,0.09695,992876,0.09695
2021-08-15 10:50:00,0.09697,0.09697,0.09665,0.09680,342539,0.09680
2021-08-15 10:55:00,0.09681,0.09690,0.09661,0.09689,278168,0.09689
2021-08-15 11:00:00,0.09681,0.09700,0.09658,0.09693,1207392,0.09693
2021-08-15 11:05:00,0.09691,0.09734,0.09691,0.09730,1124751,0.09730
2021-08-15 11:10:00,0.09731,0.09744,0.09722,0.09724,995906,0.09724
2021-08-15 11:15:00,0.09725,0.09743,0.09699,0.09702,1298901,0.09702
2021-08-15 11:20:00,0.09705,0.09732,0.09704,0.09722,910978,0.09722
2021-08-15 11:25:00,0.09725,0.09728,0.09701,0.09722,863326,0.09722
2021-08-15 11:30:00,0.09720,0.09751,0.09694,0.09700,1451370,0.09700
2021-08-15 11:35:00,0.09701,0.09709,0.09655,0.09681,997123,0.09681
2021-08-15 11:40:00,0.09684,0.09719,0.09667,0.09670,807811,0.09670
2021-08-15 11:45:00,0.09667,0.09706,0.09657,0.09666,361049,0.09666
2021-08-15 11:50:00,0.09669,0.09688,0.09610,0.09659,1156367,0.09659
2021-08-15 11:55:00,0.09651,0.09684,0.09651,0.09669,516878,0.09669
2021-08-15 12:00:00,0.09670,0.09670,0.09638,0.09638,375451,0.09638
2021-08-15 12:05:00,0.09639,0.09657,0.09621,0.09623,456004,0.09623
2021-08-15 12:10:00,0.09631,0.09636,0.09556,0.09573,1344161,0.09573
2021-08-15 12:15:00,0.09571,0.09635,0.09564,0.09604,1085739,0.09604
2021-08-15 12:20:00,0.09620,0.09623,0.09583,0.09616,263289,0.09616
2021-08-15 12:25:00,0.09623,0.09635,0.09602,0.09635,372213,0.09635
2021-08-15 12:30:00,0.09635,0.09697,0.09630,0.09690,882856,0.09690
2021-08-15 12:35:00,0.09695,0.09709,0.09668,0.09678,1030638,0.09678
2021-08-15 12:40:00,0.09684,0.09684,0.09654,0.09660,898380,0.09660
2021-08-15 12:45:00,0.09662,0.09665,0.09624,0.09630,837715,0.09630
2021-08-15 12:50:00,0.09632,0.09652,0.09619,0.09647,640481,0.09647
2021-08-15 12:55:00,0.09645,0.09675,0.09644,0.09660,562040,0.09660
2021-08-15 13:00:00,0.09663,0.09663,0.09589,0.09611,1335005,0.09611
2021-08-15 13:05:00,0.09603,0.09675,0.09602,0.09673,936214,0.09673
2021-08-15 13:10:00,0.09673,0.09684,0.09646,0.09655,533439,0.09655
2021-08-15 13:15:00,0.09655,0.09655,0.09611,0.09614,300378,0.09614
2021-08-15 13:20:00,0.09610,0.09610,0.09582,0.09597,846500,0.09597
2021-08-15 13:25:00,0.09595,0.09609,0.09580,0.09604,462391,0.09604
2021-08-15 13:30:00,0.09602,0.09602,0.09569,0.09573,386237,0.09573
2021-08-15 13:35:00,0.09574,0.09584,0.09529,0.09536,985130,0.09536
2021-08-15 13:40:00,0.09539,0.09567,0.09521,0.09547,512357,0.09547
2021-08-15 13:45:00,0.09548,0.09559,0.09505,0.09518,800821,0.09518
2021-08-15 13:50:00,0.09513,0.09567,0.09509,0.09566,370242,0.09566
2021-08-15 13:55:00,0.09566,0.09568,0.09538,0.09551,259775,0.09551
2021-08-15 14:00:00,0.09550,0.09667,0.09531,0.09639,4695052,0.09639
2021-08-15 14:05:00,0.09642,0.09660,0.09633,0.09649,1159395,0.09649
2021-08-15 14:10:00,0.09654,0.09655,0.09618,0.09647,423402,0.09647
2021-08-15 14:15:00,0.09645,0.09705,0.09617,0.09678,3825841,0.09678
2021-08-15 14:20:00,0.09675,0.09693,0.09652,0.09684,673124,0.09684
2021-08-15 14:25:00,0.09681,0.09705,0.09657,0.09705,717827,0.09705
2021-08-15 14:30:00,0.09705,0.09708,0.09670,0.09703,1021557,0.09703
2021-08-15 14:35:00,0.09697,0.09702,0.09663,0.09669,1034057,0.09669
2021-08-15 14:40:00,0.09668,0.09676,0.09541,0.09571,3181710,0.09571
2021-08-15 14:45:00,0.09566,0.09705,0.09542,0.09688,3355165,0.09688
2021-08-15 14:50:00,0.09690,0.09850,0.09688,0.09799,5824589,0.09799
2021-08-15 14:55:00,0.09798,0.09810,0.09760,0.09807,1114093,0.09807
2021-08-15 15:00:00,0.09806,0.09806,0.09726,0.09800,2744572,0.09800
2021-08-15 15:05:00,0.09800,0.09910,0.09794,0.09852,3421884,0.09852
2021-08-15 15:10:00,0.09858,0.09858,0.09804,0.09821,1427867,0.09821
2021-08-15 15:15:00,0.09825,0.09843,0.09778,0.09783,705302,0.09783
2021-08-15 15:20:00,0.09789,0.09824,0.09760,0.09811,898435,0.09811
2021-08-15 15:25:00,0.09815,0.09822,0.09789,0.09791,482735,0.09791
2021-08-15 15:30:00,0.09796,0.09809,0.09779,0.09807,416140,0.09807
2021-08-15 15:35:00,0.09805,0.09805,0.09778,0.09794,310080,0.09794
2021-08-15 15:40:00,0.09789,0.09794,0.09735,0.09758,1295707,0.09758
2021-08-15 15:45:00,0.09759,0.09860,0.09728,0.09764,2992857,0.09764
2021-08-15 15:50:00,0.09762,0.09786,0.09713,0.09775,2046431,0.09775
2021-08-15 15:55:00,0.09773,0.09807,0.09769,0.09773,908042,0.09773
2021-08-15 16:00:00,0.09770,0.09805,0.09742,0.09743,1303649,0.09743
2021-08-15 16:05:00,0.09741,0.09765,0.09736,0.09755,493012,0.09755
2021-08-15 16:10:00,0.09755,0.09774,0.09744,0.09766,892380,0.09766
2021-08-15 16:15:00,0.09768,0.09768,0.09746,0.09753,433998,0.09753
2021-08-15 16:20:00,0.09750,0.09751,0.09674,0.09675,1375215,0.09675
2021-08-15 16:25:00,0.09675,0.09696,0.09660,0.09689,964676,0.09689
2021-08-15 16:30:00,0.09689,0.09689,0.09652,0.09669,719340,0.09669
2021-08-15 16:35:00,0.09666,0.09679,0.09658,0.09679,272555,0.09679
2021-08-15 16:40:00,0.09671,0.09693,0.09665,0.09684,129453,0.09684
2021-08-15 16:45:00,0.09681,0.09695,0.09671,0.09683,230532,0.09683
2021-08-15 16:50:00,0.09681,0.09720,0.09655,0.09695,839011,0.09695
2021-08-15 16:55:00,0.09692,0.09743,0.09691,0.09735,326566,0.09735
2021-08-15 17:00:00,0.09724,0.09765,0.09716,0.09755,1014406,0.09755
2021-08-15 17:05:00,0.09756,0.09757,0.09724,0.09747,701441,0.09747
2021-08-15 17:10:00,0.09745,0.09745,0.09713,0.09717,552162,0.09717
2021-08-15 17:15:00,0.09720,0.09721,0.09690,0.09708,494911,0.09708
2021-08-15 17:20:00,0.09707,0.09731,0.09701,0.09723,406186,0.09723
2021-08-15 17:25:00,0.09727,0.09752,0.09713,0.09730,479641,0.09730
2021-08-15 17:30:00,0.09727,0.09739,0.09703,0.09703,691376,0.09703
2021-08-15 17:35:00,0.09709,0.09709,0.09691,0.09703,450561,0.09703
2021-08-15 17:40:00,0.09707,0.09711,0.09681,0.09698,408768,0.09698
2021-08-15 17:45:00,0.09694,0.09724,0.09688,0.09703,270688,0.09703
2021-08-15 17:50:00,0.09707,0.09714,0.09683,0.09690,181695,0.09690
2021-08-15 17:55:00,0.09691,0.09701,0.09669,0.09678,481029,0.09678
2021-08-15 18:00:00,0.09676,0.09694,0.09637,0.09652,1702031,0.09652
2021-08-15 18:05:00,0.09652,0.09723,0.09641,0.09703,1308661,0.09703
2021-08-15 18:10:00,0.09700,0.09716,0.09676,0.09686,481690,0.09686
2021-08-15 18:15:00,0.09683,0.09706,0.09645,0.09677,847609,0.09677
2021-08-15 18:20:00,0.09672,0.09674,0.09648,0.09655,201331,0.09655
2021-08-15 18:25:00,0.09658,0.09727,0.09658,0.09718,486519,0.09718
2021-08-15 18:30:00,0.09712,0.09731,0.09696,0.09710,1080959,0.09710
2021-08-15 18:35:00,0.09718,0.09718,0.09680,0.09693,417610,0.09693
2021-08-15 18:40:00,0.09699,0.09709,0.09677,0.09704,205765,0.09704
2021-08-15 18:45:00,0.09703,0.09736,0.09696,0.09727,299985,0.09727
2021-08-15 18:50:00,0.09728,0.09745,0.09704,0.09730,605530,0.09730
2021-08-15 18:55:00,0.09738,0.09738,0.09715,0.09731,386545,0.09731
2021-08-15 19:00:00,0.09731,0.09762,0.09717,0.09762,557397,0.09762
2021-08-15 19:05:00,0.09762,0.09779,0.09740,0.09762,601306,0.09762
2021-08-15 19:10:00,0.09766,0.09795,0.09751,0.09795,215518,0.09795
2021-08-15 19:15:00,0.09795,0.09795,0.09761,0.09788,410396,0.09788
2021-08-15 19:20:00,0.09790,0.09792,0.09748,0.09768,448007,0.09768
2021-08-15 19:25:00,0.09767,0.09780,0.09762,0.09763,381934,0.09763
2021-08-15 19:30:00,0.09763,0.09763,0.09701,0.09733,1252571,0.09733
2021-08-15 19:35:00,0.09745,0.09762,0.09712,0.09746,462545,0.09746
2021-08-15 19:40:00,0.09753,0.09806,0.09746,0.09791,847587,0.09791
2021-08-15 19:45:00,0.09790,0.09796,0.09769,0.09786,359940,0.09786
2021-08-15 19:50:00,0.09790,0.09791,0.09769,0.09784,220705,0.09784
2021-08-15 19:55:00,0.09784,0.09806,0.09770,0.09798,305901,0.09798
2021-08-15 20:00:00,0.09793,0.09815,0.09779,0.09786,718354,0.09786
2021-08-15 20:05:00,0.09787,0.09790,0.09770,0.09779,224539,0.09779
2021-08-15 20:10:00,0.09778,0.09778,0.09744,0.09764,400808,0.09764
2021-08-15 20:15:00,0.09768,0.09776,0.09746,0.09763,180764,0.09763
2021-08-15 20:20:00,0.09763,0.09769,0.09730,0.09741,327170,0.09741
2021-08-15 20:25:00,0.09745,0.09766,0.09738,0.09747,328968,0.09747
2021-08-15 20:30:00,0.09750,0.09799,0.09750,0.09797,483365,0.09797
2021-08-15 20:35:00,0.09797,0.09802,0.09753,0.09787,466496,0.09787
2021-08-15 20:40:00,0.09785,0.09820,0.09783,0.09810,728733,0.09810
2021-08-15 20:45:00,0.09809,0.09862,0.09797,0.09860,1058141,0.09860
2021-08-15 20:50:00,0.09861,0.09869,0.09821,0.09852,1168443,0.09852
2021-08-15 20:55:00,0.09850,0.09896,0.09842,0.09896,571561,0.09896
2021-08-15 21:00:00,0.09895,0.09936,0.09874,0.09936,1684329,0.09936
2021-08-15 21:05:00,0.09936,0.09942,0.09880,0.09903,1055679,0.09903
2021-08-15 21:10:00,0.09904,0.09904,0.09873,0.09888,552692,0.09888
2021-08-15 21:15:00,0.09889,0.09969,0.09886,0.09965,1697964,0.09965
2021-08-15 21:20:00,0.09969,0.09974,0.09914,0.09947,1431400,0.09947
2021-08-15 21:25:00,0.09940,0.09987,0.09940,0.09973,1372999,0.09973
2021-08-15 21:30:00,0.09971,0.10024,0.09968,0.09996,2267263,0.09996
2021-08-15 21:35:00,0.10001,0.10063,0.09984,0.10050,1761268,0.10050
2021-08-15 21:40:00,0.10050,0.10126,0.10043,0.10117,2469420,0.10117
2021-08-15 21:45:00,0.10118,0.10130,0.10067,0.10103,1934420,0.10103
2021-08-15 21:50:00,0.10100,0.10119,0.10091,0.10097,1024251,0.10097
2021-08-15 21:55:00,0.10103,0.10260,0.10097,0.10202,6882531,0.10202
2021-08-15 22:00:00,0.10201,0.10329,0.10200,0.10256,4264399,0.10256
2021-08-15 22:05:00,0.10256,0.10609,0.10249,0.10513,10593630,0.10513
2021-08-15 22:10:00,0.10514,0.10654,0.10483,0.10563,11995237,0.10563
2021-08-15 22:15:00,0.10561,0.10570,0.10403,0.10505,7692354,0.10505
2021-08-15 22:20:00,0.10504,0.10522,0.10425,0.10466,3101808,0.10466
2021-08-15 22:25:00,0.10466,0.10467,0.10346,0.10357,4634070,0.10357
2021-08-15 22:30:00,0.10360,0.10373,0.10275,0.10349,4581891,0.10349
2021-08-15 22:35:00,0.10352,0.10446,0.10273,0.10367,4690129,0.10367
2021-08-15 22:40:00,0.10368,0.10559,0.10326,0.10539,7682674,0.10539
2021-08-15 22:45:00,0.10538,0.10580,0.10470,0.10493,5626312,0.10493
2021-08-15 22:50:00,0.10494,0.10774,0.10494,0.10698,10138352,0.10698
2021-08-15 22:55:00,0.10706,0.10850,0.10698,0.10786,8821167,0.10786
2021-08-15 23:00:00,0.10785,0.10868,0.10723,0.10787,7313120,0.10787
2021-08-15 23:05:00,0.10778,0.10785,0.10670,0.10692,3369346,0.10692
2021-08-15 23:10:00,0.10686,0.10759,0.10675,0.10679,1875751,0.10679
2021-08-15 23:15:00,0.10680,0.10724,0.10678,0.10723,1833018,0.10723
2021-08-15 23:20:00,0.10720,0.10746,0.10678,0.10710,2491003,0.10710
2021-08-15 23:25:00,0.10712,0.10768,0.10699,0.10730,1629989,0.10730
2021-08-15 23:30:00,0.10730,0.10736,0.10609,0.10614,2441915,0.10614
2021-08-15 23:35:00,0.10617,0.10712,0.10617,0.10679,2315005,0.10679
2021-08-15 23:40:00,0.10683,0.10683,0.10619,0.10661,2531106,0.10661
2021-08-15 23:45:00,0.10667,0.10720,0.10663,0.10680,1966298,0.10680
2021-08-15 23:50:00,0.10683,0.10695,0.10611,0.10629,1616144,0.10629
2021-08-15 23:55:00,0.10630,0.10836,0.10613,0.10834,2720109,0.10834
2021-08-16 00:00:00,0.10834,0.10841,0.10679,0.10718,4052530,0.10718
2021-08-16 00:05:00,0.10710,0.10728,0.10656,0.10700,1589434,0.10700
2021-08-16 00:10:00,0.10696,0.10849,0.10696,0.10841,1571219,0.10841
2021-08-16 00:15:00,0.10840,0.11009,0.10835,0.10953,8934203,0.10953
2021-08-16 00:20:00,0.10954,0.10954,0.10822,0.10824,4747749,0.10824
2021-08-16 00:25:00,0.10824,0.10850,0.10726,0.10739,2429017,0.10739
2021-08-16 00:30:00,0.10739,0.10754,0.10726,0.10726,1063838,0.10726
2021-08-16 00:35:00,0.10726,0.10888,0.10726,0.10747,4744576,0.10747
2021-08-16 00:40:00,0.10749,0.10765,0.10735,0.10760,717202,0.10760
2021-08-16 00:45:00,0.10762,0.10883,0.10760,0.10781,2193401,0.10781
2021-08-16 00:50:00,0.10786,0.10845,0.10782,0.10820,919417,0.10820
2021-08-16 00:55:00,0.10819,0.10832,0.10774,0.10809,1294347,0.10809
2021-08-16 01:00:00,0.10808,0.11025,0.10806,0.10963,5548691,0.10963
2021-08-16 01:05:00,0.10964,0.11300,0.10958,0.11282,16036488,0.11282
2021-08-16 01:10:00,0.11278,0.11300,0.10945,0.11214,16137300,0.11214
2021-08-16 01:15:00,0.11212,0.11243,0.10953,0.11020,8878423,0.11020
2021-08-16 01:20:00,0.11019,0.11035,0.10880,0.10977,4978442,0.10977
2021-08-16 01:25:00,0.10975,0.11099,0.10948,0.11059,3514627,0.11059
2021-08-16 01:30:00,0.11054,0.11194,0.11050,0.11187,5328608,0.11187
2021-08-16 01:35:00,0.11181,0.11186,0.11000,0.11030,4483301,0.11030
2021-08-16 01:40:00,0.11029,0.11110,0.10986,0.11098,4019540,0.11098
2021-08-16 01:45:00,0.11103,0.11111,0.11026,0.11063,2491489,0.11063
2021-08-16 01:50:00,0.11064,0.11089,0.10971,0.11029,2936959,0.11029
2021-08-16 01:55:00,0.11031,0.11087,0.11009,0.11082,1109563,0.11082
2021-08-16 02:00:00,0.11078,0.11131,0.10913,0.10946,5027246,0.10946
2021-08-16 02:05:00,0.10946,0.10999,0.10928,0.10959,2753645,0.10959
2021-08-16 02:10:00,0.10962,0.11000,0.10959,0.10994,1133122,0.10994
2021-08-16 02:15:00,0.10990,0.11150,0.10990,0.11104,3142623,0.11104
2021-08-16 02:20:00,0.11101,0.11249,0.11092,0.11214,6178772,0.11214
2021-08-16 02:25:00,0.11213,0.11266,0.11200,0.11211,3361049,0.11211
2021-08-16 02:30:00,0.11214,0.11235,0.11100,0.11183,6650246,0.11183
2021-08-16 02:35:00,0.11185,0.11246,0.11101,0.11112,2216568,0.11112
2021-08-16 02:40:00,0.11111,0.11166,0.11095,0.11102,1418282,0.11102
2021-08-16 02:45:00,0.11104,0.11210,0.11104,0.11167,1975305,0.11167
2021-08-16 02:50:00,0.11170,0.11354,0.11170,0.11341,4745238,0.11341
2021-08-16 02:55:00,0.11352,0.11445,0.11328,0.11381,7154140,0.11381
2021-08-16 03:00:00,0.11379,0.11399,0.11247,0.11256,4473517,0.11256
2021-08-16 03:05:00,0.11260,0.11274,0.11188,0.11205,2365967,0.11205
2021-08-16 03:10:00,0.11205,0.11240,0.11160,0.11212,2181630,0.11212
2021-08-16 03:15:00,0.11212,0.11331,0.11196,0.11199,2671132,0.11199
2021-08-16 03:20:00,0.11203,0.11288,0.11196,0.11248,2479541,0.11248
2021-08-16 03:25:00,0.11250,0.11466,0.11250,0.11380,7486247,0.11380
2021-08-16 03:30:00,0.11387,0.11473,0.11372,0.11391,6428209,0.11391
2021-08-16 03:35:00,0.11400,0.11455,0.11390,0.11427,3195689,0.11427
2021-08-16 03:40:00,0.11425,0.11436,0.11310,0.11354,4194721,0.11354
2021-08-16 03:45:00,0.11353,0.11386,0.11306,0.11314,4911829,0.11314
2021-08-16 03:50:00,0.11317,0.11322,0.11248,0.11294,2171526,0.11294
2021-08-16 03:55:00,0.11289,0.11352,0.11285,0.11320,2310164,0.11320
2021-08-16 04:00:00,0.11321,0.11339,0.11228,0.11294,2490559,0.11294
2021-08-16 04:05:00,0.11294,0.11311,0.11268,0.11280,1328500,0.11280
2021-08-16 04:10:00,0.11280,0.11374,0.11275,0.11341,3127305,0.11341
2021-08-16 04:15:00,0.11341,0.11567,0.11334,0.11531,6390195,0.11531
2021-08-16 04:20:00,0.11529,0.11828,0.11503,0.11818,13150161,0.11818
2021-08-16 04:25:00,0.11817,0.11887,0.11678,0.11723,16415597,0.11723
2021-08-16 04:30:00,0.11716,0.11779,0.11565,0.11592,9934460,0.11592
2021-08-16 04:35:00,0.11586,0.11632,0.11357,0.11364,11374238,0.11364
2021-08-16 04:40:00,0.11364,0.11470,0.11350,0.11355,6486211,0.11355
2021-08-16 04:45:00,0.11359,0.11483,0.11231,0.11309,11397993,0.11309
2021-08-16 04:50:00,0.11310,0.11359,0.11141,0.11141,11940502,0.11141
2021-08-16 04:55:00,0.11141,0.11283,0.11117,0.11248,7553309,0.11248
2021-08-16 05:00:00,0.11251,0.11312,0.11249,0.11306,4484691,0.11306
2021-08-16 05:05:00,0.11306,0.11331,0.11304,0.11328,1879152,0.11328
2021-08-16 05:10:00,0.11326,0.11384,0.11310,0.11374,3460818,0.11374
2021-08-16 05:15:00,0.11375,0.11566,0.11375,0.11460,6249251,0.11460
2021-08-16 05:20:00,0.11461,0.11621,0.11383,0.11567,6087717,0.11567

考虑使用 scipy.signal.find_peaks

重要提示:请注意,以下所有技术都具有 峰值提前偏差(它们在考虑任何给定的未来时使用点点),对任何类型的交易算法都有严重影响。

排除免责声明,这是一个查找局部最大值的示例(对于局部最小值,您只需使用 find_peaks(-s, ...)):

# random walk
np.random.seed(0)
s = np.random.normal(size=200).cumsum()

# find local maximas
from scipy.signal import find_peaks

imax, propmax = find_peaks(s)
plt.plot(s)
plt.scatter(x=imax, y=s[imax])
plt.show()

您可以通过指定峰属性的条件来更改保留哪些峰。有关完整示例,包括寻找最小值:

kwargs = dict(distance=5, prominence=2)
imax, propmax = find_peaks(s, **kwargs)
imin, propmin = find_peaks(-s, **kwargs)

plt.plot(s)
plt.scatter(x=imax, y=s[imax], c='b')
plt.scatter(x=imin, y=s[imin], c='r')
plt.show()

您可以将其与系列的预过滤相结合。滤除噪声的常用技术是 median filter.

z = pd.Series(s).rolling(4, center=True).median()
z.plot()

kwargs = dict(distance=5, prominence=2)
imax, propmax = find_peaks(z, **kwargs)
imin, propmin = find_peaks(-z, **kwargs)

plt.scatter(x=imax, y=z[imax], c='b')
plt.scatter(x=imin, y=z[imin], c='r')
plt.show()

最后,为了有效地研究时间序列的“峰谷”间隔和其他类似属性,来自 Detrended Fluctuation Analysis 的技术非常强大。不过,这超出了本答案的范围。