You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The detect_peaks function is used to identify peaks and lows in a given column of a DataFrame. It returns a DataFrame with two additional columns: one for higher highs and another for lower lows. The function can be used to detect peaks and lows in a DataFrame. It identifies local maxima and minima based on the specified order of neighboring points. The function can also filter out peaks and lows based on a minimum number of consecutive occurrences. This allows you to focus on significant peaks and lows that are more likely to be relevant for analysis.
485
+
486
+
> There is always a delay between an actual peak and the detection of that peak. This is determined by the `number_of_neighbors_to_compare` parameter. For example
487
+
> if for a given column you set `number_of_neighbors_to_compare=5`, the function will look at the 5 previous and 5 next data points to determine if the current point is a peak or a low. This means that the peak or low will only be detected after the 5th data point has been processed. So say you have OHLCV data of 15 minute intervals, and you set `number_of_neighbors_to_compare=5`, the function will only detect the peak or low after the 5th data point has been processed, which means that there will be a delay of 75 minutes (5 * 15 minutes) before the peak or low is detected.
488
+
489
+
```python
490
+
defdetect_peaks(
491
+
data: Union[PdDataFrame, PlDataFrame],
492
+
column: str,
493
+
number_of_neighbors_to_compare: int=5,
494
+
min_consecutive: int=2
495
+
) -> Union[PdDataFrame, PlDataFrame]:
496
+
```
497
+
498
+
Example
499
+
500
+
```python
501
+
from investing_algorithm_framework import download
502
+
from pyindicators import detect_peaks
503
+
504
+
pl_df = download(
505
+
symbol="btc/eur",
506
+
market="binance",
507
+
time_frame="1d",
508
+
start_date="2023-12-01",
509
+
end_date="2023-12-25",
510
+
save=True,
511
+
storage_path="./data"
512
+
)
513
+
514
+
pd_df = download(
515
+
symbol="btc/eur",
516
+
market="binance",
517
+
time_frame="1d",
518
+
start_date="2023-12-01",
519
+
end_date="2023-12-25",
520
+
pandas=True,
521
+
save=True,
522
+
storage_path="./data"
523
+
)
524
+
525
+
# Calculate peaks and lows for Polars DataFrame, with a neighbour comparison of 4 and minimum of 2 consecutive peaks
The detect_bullish_divergence function is used to identify bullish divergences between two columns in a DataFrame. It checks for bullish divergences based on the peaks and lows detected in the specified columns. The function returns a DataFrame with additional columns indicating the presence of bullish divergences.
539
+
540
+
A bullish divergence occurs when the price makes a lower low while the indicator makes a higher low. This suggests that the downward momentum is weakening, and a potential reversal to the upside may occur.
541
+
542
+
> !Important: This function expects that for two given columns there will be corresponding peaks and lows columns. This means that before you can use this function, you must first call the detect_peaks function on both columns. For example: if you want to detect bullish divergence between the "Close" column and the "RSI_14" column, you must first call detect_peaks on both columns.
543
+
> If no corresponding {column}_peaks and {column}_lows columns are found, the function will raise a PyIndicatorException.
544
+
545
+
```python
546
+
defbullish_divergence(
547
+
data: Union[pd.DataFrame, pl.DataFrame],
548
+
first_column: str,
549
+
second_column: str,
550
+
window_size=1,
551
+
result_column: str="bullish_divergence",
552
+
number_of_neighbors_to_compare: int=5,
553
+
min_consecutive: int=2
554
+
) -> Union[pd.DataFrame, pl.DataFrame]:
555
+
```
556
+
557
+
Example
558
+
559
+
```python
560
+
from investing_algorithm_framework import download
561
+
from pyindicators import bullish_divergence
562
+
pl_df = download(
563
+
symbol="btc/eur",
564
+
market="binance",
565
+
time_frame="1d",
566
+
start_date="2023-12-01",
567
+
end_date="2023-12-25",
568
+
save=True,
569
+
storage_path="./data"
570
+
)
571
+
pd_df = download(
572
+
symbol="btc/eur",
573
+
market="binance",
574
+
time_frame="1d",
575
+
start_date="2023-12-01",
576
+
end_date="2023-12-25",
577
+
pandas=True,
578
+
save=True,
579
+
storage_path="./data"
580
+
)
581
+
582
+
# Calculate bullish divergence for Polars DataFrame
The detect_bearish_divergence function is used to identify bearish divergences between two columns in a DataFrame. It checks for bearish divergences based on the peaks and lows detected in the specified columns. The function returns a DataFrame with additional columns indicating the presence of bearish divergences.
596
+
597
+
A bearish divergence occurs when the price makes a higher high while the indicator makes a lower high. This suggests that the upward momentum is weakening, and a potential reversal to the downside may occur.
598
+
599
+
```python
600
+
defbearish_divergence(
601
+
data: Union[pd.DataFrame, pl.DataFrame],
602
+
first_column: str,
603
+
second_column: str,
604
+
window_size=1,
605
+
result_column: str="bearish_divergence",
606
+
number_of_neighbors_to_compare: int=5,
607
+
min_consecutive: int=2
608
+
) -> Union[pd.DataFrame, pl.DataFrame]:
609
+
```
610
+
611
+
Example
612
+
613
+
```python
614
+
from investing_algorithm_framework import download
615
+
from pyindicators import bearish_divergence
616
+
pl_df = download(
617
+
symbol="btc/eur",
618
+
market="binance",
619
+
time_frame="1d",
620
+
start_date="2023-12-01",
621
+
end_date="2023-12-25",
622
+
save=True,
623
+
storage_path="./data"
624
+
)
625
+
pd_df = download(
626
+
symbol="btc/eur",
627
+
market="binance",
628
+
time_frame="1d",
629
+
start_date="2023-12-01",
630
+
end_date="2023-12-25",
631
+
pandas=True,
632
+
save=True,
633
+
storage_path="./data"
634
+
)
635
+
636
+
# Calculate bearish divergence for Polars DataFrame
0 commit comments