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.
The first parameter is either prices (a pandas/polars DataFrame with columns open, high, low, close, volume — all lower case, see mintalib.utils.normalize_prices to fix capitalization) or series (a pandas/polars series or numpy array).
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.098298 | 0.098725 | 0.098298 | 0.098298 | 469033600 |
| 1980-12-15 | 0.093597 | 0.093597 | 0.093169 | 0.093169 | 175884800 |
| 1980-12-16 | 0.086758 | 0.086758 | 0.086331 | 0.086331 | 105728000 |
| 1980-12-17 | 0.088468 | 0.088895 | 0.088468 | 0.088468 | 86441600 |
| 1980-12-18 | 0.091032 | 0.091460 | 0.091032 | 0.091032 | 73449600 |
| ... | ... | ... | ... | ... | ... |
| 2026-04-20 | 270.329987 | 274.279999 | 270.290009 | 273.049988 | 36590200 |
| 2026-04-21 | 271.500000 | 272.799988 | 265.399994 | 266.170013 | 50209800 |
| 2026-04-22 | 267.820007 | 273.739990 | 266.869995 | 273.170013 | 43249200 |
| 2026-04-23 | 275.049988 | 275.769989 | 271.649994 | 273.429993 | 33399600 |
| 2026-04-24 | 272.760010 | 273.059998 | 269.649994 | 271.059998 | 38124500 |
11433 rows × 5 columns
Series Functions¶
Series functions take a single series as first argument — select the column explicitly. Passing a DataFrame to a series function raises a TypeError: there is no implicit close selection.
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-04-20 257.638998
2026-04-21 258.372999
2026-04-22 259.449500
2026-04-23 260.489999
2026-04-24 261.398499
Length: 11433, dtype: float64
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-04-20 | 2.872127 | 0.764249 | 2.107878 |
| 2026-04-21 | 2.926444 | 1.196688 | 1.729756 |
| 2026-04-22 | 3.494055 | 1.656161 | 1.837893 |
| 2026-04-23 | 3.919685 | 2.108866 | 1.810819 |
| 2026-04-24 | 4.019427 | 2.490978 | 1.528449 |
11433 rows × 3 columns
Prices Functions¶
Prices functions take the full prices DataFrame:
ta.atr(prices, 14)
date
1980-12-12 NaN
1980-12-15 NaN
1980-12-16 NaN
1980-12-17 NaN
1980-12-18 NaN
...
2026-04-20 5.964207
2026-04-21 6.084621
2026-04-22 6.190717
2026-04-23 6.042809
2026-04-24 5.881179
Length: 11433, dtype: float64
Backends¶
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 |
| … | … | … |
| 2.872127 | 0.764249 | 2.107878 |
| 2.926444 | 1.196688 | 1.729756 |
| 3.494055 | 1.656161 | 1.837893 |
| 3.919685 | 2.108866 | 1.810819 |
| 4.019427 | 2.490978 | 1.528449 |