finmlkit.feature.transforms module

Feature transform wrapper for financial time series data.

class finmlkit.feature.transforms.ADX(length: int = 14, input_cols: list[str] = None)[source]

Bases: MISOTransform

Computes the Average Directional Index (ADX) of price data.

ADX measures the strength of a trend (regardless of direction) on a scale from 0 to 100. Values below 20 indicate a weak trend, above 25 indicate a strong trend.

This implementation uses Wilder’s smoothing method for calculations.

class finmlkit.feature.transforms.ATR(window: int = 14, ema_based: bool = False, normalize: bool = False, input_cols: list[str] = None)[source]

Bases: MISOTransform

Computes the Average True Range (ATR) of price data.

class finmlkit.feature.transforms.ApproximateEntropy(window: int = 24, m: int = 2, tolerance: float = 0.2, input_col: str = 'ret1')[source]

Bases: SISOTransform

Computes the approximate entropy (ApEn) of a time series.

Approximate entropy measures the complexity or irregularity of a time series: - High ApEn values indicate high irregularity/unpredictability - Low ApEn values indicate regularity/structure/predictability

This implementation uses the antropy package for calculating ApEn.

class finmlkit.feature.transforms.BarDuration(periods=1, input_col: str = 'close')[source]

Bases: SISOTransform

This transform calculates the time difference between consecutive bars in seconds.

class finmlkit.feature.transforms.BarDurationEWMA(span: int = 20, input_col: str = 'close')[source]

Bases: SISOTransform

Computes the Exponentially Weighted Moving Average (EWMA) of bar durations.

This transform calculates the time difference between consecutive bars and then applies an exponential moving average to these durations. It’s useful for: - Identifying periods of high/low trading activity - Normalizing other features based on time flow - Detecting regime changes in market microstructure

class finmlkit.feature.transforms.BarRate(window: Timedelta, input_col: str = 'close')[source]

Bases: SISOTransform

Calculates the rate of bars (number of bars divided by time window) in a specified time window.

This is useful for: - Detecting rare “flurries” of activity (multiple jumps in short periods) - Distinguishing between normal and super-quiet market regimes - Identifying periods of unusual market activity

For example: - rate_6m: bars in last 6 min ÷ 360 s - Flags the rare flurries (2-3 jumps in a few minutes) - rate_30m: CUSUM bars in last 30 min ÷ 1800 s - Separates “normal” from “super-quiet” regimes

class finmlkit.feature.transforms.BiPowerVariation(window: int = 12, input_col: str = 'ret1')[source]

Bases: SISOTransform

Computes the bi-power variation (BV) of a return series.

Bi-power variation is used to estimate the integrated variance in the presence of jumps. It is calculated as the sum of the products of consecutive absolute returns, multiplied by a correction factor.

This is useful for: - Separating continuous and jump components of volatility - Creating jump-robust volatility estimators - Identifying the presence of jumps when compared to realized volatility

class finmlkit.feature.transforms.BollingerPercentB(window: int, num_std: float = 2.0, input_col: str = 'close')[source]

Bases: SISOTransform

Computes the Bollinger Percent B of a time series.

class finmlkit.feature.transforms.BurstRatio(window: int, input_col: str)[source]

Bases: SISOTransform

Computes the burst ratio of a time series using a rolling window.

class finmlkit.feature.transforms.CUSUMTest(window_size: int = 50, warmup_period: int = 30, max_age: int = 144, input_col: str = 'close')[source]

Bases: SIMOTransform

Computes the CUSUM test statistics for structural breaks in time series.

Features include: - Break indicators (snt - critical values): Positive when a break is detected - Flag features: Binary indicator when a break is detected (1 when break just fired, else 0) - Score features: Magnitude of the break, clipped to ±10 σ_noise - Age features: Number of bars since the last break, capped at a maximum value

property output_name

Get the output names of the transform. For SIMO transforms, the output names are derived from the input column name. :return: List of output names

class finmlkit.feature.transforms.CandleShape(input_cols: list[str] = None)[source]

Bases: MIMOTransform

Computes various candle shape metrics to characterize price action.

Features include: - wick_up_ratio: Ratio of upper wick to total candle range - wick_dn_ratio: Ratio of lower wick to total candle range - body_ratio: Ratio of candle body to total candle range - vwap_drift: Percentage difference between VWAP and open price

property output_name

Get the output names of the transform. :return: List of output names

class finmlkit.feature.transforms.DailyGap(input_col: str = 'close')[source]

Bases: SISOTransform

Calculates the overnight UTC gap between the close price at 00:00 and the previous day’s close at 23:45. Formula: (close_{00:00} - close_{23:45_prev}) / close_{23:45_prev}

This assumes the input data is in 15-minute intervals and is UTC-aligned.

class finmlkit.feature.transforms.DirRunLen(input_col: str = 'ret1')[source]

Bases: SISOTransform

Counts consecutive same-sign returns until just before the current bar.

The streak resets when the sign changes or when a return is 0. The count indicates the length of the streak of consecutive returns with the same sign.

static numba_core(x: ndarray) ndarray[source]

Numba implementation of directional run length calculation.

Parameters:

x – Input array of returns

Returns:

Array containing directional run lengths

class finmlkit.feature.transforms.EWMA(span: int, input_col: str = None)[source]

Bases: SISOTransform

Computes the Exponentially Weighted Moving Average (EWMA) of a time series.

class finmlkit.feature.transforms.EWMST(half_life: Timedelta, input_col: str = 'y')[source]

Bases: SISOTransform

Computes the exponentially weighted moving standard deviation of a time series.

class finmlkit.feature.transforms.FlowAcceleration(window: int, recent_periods, input_col: str = 'volume')[source]

Bases: SISOTransform

Computes the Flow Acceleration of a time series.

class finmlkit.feature.transforms.HurstExponent(window: int = 24, input_col: str = 'ret1')[source]

Bases: SISOTransform

Computes the Hurst exponent of a time series using the aggregated variance method.

The Hurst exponent (H) is a measure of the long-term memory of a time series: - H > 0.5 indicates a persistent/trending price path - H = 0.5 indicates a random walk (Brownian motion) - H < 0.5 indicates a mean-reverting/noisy series

This implementation uses the aggregated variance method to estimate H.

class finmlkit.feature.transforms.Identity(input_col: str = 'close')[source]

Bases: BaseTransform

Returns the identity transform of a selected column

property output_name: str

Returns the name of the output column.

class finmlkit.feature.transforms.Lag(periods: int = 1, input_col: str = 'close')[source]

Bases: SISOTransform

Implements lagged values of a time series.

class finmlkit.feature.transforms.MeanReversionZScore(window: int = 48, input_col: str = 'close')[source]

Bases: SISOTransform

Calculates the z-score of price relative to its simple moving average. Formula: (close - SMA_window)/std_window Used as a mean-reversion filter to identify potential mean-reversion opportunities.

class finmlkit.feature.transforms.ORBBreak(input_cols: list[str] = None)[source]

Bases: MIMOTransform

Detects Opening Range Breakout (ORB) signals within a UTC day.

An ORB occurs when the price breaks above the high or below the low of the first hour of trading. The transform returns two signals: a long signal (1 when price breaks above opening range high, otherwise 0) and a short signal (1 when price breaks below opening range low, otherwise 0).

This implementation assumes the input data is in 15-minute intervals and is UTC-aligned. The opening range is defined as the first 4 bars (first hour) of each UTC day.

property output_name

Get the output names of the transform. :return: List of output names

class finmlkit.feature.transforms.ParkinsonRange(input_cols=None)[source]

Bases: MISOTransform

Computes the Parkinson range of a time series.

class finmlkit.feature.transforms.PctChange(window: int, input_col: str = 'close')[source]

Bases: SISOTransform

Computes the percentage change of a time series using a specified lag.

class finmlkit.feature.transforms.PriceVolumeCorrelation(window: int = 8, input_cols: list[str] = None)[source]

Bases: MISOTransform

Calculates the rolling Pearson correlation coefficient between price returns and volume.

class finmlkit.feature.transforms.ROC(periods: int, input_col: str = 'close')[source]

Bases: SISOTransform

Computes the Rate of Change (ROC) of a time series.

class finmlkit.feature.transforms.RSIWilder(window: int = 14, input_col: str = 'close')[source]

Bases: SISOTransform

Computes the Relative Strength Index (RSI) of a time series using Wilder’s smoothing method.

class finmlkit.feature.transforms.RealizedVolatility(window: int, is_sample=False, input_col: str = 'ret')[source]

Bases: SISOTransform

Computes the realized volatility of a time series.

class finmlkit.feature.transforms.Return(periods: int = 1, input_col: str = 'close', is_log: bool = False)[source]

Bases: SISOTransform

Implements lagged return

class finmlkit.feature.transforms.ReturnT(window: Timedelta = Timedelta('0 days 00:00:00.000001'), is_log: bool = False, input_col: str = 'close')[source]

Bases: SISOTransform

Calculates the lagged returns of a time series using a specified period defined in seconds. Works for irregular time series too.

class finmlkit.feature.transforms.SMA(window: int, input_col: str = 'x')[source]

Bases: SISOTransform

Computes the Simple Moving Average (SMA) of a time series.

class finmlkit.feature.transforms.StochK(length: int = 14, input_cols: list[str] = None)[source]

Bases: MISOTransform

Computes the Stochastic Oscillator %K of a time series.

class finmlkit.feature.transforms.TimeCues(input_col: str = 'close')[source]

Bases: SIMOTransform

Computes time-based features for a time series.

property output_name

Get the output names of the transform. For SIMO transforms, the output names are derived from the input column name. :return: List of output names

class finmlkit.feature.transforms.VPIN(window: int = 32, input_cols: list[str] = None)[source]

Bases: MISOTransform

Calculates the VPIN (Volume-synchronized Probability of Informed Trading) metric. VPIN measures the fraction of signed volume imbalance to total volume in a rolling window.

class finmlkit.feature.transforms.VWAPDistance(periods: int, is_log: bool = False, input_cols: str = None)[source]

Bases: MISOTransform

Computes the distance of the current price from the VWAP (Volume Weighted Average Price).

class finmlkit.feature.transforms.VarianceRatio14(window: int = 32, input_col: str = 'close', ret_type: str = 'log', ddof: int = 0)[source]

Bases: SISOTransform

Computes the Variance Ratio of 1-bar returns to 4-bar returns: var(1-bar) / var(4×1-bar).

This is a useful metric to detect microstructure noise vs trending behavior. For random walks, the ratio should be close to 0.25 (1/4). Values < 0.25 suggest mean reversion, while values > 0.25 suggest trending/momentum.

class finmlkit.feature.transforms.ZScore(window: int, input_col: str, ddof: int = 0)[source]

Bases: SISOTransform

Computes the z-score of a time series using a rolling window.