Using Functions¶
The mintalib.functions module is the simplest interface, providing plain calculation functions.
Functions are named in lower case (e.g. sma, ema, macd). Some names like abs, min, max, sum shadow Python builtins, so it is best to import the module with a short alias rather than importing names directly.
Functions take either a single series or separate price columns like open, high, low, close, volume. Inputs can be pandas/polars series or numpy arrays.
import mintalib.functions as ta
from mintalib.samples import sample_prices
prices = sample_prices()
prices
| open | high | low | close | volume | |
|---|---|---|---|---|---|
| date | |||||
| 1980-12-12 | 0.098207 | 0.098634 | 0.098207 | 0.098207 | 469033600 |
| 1980-12-15 | 0.093510 | 0.093510 | 0.093083 | 0.093083 | 175884800 |
| 1980-12-16 | 0.086678 | 0.086678 | 0.086251 | 0.086251 | 105728000 |
| 1980-12-17 | 0.088386 | 0.088813 | 0.088386 | 0.088386 | 86441600 |
| 1980-12-18 | 0.090949 | 0.091376 | 0.090949 | 0.090949 | 73449600 |
| ... | ... | ... | ... | ... | ... |
| 2026-07-31 | 304.809998 | 310.690002 | 300.000000 | 308.910004 | 132489100 |
| 2026-08-03 | 309.579987 | 311.799988 | 302.559998 | 303.420013 | 75052000 |
| 2026-08-04 | 302.730011 | 310.420013 | 301.320007 | 309.380005 | 68001000 |
| 2026-08-05 | 309.359985 | 311.709991 | 305.670013 | 311.000000 | 49178700 |
| 2026-08-06 | 314.339996 | 316.289398 | 313.489990 | 314.260010 | 7165536 |
11504 rows × 5 columns
Series Functions¶
Series functions take a single series as first argument.
ta.sma(prices["close"], period=20)
date
1980-12-12 NaN
1980-12-15 NaN
1980-12-16 NaN
1980-12-17 NaN
1980-12-18 NaN
...
2026-07-31 324.3670
2026-08-03 323.9050
2026-08-04 323.8410
2026-08-05 323.7215
2026-08-06 323.6235
Length: 11504, dtype: float64
Multi Input Functions¶
Multi-input functions take their column data as separate positional arguments
ta.atr(prices['high'], prices['low'], prices['close'], period=14)
date
1980-12-12 NaN
1980-12-15 NaN
1980-12-16 NaN
1980-12-17 NaN
1980-12-18 NaN
...
2026-07-31 9.872007
2026-08-03 9.826863
2026-08-04 9.774945
2026-08-05 9.508161
2026-08-06 9.206821
Length: 11504, dtype: float64
Multi Output Functions¶
Multi-output functions like macd return a DataFrame (a named tuple at the core level):
ta.macd(prices["close"], 12, 26, 9)
| macd | macdsignal | macdhist | |
|---|---|---|---|
| date | |||
| 1980-12-12 | NaN | NaN | NaN |
| 1980-12-15 | NaN | NaN | NaN |
| 1980-12-16 | NaN | NaN | NaN |
| 1980-12-17 | NaN | NaN | NaN |
| 1980-12-18 | NaN | NaN | NaN |
| ... | ... | ... | ... |
| 2026-07-31 | 6.894136 | 8.260785 | -1.366649 |
| 2026-08-03 | 4.536518 | 7.515932 | -2.979414 |
| 2026-08-04 | 3.113124 | 6.635370 | -3.522246 |
| 2026-08-05 | 2.091683 | 5.726633 | -3.634950 |
| 2026-08-06 | 1.527629 | 4.886832 | -3.359203 |
11504 rows × 3 columns
Polars Backend¶
Results come back in the same backend as the input: pandas in → pandas out (index preserved), polars in → polars out (with NaN converted to null), numpy in → numpy out.
polars_prices = sample_prices(backend="polars")
ta.macd(polars_prices["close"])
| macd | macdsignal | macdhist |
|---|---|---|
| f64 | f64 | f64 |
| null | null | null |
| null | null | null |
| null | null | null |
| null | null | null |
| null | null | null |
| … | … | … |
| 6.894136 | 8.260785 | -1.366649 |
| 4.536518 | 7.515932 | -2.979414 |
| 3.113124 | 6.63537 | -3.522246 |
| 2.091683 | 5.726633 | -3.63495 |
| 1.527629 | 4.886832 | -3.359203 |