Source code for ferro_ta.indicators.momentum

"""
Momentum Indicators — Oscillators measuring speed and change of price movements.

Functions
---------
RSI       — Relative Strength Index
MOM       — Momentum
ROC       — Rate of Change: ((price/prevPrice)-1)*100
ROCP      — Rate of Change Percentage: (price-prevPrice)/prevPrice
ROCR      — Rate of Change Ratio: price/prevPrice
ROCR100   — Rate of Change Ratio 100 scale: (price/prevPrice)*100
WILLR     — Williams' %R
AROON     — Aroon (returns aroon_down, aroon_up)
AROONOSC  — Aroon Oscillator
CCI       — Commodity Channel Index
MFI       — Money Flow Index
BOP       — Balance Of Power
STOCHF    — Stochastic Fast
STOCH     — Stochastic
STOCHRSI  — Stochastic Relative Strength Index
APO       — Absolute Price Oscillator
PPO       — Percentage Price Oscillator
CMO       — Chande Momentum Oscillator
PLUS_DM   — Plus Directional Movement
MINUS_DM  — Minus Directional Movement
PLUS_DI   — Plus Directional Indicator
MINUS_DI  — Minus Directional Indicator
DX        — Directional Movement Index
ADX       — Average Directional Movement Index
ADXR      — Average Directional Movement Index Rating
DMI       — Directional Movement Index (+DI, -DI, ADX)
TRIX      — 1-day Rate-Of-Change of Triple Smooth EMA
ULTOSC    — Ultimate Oscillator
TRANGE    — True Range (also in volatility)
ELDER_RAY — Elder Ray bull / bear power
FISHER    — Ehlers Fisher Transform
CRSI      — Connors RSI
"""

from __future__ import annotations

import numpy as np
from numpy.typing import ArrayLike

from ferro_ta._ferro_ta import (
    adx as _adx,
)
from ferro_ta._ferro_ta import (
    adxr as _adxr,
)
from ferro_ta._ferro_ta import (
    apo as _apo,
)
from ferro_ta._ferro_ta import (
    aroon as _aroon,
)
from ferro_ta._ferro_ta import (
    aroonosc as _aroonosc,
)
from ferro_ta._ferro_ta import (
    bop as _bop,
)
from ferro_ta._ferro_ta import (
    cci as _cci,
)
from ferro_ta._ferro_ta import (
    cmo as _cmo,
)
from ferro_ta._ferro_ta import (
    crsi as _crsi,
)
from ferro_ta._ferro_ta import (
    dmi as _dmi,
)
from ferro_ta._ferro_ta import (
    dx as _dx,
)
from ferro_ta._ferro_ta import (
    elder_ray as _elder_ray,
)
from ferro_ta._ferro_ta import (
    fisher as _fisher,
)
from ferro_ta._ferro_ta import (
    mfi as _mfi,
)
from ferro_ta._ferro_ta import (
    minus_di as _minus_di,
)
from ferro_ta._ferro_ta import (
    minus_dm as _minus_dm,
)
from ferro_ta._ferro_ta import (
    mom as _mom,
)
from ferro_ta._ferro_ta import (
    plus_di as _plus_di,
)
from ferro_ta._ferro_ta import (
    plus_dm as _plus_dm,
)
from ferro_ta._ferro_ta import (
    ppo as _ppo,
)
from ferro_ta._ferro_ta import (
    roc as _roc,
)
from ferro_ta._ferro_ta import (
    rocp as _rocp,
)
from ferro_ta._ferro_ta import (
    rocr as _rocr,
)
from ferro_ta._ferro_ta import (
    rocr100 as _rocr100,
)
from ferro_ta._ferro_ta import (
    rsi as _rsi,
)
from ferro_ta._ferro_ta import (
    stoch as _stoch,
)
from ferro_ta._ferro_ta import (
    stochf as _stochf,
)
from ferro_ta._ferro_ta import (
    stochrsi as _stochrsi,
)
from ferro_ta._ferro_ta import (
    trix as _trix,
)
from ferro_ta._ferro_ta import (
    ultosc as _ultosc,
)
from ferro_ta._ferro_ta import (
    willr as _willr,
)
from ferro_ta._utils import _to_f64, apply_nan_policy
from ferro_ta.core.exceptions import _normalize_rust_error
from ferro_ta.indicators.volatility import TRANGE


[docs] def RSI( close: ArrayLike, timeperiod: int = 14, *, nan_policy: str = "propagate" ) -> np.ndarray: """Relative Strength Index. Parameters ---------- close : array-like Sequence of closing prices. timeperiod : int, optional Number of periods (default 14). nan_policy : {"propagate", "skip"}, optional ``"propagate"`` (default, TA-Lib semantics): a NaN input poisons every later value. ``"skip"``: rows with a non-finite input are dropped, the indicator runs on the remaining rows, and NaN is written back at the dropped rows (matches the streaming classes tick for tick). Returns ------- numpy.ndarray Array of RSI values (0–100); leading ``timeperiod`` entries are ``NaN``. """ try: return apply_nan_policy( lambda c: _rsi(c, timeperiod), (_to_f64(close),), nan_policy ) except ValueError as e: _normalize_rust_error(e)
[docs] def MOM(close: ArrayLike, timeperiod: int = 10) -> np.ndarray: """Momentum. Parameters ---------- close : array-like Sequence of closing prices. timeperiod : int, optional Number of periods (default 10). Returns ------- numpy.ndarray Array of MOM values; leading ``timeperiod`` entries are ``NaN``. """ try: return _mom(_to_f64(close), timeperiod) except ValueError as e: _normalize_rust_error(e)
[docs] def ROC(close: ArrayLike, timeperiod: int = 10) -> np.ndarray: """Rate of Change: ((price/prevPrice)-1)*100. Parameters ---------- close : array-like Sequence of closing prices. timeperiod : int, optional Number of periods (default 10). Returns ------- numpy.ndarray Array of ROC values; leading ``timeperiod`` entries are ``NaN``. """ try: return _roc(_to_f64(close), timeperiod) except ValueError as e: _normalize_rust_error(e)
[docs] def ROCP(close: ArrayLike, timeperiod: int = 10) -> np.ndarray: """Rate of Change Percentage: (price-prevPrice)/prevPrice. Parameters ---------- close : array-like Sequence of closing prices. timeperiod : int, optional Number of periods (default 10). Returns ------- numpy.ndarray Array of ROCP values; leading ``timeperiod`` entries are ``NaN``. """ try: return _rocp(_to_f64(close), timeperiod) except ValueError as e: _normalize_rust_error(e)
[docs] def ROCR(close: ArrayLike, timeperiod: int = 10) -> np.ndarray: """Rate of Change Ratio: price/prevPrice. Parameters ---------- close : array-like Sequence of closing prices. timeperiod : int, optional Number of periods (default 10). Returns ------- numpy.ndarray Array of ROCR values; leading ``timeperiod`` entries are ``NaN``. """ try: return _rocr(_to_f64(close), timeperiod) except ValueError as e: _normalize_rust_error(e)
[docs] def ROCR100(close: ArrayLike, timeperiod: int = 10) -> np.ndarray: """Rate of Change Ratio 100 scale: (price/prevPrice)*100. Parameters ---------- close : array-like Sequence of closing prices. timeperiod : int, optional Number of periods (default 10). Returns ------- numpy.ndarray Array of ROCR100 values; leading ``timeperiod`` entries are ``NaN``. """ try: return _rocr100(_to_f64(close), timeperiod) except ValueError as e: _normalize_rust_error(e)
[docs] def WILLR( high: ArrayLike, low: ArrayLike, close: ArrayLike, timeperiod: int = 14, ) -> np.ndarray: """Williams' %R. Parameters ---------- high : array-like Sequence of high prices. low : array-like Sequence of low prices. close : array-like Sequence of closing prices. timeperiod : int, optional Number of periods (default 14). Returns ------- numpy.ndarray Array of WILLR values (-100 to 0); leading ``timeperiod - 1`` entries are ``NaN``. """ try: return _willr(_to_f64(high), _to_f64(low), _to_f64(close), timeperiod) except ValueError as e: _normalize_rust_error(e)
[docs] def AROON( high: ArrayLike, low: ArrayLike, timeperiod: int = 14, ) -> tuple[np.ndarray, np.ndarray]: """Aroon. Parameters ---------- high : array-like Sequence of high prices. low : array-like Sequence of low prices. timeperiod : int, optional Number of periods (default 14). Returns ------- tuple[numpy.ndarray, numpy.ndarray] ``(aroondown, aroonup)`` — two arrays of equal length. Leading ``timeperiod`` entries are ``NaN``. """ try: return _aroon(_to_f64(high), _to_f64(low), timeperiod) except ValueError as e: _normalize_rust_error(e)
[docs] def AROONOSC( high: ArrayLike, low: ArrayLike, timeperiod: int = 14, ) -> np.ndarray: """Aroon Oscillator. Parameters ---------- high : array-like Sequence of high prices. low : array-like Sequence of low prices. timeperiod : int, optional Number of periods (default 14). Returns ------- numpy.ndarray Array of AROONOSC values; leading ``timeperiod`` entries are ``NaN``. """ try: return _aroonosc(_to_f64(high), _to_f64(low), timeperiod) except ValueError as e: _normalize_rust_error(e)
[docs] def CCI( high: ArrayLike, low: ArrayLike, close: ArrayLike, timeperiod: int = 14, ) -> np.ndarray: """Commodity Channel Index. Parameters ---------- high : array-like Sequence of high prices. low : array-like Sequence of low prices. close : array-like Sequence of closing prices. timeperiod : int, optional Number of periods (default 14). Returns ------- numpy.ndarray Array of CCI values; leading ``timeperiod - 1`` entries are ``NaN``. """ try: return _cci(_to_f64(high), _to_f64(low), _to_f64(close), timeperiod) except ValueError as e: _normalize_rust_error(e)
[docs] def MFI( high: ArrayLike, low: ArrayLike, close: ArrayLike, volume: ArrayLike, timeperiod: int = 14, ) -> np.ndarray: """Money Flow Index. Parameters ---------- high : array-like Sequence of high prices. low : array-like Sequence of low prices. close : array-like Sequence of closing prices. volume : array-like Sequence of volume values. timeperiod : int, optional Number of periods (default 14). Returns ------- numpy.ndarray Array of MFI values (0–100); leading ``timeperiod`` entries are ``NaN``. """ try: return _mfi( _to_f64(high), _to_f64(low), _to_f64(close), _to_f64(volume), timeperiod ) except ValueError as e: _normalize_rust_error(e)
[docs] def BOP( open: ArrayLike, high: ArrayLike, low: ArrayLike, close: ArrayLike, ) -> np.ndarray: """Balance Of Power. Parameters ---------- open : array-like Sequence of open prices. high : array-like Sequence of high prices. low : array-like Sequence of low prices. close : array-like Sequence of closing prices. Returns ------- numpy.ndarray Array of BOP values (-1 to 1). """ try: return _bop(_to_f64(open), _to_f64(high), _to_f64(low), _to_f64(close)) except ValueError as e: _normalize_rust_error(e)
[docs] def STOCHF( high: ArrayLike, low: ArrayLike, close: ArrayLike, fastk_period: int = 5, fastd_period: int = 3, fastd_matype: int = 0, ) -> tuple[np.ndarray, np.ndarray]: """Stochastic Fast. Parameters ---------- high : array-like Sequence of high prices. low : array-like Sequence of low prices. close : array-like Sequence of closing prices. fastk_period : int, optional %K period (default 5). fastd_period : int, optional %D smoothing period (default 3). fastd_matype : int, optional Moving average type applied to the %D leg (default 0): * 0 = SMA (Simple) * 1 = EMA (Exponential) * 2 = WMA (Weighted) * 3 = DEMA (Double EMA) * 4 = TEMA (Triple EMA) * 5 = TRIMA (Triangular) * 6 = KAMA (Kaufman Adaptive) * 7 = T3 (Tillson) * 8 = T3 (Tillson; exact alias of 7) Values ``0``-``6`` and ``8`` match TA-Lib's numbering, but ``7`` is T3 here where TA-Lib's ``7`` is MAMA. MAMA is not reachable through any ``matype`` value -- call :func:`ferro_ta.MAMA` directly. Returns ------- tuple[numpy.ndarray, numpy.ndarray] ``(fastk, fastd)`` — two arrays of equal length. """ try: return _stochf( _to_f64(high), _to_f64(low), _to_f64(close), fastk_period, fastd_period, fastd_matype, ) except ValueError as e: _normalize_rust_error(e)
[docs] def STOCH( high: ArrayLike, low: ArrayLike, close: ArrayLike, fastk_period: int = 5, slowk_period: int = 3, slowk_matype: int = 0, slowd_period: int = 3, slowd_matype: int = 0, *, nan_policy: str = "propagate", ) -> tuple[np.ndarray, np.ndarray]: """Stochastic. Parameters follow TA-Lib's *interleaved* order: each ``*_matype`` comes immediately after the period it types, so a mis-ordered positional call fails the type checker instead of returning a wrong answer. Parameters ---------- high : array-like Sequence of high prices. low : array-like Sequence of low prices. close : array-like Sequence of closing prices. fastk_period : int, optional Fast %K period (default 5). slowk_period : int, optional Slow %K smoothing period (default 3). slowk_matype : int, optional Moving average type applied to the slow %K leg (default 0): * 0 = SMA (Simple) * 1 = EMA (Exponential) * 2 = WMA (Weighted) * 3 = DEMA (Double EMA) * 4 = TEMA (Triple EMA) * 5 = TRIMA (Triangular) * 6 = KAMA (Kaufman Adaptive) * 7 = T3 (Tillson) * 8 = T3 (Tillson; exact alias of 7) Values ``0``-``6`` and ``8`` match TA-Lib's numbering, but ``7`` is T3 here where TA-Lib's ``7`` is MAMA. MAMA is not reachable through any ``matype`` value -- call :func:`ferro_ta.MAMA` directly. slowd_period : int, optional Slow %D smoothing period (default 3). slowd_matype : int, optional Moving average type applied to the slow %D leg (default 0): * 0 = SMA (Simple) * 1 = EMA (Exponential) * 2 = WMA (Weighted) * 3 = DEMA (Double EMA) * 4 = TEMA (Triple EMA) * 5 = TRIMA (Triangular) * 6 = KAMA (Kaufman Adaptive) * 7 = T3 (Tillson) * 8 = T3 (Tillson; exact alias of 7) Values ``0``-``6`` and ``8`` match TA-Lib's numbering, but ``7`` is T3 here where TA-Lib's ``7`` is MAMA. MAMA is not reachable through any ``matype`` value -- call :func:`ferro_ta.MAMA` directly. nan_policy : {"propagate", "skip"}, optional ``"propagate"`` (default, TA-Lib semantics): a NaN input poisons every later value. ``"skip"``: rows with a non-finite input are dropped, the indicator runs on the remaining rows, and NaN is written back at the dropped rows (matches the streaming classes tick for tick). Returns ------- tuple[numpy.ndarray, numpy.ndarray] ``(slowk, slowd)`` — two arrays of equal length. """ try: return apply_nan_policy( lambda hi, lo, cl: _stoch( hi, lo, cl, fastk_period, slowk_period, slowk_matype, slowd_period, slowd_matype, ), (_to_f64(high), _to_f64(low), _to_f64(close)), nan_policy, ) except ValueError as e: _normalize_rust_error(e)
[docs] def STOCHRSI( close: ArrayLike, timeperiod: int = 14, fastk_period: int = 5, fastd_period: int = 3, fastd_matype: int = 0, ) -> tuple[np.ndarray, np.ndarray]: """Stochastic Relative Strength Index. Parameters ---------- close : array-like Sequence of closing prices. timeperiod : int, optional RSI period (default 14). fastk_period : int, optional Stochastic %K period (default 5). fastd_period : int, optional Stochastic %D smoothing period (default 3). fastd_matype : int, optional Moving average type applied to the %D leg (default 0): * 0 = SMA (Simple) * 1 = EMA (Exponential) * 2 = WMA (Weighted) * 3 = DEMA (Double EMA) * 4 = TEMA (Triple EMA) * 5 = TRIMA (Triangular) * 6 = KAMA (Kaufman Adaptive) * 7 = T3 (Tillson) * 8 = T3 (Tillson; exact alias of 7) Values ``0``-``6`` and ``8`` match TA-Lib's numbering, but ``7`` is T3 here where TA-Lib's ``7`` is MAMA. MAMA is not reachable through any ``matype`` value -- call :func:`ferro_ta.MAMA` directly. Returns ------- tuple[numpy.ndarray, numpy.ndarray] ``(fastk, fastd)`` — two arrays of equal length. """ try: return _stochrsi( _to_f64(close), timeperiod, fastk_period, fastd_period, fastd_matype ) except ValueError as e: _normalize_rust_error(e)
[docs] def APO( close: ArrayLike, fastperiod: int = 12, slowperiod: int = 26, matype: int = 1, ) -> np.ndarray: """Absolute Price Oscillator. Parameters ---------- close : array-like Sequence of closing prices. fastperiod : int, optional Fast MA period (default 12). slowperiod : int, optional Slow MA period (default 26). matype : int, optional Moving average type for both legs. Defaults to ``1`` (EMA) rather than TA-Lib's ``0`` (SMA), because this function has always computed the EMA form; pass ``0`` for TA-Lib's SMA form (default 1): * 0 = SMA (Simple) * 1 = EMA (Exponential) * 2 = WMA (Weighted) * 3 = DEMA (Double EMA) * 4 = TEMA (Triple EMA) * 5 = TRIMA (Triangular) * 6 = KAMA (Kaufman Adaptive) * 7 = T3 (Tillson) * 8 = T3 (Tillson; exact alias of 7) Values ``0``-``6`` and ``8`` match TA-Lib's numbering, but ``7`` is T3 here where TA-Lib's ``7`` is MAMA. MAMA is not reachable through any ``matype`` value -- call :func:`ferro_ta.MAMA` directly. Returns ------- numpy.ndarray Array of APO values; leading entries are ``NaN`` for the slow leg's lookback (which depends on *matype*). """ try: return _apo(_to_f64(close), fastperiod, slowperiod, matype) except ValueError as e: _normalize_rust_error(e)
[docs] def PPO( close: ArrayLike, fastperiod: int = 12, slowperiod: int = 26, signalperiod: int = 9, matype: int = 1, ) -> tuple[np.ndarray, np.ndarray, np.ndarray]: """Percentage Price Oscillator. Parameters ---------- close : array-like Sequence of closing prices. fastperiod : int, optional Fast MA period (default 12). slowperiod : int, optional Slow MA period (default 26). signalperiod : int, optional Signal EMA period (default 9). matype : int, optional Moving average type for the fast and slow legs. Defaults to ``1`` (EMA) rather than TA-Lib's ``0`` (SMA), because this function has always computed the EMA form; pass ``0`` for TA-Lib's SMA form (default 1): * 0 = SMA (Simple) * 1 = EMA (Exponential) * 2 = WMA (Weighted) * 3 = DEMA (Double EMA) * 4 = TEMA (Triple EMA) * 5 = TRIMA (Triangular) * 6 = KAMA (Kaufman Adaptive) * 7 = T3 (Tillson) * 8 = T3 (Tillson; exact alias of 7) Values ``0``-``6`` and ``8`` match TA-Lib's numbering, but ``7`` is T3 here where TA-Lib's ``7`` is MAMA. MAMA is not reachable through any ``matype`` value -- call :func:`ferro_ta.MAMA` directly. Returns ------- tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray] ``(ppo, signal, histogram)`` — three arrays of equal length. """ try: return _ppo(_to_f64(close), fastperiod, slowperiod, signalperiod, matype) except ValueError as e: _normalize_rust_error(e)
[docs] def CMO(close: ArrayLike, timeperiod: int = 14) -> np.ndarray: """Chande Momentum Oscillator. Parameters ---------- close : array-like Sequence of closing prices. timeperiod : int, optional Number of periods (default 14). Returns ------- numpy.ndarray Array of CMO values (-100 to 100); leading ``timeperiod`` entries are ``NaN``. """ try: return _cmo(_to_f64(close), timeperiod) except ValueError as e: _normalize_rust_error(e)
[docs] def PLUS_DM(high: ArrayLike, low: ArrayLike, timeperiod: int = 14) -> np.ndarray: """Plus Directional Movement. Parameters ---------- high : array-like Sequence of high prices. low : array-like Sequence of low prices. timeperiod : int, optional Smoothing period (default 14). Returns ------- numpy.ndarray Array of +DM values. """ try: return _plus_dm(_to_f64(high), _to_f64(low), timeperiod) except ValueError as e: _normalize_rust_error(e)
[docs] def MINUS_DM(high: ArrayLike, low: ArrayLike, timeperiod: int = 14) -> np.ndarray: """Minus Directional Movement. Parameters ---------- high : array-like Sequence of high prices. low : array-like Sequence of low prices. timeperiod : int, optional Smoothing period (default 14). Returns ------- numpy.ndarray Array of -DM values. """ try: return _minus_dm(_to_f64(high), _to_f64(low), timeperiod) except ValueError as e: _normalize_rust_error(e)
[docs] def PLUS_DI( high: ArrayLike, low: ArrayLike, close: ArrayLike, timeperiod: int = 14, ) -> np.ndarray: """Plus Directional Indicator. Parameters ---------- high : array-like Sequence of high prices. low : array-like Sequence of low prices. close : array-like Sequence of closing prices. timeperiod : int, optional Smoothing period (default 14). Returns ------- numpy.ndarray Array of +DI values. """ try: return _plus_di(_to_f64(high), _to_f64(low), _to_f64(close), timeperiod) except ValueError as e: _normalize_rust_error(e)
[docs] def MINUS_DI( high: ArrayLike, low: ArrayLike, close: ArrayLike, timeperiod: int = 14, ) -> np.ndarray: """Minus Directional Indicator. Parameters ---------- high : array-like Sequence of high prices. low : array-like Sequence of low prices. close : array-like Sequence of closing prices. timeperiod : int, optional Smoothing period (default 14). Returns ------- numpy.ndarray Array of -DI values. """ try: return _minus_di(_to_f64(high), _to_f64(low), _to_f64(close), timeperiod) except ValueError as e: _normalize_rust_error(e)
[docs] def DX( high: ArrayLike, low: ArrayLike, close: ArrayLike, timeperiod: int = 14, ) -> np.ndarray: """Directional Movement Index. Parameters ---------- high : array-like Sequence of high prices. low : array-like Sequence of low prices. close : array-like Sequence of closing prices. timeperiod : int, optional Smoothing period (default 14). Returns ------- numpy.ndarray Array of DX values (0–100). """ try: return _dx(_to_f64(high), _to_f64(low), _to_f64(close), timeperiod) except ValueError as e: _normalize_rust_error(e)
[docs] def ADX( high: ArrayLike, low: ArrayLike, close: ArrayLike, timeperiod: int = 14, ) -> np.ndarray: """Average Directional Movement Index. Parameters ---------- high : array-like Sequence of high prices. low : array-like Sequence of low prices. close : array-like Sequence of closing prices. timeperiod : int, optional Smoothing period (default 14). Returns ------- numpy.ndarray Array of ADX values (0–100). """ try: return _adx(_to_f64(high), _to_f64(low), _to_f64(close), timeperiod) except ValueError as e: _normalize_rust_error(e)
[docs] def DMI( high: ArrayLike, low: ArrayLike, close: ArrayLike, timeperiod: int = 14, ) -> tuple[np.ndarray, np.ndarray, np.ndarray]: """Directional Movement Index — ``(PLUS_DI, MINUS_DI, ADX)`` in one pass. Parameters ---------- high : array-like Sequence of high prices. low : array-like Sequence of low prices. close : array-like Sequence of closing prices. timeperiod : int, optional Wilder smoothing period (default 14). Returns ------- plus_di, minus_di, adx : numpy.ndarray The three ADX-family series, identical to calling ``PLUS_DI``, ``MINUS_DI``, and ``ADX`` separately. """ try: return _dmi(_to_f64(high), _to_f64(low), _to_f64(close), timeperiod) except ValueError as e: _normalize_rust_error(e)
[docs] def ADXR( high: ArrayLike, low: ArrayLike, close: ArrayLike, timeperiod: int = 14, ) -> np.ndarray: """Average Directional Movement Index Rating. Parameters ---------- high : array-like Sequence of high prices. low : array-like Sequence of low prices. close : array-like Sequence of closing prices. timeperiod : int, optional Smoothing period (default 14). Returns ------- numpy.ndarray Array of ADXR values (0–100). """ try: return _adxr(_to_f64(high), _to_f64(low), _to_f64(close), timeperiod) except ValueError as e: _normalize_rust_error(e)
[docs] def TRIX(close: ArrayLike, timeperiod: int = 30) -> np.ndarray: """1-day Rate-Of-Change of a Triple Smooth EMA. Parameters ---------- close : array-like Sequence of closing prices. timeperiod : int, optional EMA period (default 30). Returns ------- numpy.ndarray Array of TRIX values. """ try: return _trix(_to_f64(close), timeperiod) except ValueError as e: _normalize_rust_error(e)
[docs] def ULTOSC( high: ArrayLike, low: ArrayLike, close: ArrayLike, timeperiod1: int = 7, timeperiod2: int = 14, timeperiod3: int = 28, ) -> np.ndarray: """Ultimate Oscillator. Parameters ---------- high : array-like Sequence of high prices. low : array-like Sequence of low prices. close : array-like Sequence of closing prices. timeperiod1 : int, optional First period (default 7). timeperiod2 : int, optional Second period (default 14). timeperiod3 : int, optional Third period (default 28). Returns ------- numpy.ndarray Array of ULTOSC values (0–100). """ try: return _ultosc( _to_f64(high), _to_f64(low), _to_f64(close), timeperiod1, timeperiod2, timeperiod3, ) except ValueError as e: _normalize_rust_error(e)
[docs] def ELDER_RAY( high: ArrayLike, low: ArrayLike, close: ArrayLike, timeperiod: int = 13, ) -> tuple[np.ndarray, np.ndarray]: """Elder Ray Index — bull power and bear power versus EMA(close). Parameters ---------- high : array-like Sequence of high prices. low : array-like Sequence of low prices. close : array-like Sequence of closing prices. timeperiod : int, optional EMA period (default 13). Returns ------- tuple[numpy.ndarray, numpy.ndarray] ``(bull_power, bear_power)``. Leading ``timeperiod - 1`` entries are ``NaN``. """ try: return _elder_ray(_to_f64(high), _to_f64(low), _to_f64(close), timeperiod) except ValueError as e: _normalize_rust_error(e)
[docs] def FISHER( high: ArrayLike, low: ArrayLike, timeperiod: int = 9, ) -> tuple[np.ndarray, np.ndarray]: """Ehlers Fisher Transform of median price. Parameters ---------- high : array-like Sequence of high prices. low : array-like Sequence of low prices. timeperiod : int, optional Highest / lowest lookback (default 9). Returns ------- tuple[numpy.ndarray, numpy.ndarray] ``(fisher, signal)`` where ``signal`` is the previous Fisher value. Leading ``timeperiod - 1`` Fisher entries are ``NaN``. """ try: return _fisher(_to_f64(high), _to_f64(low), timeperiod) except ValueError as e: _normalize_rust_error(e)
[docs] def CRSI( close: ArrayLike, timeperiod: int = 3, streakperiod: int = 2, rankperiod: int = 100, ) -> np.ndarray: """Connors RSI — average of price RSI, streak RSI, and ROC percent rank. Parameters ---------- close : array-like Sequence of closing prices. timeperiod : int, optional RSI period of close (default 3). streakperiod : int, optional RSI period of the up/down streak (default 2). rankperiod : int, optional Percent-rank lookback of 1-bar ROC (default 100). Returns ------- numpy.ndarray Array of Connors RSI values (0–100). """ try: return _crsi(_to_f64(close), timeperiod, streakperiod, rankperiod) except ValueError as e: _normalize_rust_error(e)
__all__ = [ "RSI", "MOM", "ROC", "ROCP", "ROCR", "ROCR100", "WILLR", "AROON", "AROONOSC", "CCI", "MFI", "BOP", "STOCHF", "STOCH", "STOCHRSI", "APO", "PPO", "CMO", "PLUS_DM", "MINUS_DM", "PLUS_DI", "MINUS_DI", "DX", "ADX", "DMI", "ADXR", "TRIX", "ULTOSC", "TRANGE", "ELDER_RAY", "FISHER", "CRSI", ]