|
| 1 | +# PyIndicators |
| 2 | + |
| 3 | +PyIndicators is a powerful and user-friendly Python library for technical analysis indicators and metrics. Written entirely in Python, it requires no external dependencies, ensuring seamless integration and ease of use. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +* Native Python implementation |
| 8 | +* Supports both pandas dataframes and polars dataframes |
| 9 | + |
| 10 | +## Indicators |
| 11 | + |
| 12 | +### Trend Indicators |
| 13 | + |
| 14 | +#### Simple Moving Average (SMA) |
| 15 | + |
| 16 | +```python |
| 17 | +from polars import DataFrame as plDataFrame |
| 18 | +from pandas import DataFrame as pdDataFrame |
| 19 | + |
| 20 | +from pyindicators import sma |
| 21 | + |
| 22 | +# Polars DataFrame |
| 23 | +pl_df = plDataFrame({"close": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]}) |
| 24 | + |
| 25 | +# Pandas DataFrame |
| 26 | +pd_df = pdDataFrame({"close": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]}) |
| 27 | + |
| 28 | +# Calculate SMA for Polars DataFrame |
| 29 | +pl_df = sma(pl_df, "close", 3) |
| 30 | +pl_df.show(10) |
| 31 | + |
| 32 | +# Calculate SMA for Pandas DataFrame |
| 33 | +pd_df = sma(pd_df, "close", 3) |
| 34 | +print(pd_df) |
| 35 | +``` |
| 36 | + |
| 37 | +#### Exponential Moving Average (EMA) |
| 38 | + |
| 39 | +```python |
| 40 | +from polars import DataFrame as plDataFrame |
| 41 | +from pandas import DataFrame as pdDataFrame |
| 42 | + |
| 43 | +from pyindicators import ema |
| 44 | + |
| 45 | +# Polars DataFrame |
| 46 | +pl_df = plDataFrame({"close": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]}) |
| 47 | +# Pandas DataFrame |
| 48 | +pd_df = pdDataFrame({"close": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]}) |
| 49 | + |
| 50 | +# Calculate EMA for Polars DataFrame |
| 51 | +pl_df = ema(pl_df, "close", 3) |
| 52 | +pl_df.show(10) |
| 53 | + |
| 54 | +# Calculate EMA for Pandas DataFrame |
| 55 | +pd_df = ema(pd_df, "close", 3) |
| 56 | +print(pd_df) |
| 57 | +``` |
| 58 | + |
| 59 | +### Momentum Indicators |
| 60 | + |
| 61 | +#### Relative Strength Index (RSI) |
| 62 | + |
| 63 | +```python |
| 64 | +from polars import DataFrame as plDataFrame |
| 65 | +from pandas import DataFrame as pdDataFrame |
| 66 | + |
| 67 | +from pyindicators import rsi |
| 68 | + |
| 69 | +# Polars DataFrame |
| 70 | +pl_df = plDataFrame({"close": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]}) |
| 71 | +# Pandas DataFrame |
| 72 | +pd_df = pdDataFrame({"close": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]}) |
| 73 | + |
| 74 | +# Calculate RSI for Polars DataFrame |
| 75 | +pl_df = rsi(pl_df, "close", 14) |
| 76 | +pl_df.show(10) |
| 77 | + |
| 78 | +# Calculate RSI for Pandas DataFrame |
| 79 | +pd_df = rsi(pd_df, "close", 14) |
| 80 | +print(pd_df) |
| 81 | +``` |
0 commit comments