|
1 | 1 | # PyIndicators |
2 | 2 |
|
3 | | -PyIndicators is a powerful and user-friendly Python library for technical analysis indicators, metrics and helper functions. Written entirely in Python, it requires no external dependencies, ensuring seamless integration and ease of use. |
| 3 | +PyIndicators is a powerful and user-friendly Python library for financial technical analysis indicators, metrics and helper functions. Written entirely in Python, it requires no external dependencies, ensuring seamless integration and ease of use. |
4 | 4 |
|
5 | 5 | ## Sponsors |
6 | 6 |
|
@@ -29,13 +29,16 @@ pip install pyindicators |
29 | 29 | * [Weighted Moving Average (WMA)](#weighted-moving-average-wma) |
30 | 30 | * [Simple Moving Average (SMA)](#simple-moving-average-sma) |
31 | 31 | * [Exponential Moving Average (EMA)](#exponential-moving-average-ema) |
32 | | - * [Stochastic Oscillator (STO)](#stochastic-oscillator-sto) |
33 | | -* [Momentum indicators](#momentum-indicators) |
| 32 | +* [Momentum and Oscillators](#momentum-and-oscillators) |
34 | 33 | * [Moving Average Convergence Divergence (MACD)](#moving-average-convergence-divergence-macd) |
35 | 34 | * [Relative Strength Index (RSI)](#relative-strength-index-rsi) |
36 | 35 | * [Relative Strength Index Wilders method (Wilders RSI)](#wilders-relative-strength-index-wilders-rsi) |
37 | 36 | * [Williams %R](#williams-r) |
38 | 37 | * [Average Directional Index (ADX)](#average-directional-index-adx) |
| 38 | + * [Stochastic Oscillator (STO)](#stochastic-oscillator-sto) |
| 39 | +* [Volatility indicators](#volatility-indicators) |
| 40 | + * [Bollinger Bands (BB)](#bollinger-bands-bb) |
| 41 | + * [Average True Range (ATR)](#average-true-range-atr) |
39 | 42 | * [Pattern recognition](#pattern-recognition) |
40 | 43 | * [Detect Peaks](#detect-peaks) |
41 | 44 | * [Detect Bullish Divergence](#detect-bullish-divergence) |
@@ -208,57 +211,7 @@ pd_df.tail(10) |
208 | 211 |
|
209 | 212 |  |
210 | 213 |
|
211 | | -#### Stochastic Oscillator (STO) |
212 | | -The Stochastic Oscillator (STO) is a momentum indicator that compares a particular closing price of an asset to a range of its prices over a certain period. It is used to identify overbought or oversold conditions in a market. The STO consists of two lines: %K and %D, where %K is the main line and %D is the signal line. |
213 | | - |
214 | | -```python |
215 | | -def stochastic_oscillator( |
216 | | - data: Union[pd.DataFrame, pl.DataFrame], |
217 | | - high_column: str = "High", |
218 | | - low_column: str = "Low", |
219 | | - close_column: str = "Close", |
220 | | - k_period: int = 14, |
221 | | - k_slowing: int = 3, |
222 | | - d_period: int = 3, |
223 | | - result_column: Optional[str] = None |
224 | | -) -> Union[pd.DataFrame, pl.DataFrame]: |
225 | | -``` |
226 | | - |
227 | | -Example |
228 | | - |
229 | | -```python |
230 | | -from investing_algorithm_framework import download |
231 | | -from pyindicators import stochastic_oscillator |
232 | | -pl_df = download( |
233 | | - symbol="btc/eur", |
234 | | - market="binance", |
235 | | - time_frame="1d", |
236 | | - start_date="2023-12-01", |
237 | | - end_date="2023-12-25", |
238 | | - save=True, |
239 | | - storage_path="./data" |
240 | | -) |
241 | | -pd_df = download( |
242 | | - symbol="btc/eur", |
243 | | - market="binance", |
244 | | - time_frame="1d", |
245 | | - start_date="2023-12-01", |
246 | | - end_date="2023-12-25", |
247 | | - pandas=True, |
248 | | - save=True, |
249 | | - storage_path="./data" |
250 | | -) |
251 | | -# Calculate Stochastic Oscillator for Polars DataFrame |
252 | | -pl_df = stochastic_oscillator(pl_df, high_column="High", low_column="Low", close_column="Close", k_period=14, k_slowing=3, d_period=3, result_column="STO") |
253 | | -pl_df.show(10) |
254 | | -# Calculate Stochastic Oscillator for Pandas DataFrame |
255 | | -pd_df = stochastic_oscillator(pd_df, high_column="High", low_column="Low", close_column="Close", k_period=14, k_slowing=3, d_period=3, result_column="STO") |
256 | | -pd_df.tail(10) |
257 | | -``` |
258 | | - |
259 | | - |
260 | | - |
261 | | -### Momentum Indicators |
| 214 | +### Momentum and Oscillators |
262 | 215 |
|
263 | 216 | Indicators that measure the strength and speed of price movements rather than the direction. |
264 | 217 |
|
@@ -528,6 +481,167 @@ pd_df.tail(10) |
528 | 481 |
|
529 | 482 |  |
530 | 483 |
|
| 484 | +#### Stochastic Oscillator (STO) |
| 485 | +The Stochastic Oscillator (STO) is a momentum indicator that compares a particular closing price of an asset to a range of its prices over a certain period. It is used to identify overbought or oversold conditions in a market. The STO consists of two lines: %K and %D, where %K is the main line and %D is the signal line. |
| 486 | + |
| 487 | +```python |
| 488 | +def stochastic_oscillator( |
| 489 | + data: Union[pd.DataFrame, pl.DataFrame], |
| 490 | + high_column: str = "High", |
| 491 | + low_column: str = "Low", |
| 492 | + close_column: str = "Close", |
| 493 | + k_period: int = 14, |
| 494 | + k_slowing: int = 3, |
| 495 | + d_period: int = 3, |
| 496 | + result_column: Optional[str] = None |
| 497 | +) -> Union[pd.DataFrame, pl.DataFrame]: |
| 498 | +``` |
| 499 | + |
| 500 | +Example |
| 501 | + |
| 502 | +```python |
| 503 | +from investing_algorithm_framework import download |
| 504 | +from pyindicators import stochastic_oscillator |
| 505 | +pl_df = download( |
| 506 | + symbol="btc/eur", |
| 507 | + market="binance", |
| 508 | + time_frame="1d", |
| 509 | + start_date="2023-12-01", |
| 510 | + end_date="2023-12-25", |
| 511 | + save=True, |
| 512 | + storage_path="./data" |
| 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 | +# Calculate Stochastic Oscillator for Polars DataFrame |
| 525 | +pl_df = stochastic_oscillator(pl_df, high_column="High", low_column="Low", close_column="Close", k_period=14, k_slowing=3, d_period=3, result_column="STO") |
| 526 | +pl_df.show(10) |
| 527 | +# Calculate Stochastic Oscillator for Pandas DataFrame |
| 528 | +pd_df = stochastic_oscillator(pd_df, high_column="High", low_column="Low", close_column="Close", k_period=14, k_slowing=3, d_period=3, result_column="STO") |
| 529 | +pd_df.tail(10) |
| 530 | +``` |
| 531 | + |
| 532 | + |
| 533 | + |
| 534 | +### Volatility indicators |
| 535 | + |
| 536 | +Indicators that measure the rate of price movement, regardless of direction. They help to identify |
| 537 | +periods of high and low volatility in the market. |
| 538 | + |
| 539 | +#### Bollinger Bands (BB) |
| 540 | + |
| 541 | +Bollinger Bands are a volatility indicator that consists of a middle band (SMA) and two outer bands (standard deviations). They help traders identify overbought and oversold conditions. |
| 542 | + |
| 543 | +```python |
| 544 | +def bollinger_bands( |
| 545 | + data: Union[PdDataFrame, PlDataFrame], |
| 546 | + source_column='Close', |
| 547 | + period=20, |
| 548 | + std_dev=2, |
| 549 | + middle_band_column_result_column='bollinger_middle', |
| 550 | + upper_band_column_result_column='bollinger_upper', |
| 551 | + lower_band_column_result_column='bollinger_lower' |
| 552 | +) -> Union[PdDataFrame, PlDataFrame]: |
| 553 | +``` |
| 554 | + |
| 555 | +Example |
| 556 | + |
| 557 | +```python |
| 558 | +from investing_algorithm_framework import download |
| 559 | + |
| 560 | +from pyindicators import ema |
| 561 | + |
| 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 bollinger bands for Polars DataFrame |
| 583 | +pl_df = bollinger_bands(pl_df, source_column="Close") |
| 584 | +pl_df.show(10) |
| 585 | + |
| 586 | +# Calculate bollinger bands for Pandas DataFrame |
| 587 | +pd_df = bollinger_bands(pd_df, source_column="Close") |
| 588 | +pd_df.tail(10) |
| 589 | +``` |
| 590 | + |
| 591 | + |
| 592 | + |
| 593 | +#### Average True Range (ATR) |
| 594 | + |
| 595 | +The Average True Range (ATR) is a volatility indicator that measures the average range between the high and low prices over a specified period. It helps traders identify potential price fluctuations and adjust their strategies accordingly. |
| 596 | + |
| 597 | +```python |
| 598 | +def atr( |
| 599 | + data: Union[PdDataFrame, PlDataFrame], |
| 600 | + source_column="Close", |
| 601 | + period=14, |
| 602 | + result_column="ATR" |
| 603 | +) -> Union[PdDataFrame, PlDataFrame]: |
| 604 | +``` |
| 605 | + |
| 606 | +Example |
| 607 | + |
| 608 | +```python |
| 609 | +from investing_algorithm_framework import download |
| 610 | + |
| 611 | +from pyindicators import ema |
| 612 | + |
| 613 | +pl_df = download( |
| 614 | + symbol="btc/eur", |
| 615 | + market="binance", |
| 616 | + time_frame="1d", |
| 617 | + start_date="2023-12-01", |
| 618 | + end_date="2023-12-25", |
| 619 | + save=True, |
| 620 | + storage_path="./data" |
| 621 | +) |
| 622 | +pd_df = download( |
| 623 | + symbol="btc/eur", |
| 624 | + market="binance", |
| 625 | + time_frame="1d", |
| 626 | + start_date="2023-12-01", |
| 627 | + end_date="2023-12-25", |
| 628 | + pandas=True, |
| 629 | + save=True, |
| 630 | + storage_path="./data" |
| 631 | +) |
| 632 | + |
| 633 | +# Calculate average true range for Polars DataFrame |
| 634 | +pl_df = atr(pl_df, source_column="Close") |
| 635 | +pl_df.show(10) |
| 636 | + |
| 637 | +# Calculate average true range for Pandas DataFrame |
| 638 | +pd_df = atr(pd_df, source_column="Close") |
| 639 | +pd_df.tail(10) |
| 640 | +``` |
| 641 | + |
| 642 | + |
| 643 | + |
| 644 | + |
531 | 645 | ### Pattern Recognition |
532 | 646 |
|
533 | 647 | #### Detect Peaks |
|
0 commit comments