Zum Inhalt springen
← Zurück zu den Projekten

Polars Ta Classic

#polars-ta-classic

Crates.io docs.rs License: MIT

A pure-Rust reimplementation of pandas-ta-classic built on Polars 0.46.

212 total indicators and patterns:

  • 150 technical-analysis indicators across 9 categories
  • 62 TA-Lib candlestick patterns

No Python. No C ta-lib shared-library dependency. No GIL. Just Rust.


#Installation

[dependencies]
polars-ta-classic = "0.1"
polars = "0.46"

Or with Cargo:

cargo add polars-ta-classic

#Quick Start

#RSI

use polars::prelude::*;
use polars_ta_classic::momentum::rsi::rsi;

let close = Series::new("close".into(), vec![
    44.34, 44.09, 44.15, 43.61, 44.33, 44.83, 45.10, 45.15,
    43.61, 44.33, 44.83, 45.10, 45.15, 43.61, 44.83,
]);

let rsi_14 = rsi(&close, 14)?;
// Returns a Series named "RSI_14" with leading nulls for the warm-up period.

#MACD

use polars_ta_classic::momentum::macd::macd;

let result = macd(&close, 12, 26, 9)?;
// result.macd      -> Series "MACD_12_26_9"
// result.signal    -> Series "MACDs_12_26_9"
// result.histogram -> Series "MACDh_12_26_9"

#Bollinger Bands

use polars_ta_classic::volatility::bbands::{bbands, BbandsConfig};

let cfg = BbandsConfig { length: 20, std_dev: 2.0 };
let bb = bbands(&close, &cfg)?;
// bb.lower, bb.mid, bb.upper  (Series)
// bb.bandwidth, bb.percent    (Series)

#SuperTrend

use polars_ta_classic::overlap::supertrend::supertrend;

let result = supertrend(&high, &low, &close, 7, 3.0)?;
// result.trend     -> trend line (lower band in uptrend, upper band in downtrend)
// result.direction -> +1 uptrend, -1 downtrend
// result.long      -> trend value when in uptrend, else NaN
// result.short     -> trend value when in downtrend, else NaN

#Ichimoku

use polars_ta_classic::overlap::ichimoku::ichimoku;

let result = ichimoku(&high, &low, &close, 9, 26, 52)?;
// result.tenkan_sen    -> conversion line
// result.kijun_sen     -> base line
// result.senkou_span_a -> leading span A
// result.senkou_span_b -> leading span B
// result.chikou_span   -> lagging span

#API Design Philosophy

  • Series in, Series out. Single-output indicators accept &Series and return TaResult<Series>.
  • Named result structs for multi-output indicators. MacdResult, BbandsResult, SupertrendResult, IchimokuResult, etc. expose each output series as a named field — no positional guessing.
  • Null-safe leading nulls instead of panics. The warm-up period is represented as None values rather than filling with zeros or panicking on insufficient data.
  • No allocating intermediate DataFrames. Indicator functions work directly on Series slices and Vec<Option<f64>> — no hidden DataFrame allocation.
  • Idiomatic Rust error handling. All functions return TaResult<T> (Result<T, TaError>). TaError has variants for Polars errors, insufficient data, and invalid parameters.

#Comparison with pandas-ta-classic

Aspect pandas-ta-classic polars-ta-classic
Language Python + pandas Rust + Polars 0.46
C dependency Optional ta-lib None
GIL Yes No
Formulas & defaults Source Identical
Type safety Runtime Compile-time
Null handling NaN floats Option<f64>
Multi-output Unnamed columns Named structs

The formulas and default parameters are a 1-to-1 match with pandas-ta-classic. Results match to floating-point precision for the same input series.


#Indicator Reference

#Overlap (Moving Averages & Price Transforms) — 37 indicators

Function Full Name Key Parameters Return
alma Arnaud Legoux Moving Average length=10, sigma=6.0, offset=0.85 Series
dema Double Exponential Moving Average length=10 Series
ema Exponential Moving Average length=10 Series
fwma Fibonacci Weighted Moving Average length=10 Series
hilo Gann High-Low Activator high_length=13, low_length=21 HiloResult
hl2 High/Low Midpoint Series
hlc3 Typical Price Series
hma Hull Moving Average length=10 Series
hwma Holt-Winter Moving Average na=0.2, nb=0.1, nc=0.1 Series
ichimoku Ichimoku Kinkō Hyō tenkan=9, kijun=26, senkou=52 IchimokuResult
jma Jurik Moving Average length=7, phase=0 Series
kama Kaufman Adaptive Moving Average length=10, fast=2, slow=30 Series
linreg Linear Regression Moving Average length=14 Series
ma Generic MA Dispatcher length=10, mamode="ema" Series
mcgd McGinley Dynamic length=10, c=1.0 Series
midpoint Midpoint length=2 Series
midprice Midpoint Price Over Period length=2 Series
mmar Modified Moving Average Ribbon length=4 Series
ohlc4 OHLC4 Average Series
psar Parabolic SAR af0=0.02, af_max=0.20 PsarResult
pwma Pascal's Triangle Weighted MA length=10 Series
rainbow Rainbow Moving Average length=2, nb=10 Series
rma Wilder's Smoothed MA length=10 Series
sinwma Sine Weighted Moving Average length=14 Series
sma Simple Moving Average length=10 Series
ssf Ehlers Super Smoother Filter length=10, poles=2 Series
supertrend Supertrend length=7, multiplier=3.0 SupertrendResult
swma Symmetric Weighted Moving Average length=4 Series
t3 Tillson T3 Moving Average length=10, a=0.7 Series
tema Triple Exponential Moving Average length=10 Series
trima Triangular Moving Average length=10 Series
vidya Variable Index Dynamic Average length=14 Series
vwma Volume Weighted Moving Average length=10 Series
wcp Weighted Close Price Series
wma Weighted Moving Average length=10 Series
zlma Zero-Lag Moving Average length=10 Series

#Momentum — 45 indicators

Function Full Name Key Parameters Return
ao Awesome Oscillator fast=5, slow=34 Series
apo Absolute Price Oscillator fast=12, slow=26 Series
bias Bias (close vs MA) length=26, mamode="sma" Series
bop Balance of Power Series
brar Bull/Bear Ratio length=26 (Series, Series)
cci Commodity Channel Index length=14, c=0.015 Series
cfo Chande Forecast Oscillator length=9 Series
cg Center of Gravity length=10 Series
cmo Chande Momentum Oscillator length=14 Series
coppock Coppock Curve length=10, fast=11, slow=14 Series
cti Correlation Trend Indicator length=12 Series
dm Directional Movement length=14 DmResult
dpo Detrended Price Oscillator length=20 Series
er Efficiency Ratio length=10 Series
eri Elder Ray Index length=13 (Series, Series)
fisher Fisher Transform length=9, signal=1 (Series, Series)
inertia Inertia length=20, rvi_length=14 Series
kdj KDJ Indicator length=9, signal=3 (Series, Series, Series)
kst Know Sure Thing roc1-4, sma1-4, signal=9 (Series, Series)
lrsi Laguerre RSI length=14, gamma=0.5 Series
macd MACD fast=12, slow=26, signal=9 MacdResult
mom Momentum length=10 Series
pgo Pretty Good Oscillator length=14 Series
po Projection Oscillator length=14 Series
ppo Percentage Price Oscillator fast=12, slow=26, signal=9 PpoResult
psl Psychological Line length=12 Series
pvo Percentage Volume Oscillator fast=12, slow=26, signal=9 PvoResult
qqe Quantitative Qualitative Estimation length=14, smooth=5, factor=4.236 (Series, Series, Series)
roc Rate of Change length=10 Series
rsi Relative Strength Index length=14 Series
rsx Relative Strength Xtra length=14 Series
rvgi Relative Vigor Index length=14, swma_length=4 (Series, Series)
slope Linear Regression Slope length=1 Series
smi Stochastic Momentum Index fast=5, slow=20, signal=5 (Series, Series)
squeeze TTM Squeeze bb_length=20, bb_std=2.0, kc_length=20, kc_scalar=1.5 Series
squeeze_pro TTM Squeeze PRO bb_length=20, bb_std=2.0, kc_length=20, kc_scalar_{wide,normal,narrow} Series
stc Schaff Trend Cycle tclength=10, fast=12, slow=26, factor=0.5 (Series, Series, Series)
stoch Stochastic Oscillator k=14, d=3, smooth_k=3 (Series, Series)
stochrsi Stochastic RSI length=14, rsi_length=14, k=3, d=3 (Series, Series)
td_seq TD Sequential (simplified) length=4 Series
trix Triple EMA Rate-of-Change length=18, signal=9 (Series, Series)
trixh TRIX Histogram length=18, signal=9, scalar=100 TrixhResult
tsi True Strength Index fast=13, slow=25, signal=13 (Series, Series)
uo Ultimate Oscillator fast=7, medium=14, slow=28 Series
vwmacd Volume-Weighted MACD fast=12, slow=26, signal=9 MacdResult
willr Williams %R length=14 Series

#Trend — 18 indicators

Function Full Name Key Parameters Return
adx Average Directional Index length=14, scalar=100 (Series, Series, Series)
amat Archer Moving Averages Trends fast=8, slow=21, lookback=2 AmatResult
aroon Aroon Oscillator length=25 AroonResult
chop Choppiness Index length=14 Series
cksp Chande Kroll Stop p=10, q=1.0, x=9 CkspResult
decay Decay (linear/exponential) length=5, mode="linear" Series
decreasing Decreasing length=1 Series
increasing Increasing length=1 Series
long_run Long Run fast=2, slow=10, length=2 Series
pmax PMAX length=10, multiplier=3.0, mamode="ema" Series
qstick Q-Stick length=10 Series
rwi Random Walk Index length=14 RwiResult
short_run Short Run fast=2, slow=10, length=2 Series
tsignals Trend Signals TsignalsResult
ttm_trend TTM Trend length=6 Series
vhf Vertical Horizontal Filter length=28 Series
vortex Vortex Indicator length=14 VortexResult
xsignals Crossover Signals XsignalsResult

#Volatility — 14 indicators

Function Full Name Key Parameters Return
aberration Aberration length=5, atr_length=15 (Series, Series)
accbands Acceleration Bands length=20, c=4.0 AccbandsResult
atr Average True Range length=14 Series
bbands Bollinger Bands length=5, std_dev=2.0 BbandsResult
donchian Donchian Channel lower_length=20, upper_length=20 DonchianResult
hwc Holt-Winter Channel na=0.2, nb=0.1, nc=0.1, scalar=1.0 HwcResult
kc Keltner Channel length=20, scalar=2.0 KcResult
massi Mass Index fast=9, slow=25 Series
natr Normalized ATR length=14 Series
pdist Periodic Distribution Series
rvi Relative Volatility Index length=14, scalar=100 Series
thermo Ehlers Thermal Cycle length=20, multiplier=2.0 (Series, Series)
true_range True Range Series
ui Ulcer Index length=14 Series

#Volume — 17 indicators

Function Full Name Key Parameters Return
ad Accumulation/Distribution Line Series
adosc A/D Oscillator fast=3, slow=10 Series
aobv Archer OBV fast=4, slow=12 AobvResult
cmf Chaikin Money Flow length=20 Series
efi Elder Force Index length=13 Series
eom Ease of Movement length=14, divisor=100_000_000 Series
kvo Klinger Volume Oscillator fast=34, slow=55, signal=13 Series
mfi Money Flow Index length=14 Series
nvi Negative Volume Index initial=1000.0 Series
obv On Balance Volume Series
pvi Positive Volume Index initial=1000.0 Series
pvol Price Volume Series
pvr Price Volume Rank Series
pvt Price Volume Trend Series
vfi Volume Flow Indicator length=130, coef=0.2, vcoef=2.5 Series
vp Volume Profile width=10 VpResult
vwap Volume Weighted Average Price Series
wb_tsv Williams Balance of Power / TSV Series

#Statistics — 10 indicators

Function Full Name Key Parameters Return
entropy Shannon Entropy length=10, base=2.0 Series
kurtosis Rolling Excess Kurtosis length=30 Series
mad Mean Absolute Deviation length=30 Series
median Rolling Median length=30 Series
quantile Rolling Quantile length=30, q=0.5 Series
skew Rolling Skewness length=30 Series
stdev Rolling Standard Deviation length=30 Series
tos_stdevall ThinkOrSwim StdevAll length=30 TosStdevAllResult
variance Rolling Variance length=30 Series
zscore Rolling Z-Score length=30 Series

#Candles — 5 indicators + 62 patterns

Function Full Name Key Parameters Return
cdl_doji Doji factor=0.1 Series
cdl_inside Inside Bar Series
cdl_pattern Pattern Dispatcher (by name) name: &str Series
cdl_z Candlestick Z-Score Anomaly length=30 Series
ha Heikin-Ashi HaResult

All pattern functions return Series of i32: 100 = bullish, -100 = bearish, 0 = no pattern.

#TA-Lib Candlestick Patterns (62)

Function Pattern Name
cdl_hammer Hammer
cdl_hangingman Hanging Man
cdl_invertedhammer Inverted Hammer
cdl_shootingstar Shooting Star
cdl_marubozu Marubozu
cdl_closingmarubozu Closing Marubozu
cdl_dojistar Doji Star
cdl_dragonflydoji Dragonfly Doji
cdl_gravestonedoji Gravestone Doji
cdl_longleggeddoji Long-Legged Doji
cdl_rickshawman Rickshaw Man
cdl_spinningtop Spinning Top
cdl_highwave High-Wave Candle
cdl_longline Long Line Candle
cdl_shortline Short Line Candle
cdl_belthold Belt-hold
cdl_takuri Takuri (Dragonfly with long lower shadow)
cdl_engulfing Engulfing
cdl_harami Harami
cdl_haramicross Harami Cross
cdl_darkcloudcover Dark Cloud Cover
cdl_piercing Piercing Line
cdl_counterattack Counterattack
cdl_separatinglines Separating Lines
cdl_inneck In-Neck Pattern
cdl_onneck On-Neck Pattern
cdl_thrusting Thrusting Pattern
cdl_matchinglow Matching Low
cdl_homingpigeon Homing Pigeon
cdl_kicking Kicking
cdl_kickingbylength Kicking by Length
cdl_sticksandwich Stick Sandwich
cdl_upsidegap2crows Upside Gap Two Crows
cdl_tasukigap Tasuki Gap
cdl_2crows Two Crows
cdl_3inside Three Inside Up/Down
cdl_3outside Three Outside Up/Down
cdl_3blackcrows Three Black Crows
cdl_3whitesoldiers Three White Soldiers
cdl_3linestrike Three-Line Strike
cdl_morningstar Morning Star
cdl_eveningstar Evening Star
cdl_morningdojistar Morning Doji Star
cdl_eveningdojistar Evening Doji Star
cdl_abandondbaby Abandoned Baby
cdl_tristar Tristar Pattern
cdl_3starsinsouth Three Stars in the South
cdl_identical3crows Identical Three Crows
cdl_advanceblock Advance Block
cdl_stalledpattern Stalled Pattern
cdl_ladderbottom Ladder Bottom
cdl_risefall3methods Rising/Falling Three Methods
cdl_mathold Mat Hold
cdl_unique3river Unique Three-River Bottom
cdl_breakaway Breakaway
cdl_concealbabyswall Concealing Baby Swallow
cdl_xsidegap3methods Upside/Downside Gap Three Methods
cdl_gapsidesidewhite Gap Side-by-Side White Lines
cdl_hikkake Hikkake Pattern
cdl_hikkakemod Modified Hikkake Pattern

#Performance — 4 indicators

Function Full Name Key Parameters Return
log_return Log Return length=1 Series
pct_return Percentage Return length=1 Series
cum_log_return Cumulative Log Return length=1 Series
drawdown Drawdown DrawdownResult

#Cycles — 3 indicators

Function Full Name Key Parameters Return
dsp Detrended Synthetic Price length=14 Series
ebsw Even Better Sinewave (Ehlers) hp_length=40, ld_length=10 Series
reflex Ehlers Reflex length=20 Series

#Error Handling

use polars_ta_classic::{TaError, TaResult};

match rsi(&close, 14) {
    Ok(series) => println!("RSI: {:?}", series),
    Err(TaError::InsufficientData { need, got }) => {
        eprintln!("Need {need} rows, got {got}");
    }
    Err(TaError::InvalidParameter(msg)) => {
        eprintln!("Bad parameter: {msg}");
    }
    Err(TaError::Polars(e)) => eprintln!("Polars error: {e}"),
}

#Contributing

Pull requests are welcome. When contributing a new indicator or fixing a formula:

  1. Match the formula and default parameters from pandas-ta-classic exactly.
  2. Add at least one test that checks the output name and at least one value against a known reference.
  3. Add a module-level doc comment (//!) with the indicator name, formula, and defaults.
  4. All 325 existing tests must continue to pass (cargo test).

#License

MIT — see LICENSE.

Neue Version verfügbar.