Technical Analysis#

This library provides technical analysis functions for the Polars DataFrame API.

Financial Disclaimer#

The indicators and outputs generated by this library do NOT constitute financial, investment, trading, or professional advice. They are for educational and informational purposes only.

Users should perform independent analysis, validate results, and consult a licensed financial professional before making investment decisions.

The authors assume no liability for losses or damages arising from the use of this software.

class polars_extensions.technical_analysis.TechnicalAnalysisNamespace(df: DataFrame)[source]#

Bases: object

Methods

ao(high, low[, short, long])

Awesome Oscillator (AO).

atr(high, low, close[, window])

Average True Range (ATR).

bollinger(col[, window, num_std])

Bollinger Bands (mid, upper, lower).

bop(open, high, low, close)

Balance of Power (BOP).

cci(high, low, close[, window])

Commodity Channel Index (CCI).

chop(high, low, close[, window])

Choppiness Index (CHOP).

compare(col, value[, op])

Compare column values to a scalar with operators: le, ge, lt, gt, eq, ne.

coppock(col[, long_period, short_period, ...])

Coppock Curve indicator.

cti(col[, window])

Correlation Trend Indicator (CTI).

delta(col[, periods])

Difference between current value and value N periods ago.

dma(col[, short_window, long_window])

Difference of Moving Averages (DMA): short SMA minus long SMA.

dmi(high, low, close[, window])

Directional Movement Index (DMI) with +DI, -DI, ADX, ADXR.

ema(col, span)

Exponential Moving Average (EMA).

eri(high, low, close[, window])

Elder-Ray Index (ERI): Bull Power and Bear Power.

fisher_transform(col[, window])

Gaussian Fisher Transform (FTR).

ichimoku(high, low, close[, tenkan, kijun, ...])

Ichimoku Cloud indicator: Tenkan-sen, Kijun-sen, Senkou Span A/B, Chikou Span.

kama(col[, window, fast, slow])

Kaufman Adaptive Moving Average (KAMA).

kdj(high, low, close[, window, k_smooth, ...])

KDJ Stochastic Oscillator.

log_return(col[, periods])

Log return: ln(current / previous N-period value)

lrma(col[, window])

Linear Regression Moving Average (LRMA).

macd(col[, fast, slow, signal])

MACD (Moving Average Convergence Divergence).

mad(col, window)

Mean Absolute Deviation over rolling window.

mstd(col, window)

Moving Standard Deviation.

mvar(col, window)

Moving Variance.

ppo(col[, fast, slow, signal])

Percentage Price Oscillator (PPO).

qqe(rsi_col[, window, smooth])

Quantitative Qualitative Estimation (QQE) indicator.

roc(col[, periods])

Rate of Change (ROC) momentum indicator.

rsi(col[, window])

Relative Strength Index (RSI).

sma(col, window)

Simple Moving Average (SMA).

stoch_rsi(col[, window])

Stochastic RSI.

supertrend(high, low, close[, period, ...])

Supertrend indicator with Upper Band and Lower Band.

tema(col[, span])

Triple Exponential Moving Average (TEMA).

tr(high, low, close)

True Range (TR).

trix(col[, window])

Triple Exponential Moving Average (TRIX).

wr(high, low, close[, window])

Williams %R Overbought/Oversold indicator.

zscore(col, window)

Z-score normalized column over rolling window.

ao(
high: str,
low: str,
short: int = 5,
long: int = 34,
) DataFrame[source]#

Awesome Oscillator (AO).

Parameters:
highstr

High price column.

lowstr

Low price column.

shortint, default 5

Short-term SMA.

longint, default 34

Long-term SMA.

Returns:
DataFrame with column: ao_<short>_<long>
atr(
high: str,
low: str,
close: str,
window: int = 14,
) DataFrame[source]#

Average True Range (ATR).

bollinger(
col: str,
window: int = 20,
num_std: float = 2.0,
) DataFrame[source]#

Bollinger Bands (mid, upper, lower).

bop(
open: str,
high: str,
low: str,
close: str,
) DataFrame[source]#

Balance of Power (BOP).

Parameters:
open_str

Open price column.

highstr

High price column.

lowstr

Low price column.

closestr

Close price column.

Returns:
DataFrame with column: bop
cci(
high: str,
low: str,
close: str,
window: int = 20,
) DataFrame[source]#

Commodity Channel Index (CCI).

Parameters:
highstr

High price column.

lowstr

Low price column.

closestr

Close price column.

windowint, default 20

Rolling window for calculation.

Returns:
DataFrame with column: <col>_cci_<window>
chop(
high: str,
low: str,
close: str,
window: int = 14,
) DataFrame[source]#

Choppiness Index (CHOP).

compare(
col: str,
value: float,
op: str = 'ge',
) DataFrame[source]#

Compare column values to a scalar with operators: le, ge, lt, gt, eq, ne.

Returns <col>_<op>_<value>

coppock(
col: str,
long_period: int = 14,
short_period: int = 11,
wma_period: int = 10,
) DataFrame[source]#

Coppock Curve indicator.

Parameters:
colstr

Column to compute Coppock curve.

long_periodint, default 14

Long-term ROC period.

short_periodint, default 11

Short-term ROC period.

wma_periodint, default 10

Smoothing period for WMA.

Returns:
DataFrame with column: coppock
cti(
col: str,
window: int = 14,
) DataFrame[source]#

Correlation Trend Indicator (CTI).

Parameters:
colstr

Column to compute CTI on.

windowint, default 14

Rolling window.

Returns:
DataFrame with column: <col>_cti_<window>
delta(
col: str,
periods: int = 1,
) DataFrame[source]#

Difference between current value and value N periods ago.

Returns <col>_delta_<periods>

dma(
col: str,
short_window: int = 10,
long_window: int = 50,
) DataFrame[source]#

Difference of Moving Averages (DMA): short SMA minus long SMA.

Parameters:
colstr

Column to compute DMA on.

short_windowint, default 10

Short period moving average.

long_windowint, default 50

Long period moving average.

Returns:
DataFrame with new column: <col>_dma_<short>_<long>
dmi(
high: str,
low: str,
close: str,
window: int = 14,
) DataFrame[source]#

Directional Movement Index (DMI) with +DI, -DI, ADX, ADXR.

Parameters:
highstr

High price column.

lowstr

Low price column.

closestr

Close price column.

windowint, default 14

Rolling window for smoothing.

Returns:
DataFrame with columns: +DI, -DI, ADX, ADXR
ema(col: str, span: int) DataFrame[source]#

Exponential Moving Average (EMA).

eri(
high: str,
low: str,
close: str,
window: int = 13,
) DataFrame[source]#

Elder-Ray Index (ERI): Bull Power and Bear Power.

Parameters:
highstr

High price column.

lowstr

Low price column.

closestr

Close price column.

windowint, default 13

EMA period.

Returns:
DataFrame with columns: bull_power, bear_power
fisher_transform(
col: str,
window: int = 10,
) DataFrame[source]#

Gaussian Fisher Transform (FTR).

Parameters:
colstr

Column to transform.

windowint, default 10

Lookback period.

Returns:
DataFrame with column: ftr_<window>
ichimoku(
high: str,
low: str,
close: str,
tenkan: int = 9,
kijun: int = 26,
senkou: int = 52,
) DataFrame[source]#

Ichimoku Cloud indicator: Tenkan-sen, Kijun-sen, Senkou Span A/B, Chikou Span.

Parameters:
highstr

High price column.

lowstr

Low price column.

closestr

Close price column.

tenkanint, default 9

Conversion line period.

kijunint, default 26

Base line period.

senkouint, default 52

Leading span B period.

Returns:
DataFrame with columns: tenkan_sen, kijun_sen, senkou_a, senkou_b, chikou_span
kama(
col: str,
window: int = 10,
fast: int = 2,
slow: int = 30,
) DataFrame[source]#

Kaufman Adaptive Moving Average (KAMA).

Parameters:
colstr

Column to compute KAMA on.

windowint, default 10

Efficiency ratio window.

fastint, default 2

Fast EMA period.

slowint, default 30

Slow EMA period.

Returns:
DataFrame with new column: <col>_kama_<window>
kdj(
high: str,
low: str,
close: str,
window: int = 14,
k_smooth: int = 3,
d_smooth: int = 3,
) DataFrame[source]#

KDJ Stochastic Oscillator.

log_return(
col: str,
periods: int = 1,
) DataFrame[source]#

Log return: ln(current / previous N-period value)

Returns <col>_log_return_<periods>

lrma(
col: str,
window: int = 14,
) DataFrame[source]#

Linear Regression Moving Average (LRMA).

Parameters:
colstr

Column to compute LRMA on.

windowint, default 14

Rolling window.

Returns:
DataFrame with column: <col>_lrma_<window>
macd(
col: str,
fast: int = 12,
slow: int = 26,
signal: int = 9,
) DataFrame[source]#

MACD (Moving Average Convergence Divergence).

mad(
col: str,
window: int,
) DataFrame[source]#

Mean Absolute Deviation over rolling window.

mstd(
col: str,
window: int,
) DataFrame[source]#

Moving Standard Deviation.

mvar(
col: str,
window: int,
) DataFrame[source]#

Moving Variance.

ppo(
col: str,
fast: int = 12,
slow: int = 26,
signal: int = 9,
) DataFrame[source]#

Percentage Price Oscillator (PPO).

Parameters:
colstr

Column to calculate PPO.

fastint, default 12

Fast EMA period.

slowint, default 26

Slow EMA period.

signalint, default 9

Signal line EMA period.

Returns:
DataFrame with columns: <col>_ppo, <col>_ppo_signal, <col>_ppo_hist
qqe(
rsi_col: str,
window: int = 14,
smooth: int = 5,
) DataFrame[source]#

Quantitative Qualitative Estimation (QQE) indicator.

Parameters:
rsi_colstr

Column containing RSI values.

windowint, default 14

Smoothing period.

smoothint, default 5

Signal smoothing period.

Returns:
DataFrame with columns: qqe_rsi, qqe_signal
roc(
col: str,
periods: int = 1,
) DataFrame[source]#

Rate of Change (ROC) momentum indicator.

Parameters:
colstr

Column to calculate ROC.

periodsint, default 1

Number of periods for difference.

Returns:
DataFrame with column: <col>_roc_<periods>
rsi(
col: str,
window: int = 14,
) DataFrame[source]#

Relative Strength Index (RSI).

sma(
col: str,
window: int,
) DataFrame[source]#

Simple Moving Average (SMA).

stoch_rsi(
col: str,
window: int = 14,
) DataFrame[source]#

Stochastic RSI.

supertrend(
high: str,
low: str,
close: str,
period: int = 10,
multiplier: float = 3.0,
) DataFrame[source]#

Supertrend indicator with Upper Band and Lower Band.

Parameters:
highstr

High price column.

lowstr

Low price column.

closestr

Close price column.

periodint, default 10

ATR period.

multiplierfloat, default 3.0

ATR multiplier.

Returns:
DataFrame with columns: supertrend, upper_band, lower_band
tema(
col: str,
span: int = 15,
) DataFrame[source]#

Triple Exponential Moving Average (TEMA).

Parameters:
colstr

Column to compute TEMA on.

spanint, default 15

EMA span.

Returns:
DataFrame with new column: <col>_tema_<span>
tr(
high: str,
low: str,
close: str,
) DataFrame[source]#

True Range (TR).

trix(
col: str,
window: int = 15,
) DataFrame[source]#

Triple Exponential Moving Average (TRIX).

Parameters:
colstr

Column to compute TRIX on.

windowint, default 15

EMA span.

Returns:
DataFrame with new column: <col>_trix_<window>
wr(
high: str,
low: str,
close: str,
window: int = 14,
) DataFrame[source]#

Williams %R Overbought/Oversold indicator.

Parameters:
highstr

High price column.

lowstr

Low price column.

closestr

Close price column.

windowint, default 14

Rolling window for calculation.

Returns:
DataFrame with column: wr_<window>
zscore(
col: str,
window: int,
) DataFrame[source]#

Z-score normalized column over rolling window.