Statistics#

Measures of a window: central tendency, dispersion, quantiles, moments, z-scores, running totals, and cross-series relationships.

Statistics#

Windowed summary statistics: central tendency, dispersion, quantiles, moments, and extremes.

Function

Description

Amihud Illiquidity

Rolling mean of |return| / notional (Amihud 2002 illiquidity ratio).

Exponentially-weighted kurtosis

EW excess kurtosis.

Exponentially-weighted mean

Exponentially-weighted moving average (pandas adjust=True).

Exponentially-weighted RMS

EW root-mean-square.

Exponentially-weighted skewness

EW skewness.

Exponentially-weighted standard deviation

EW standard deviation.

Exponentially-weighted variance

EW variance (pandas adjust=True bias-corrected).

Expanding kurtosis

Running bias-corrected excess kurtosis (Fisher) over the whole history.

Expanding mean

Running mean over the whole history since the last reset.

Expanding skewness

Running bias-corrected sample skewness (G1) over the whole history.

Expanding standard deviation

Running sample standard deviation (ddof=1) over the whole history.

Expanding variance

Running sample variance (ddof=1) over the whole history.

Rolling argmax

Position of the maximum within the trailing window (0 is the oldest sample).

Rolling argmin

Position of the minimum within the trailing window (0 is the oldest sample).

Rolling interquartile range

Q3 minus Q1 over the trailing window.

Rolling kurtosis

Trailing-window excess kurtosis.

Rolling mean absolute deviation

Trailing-window mean absolute deviation from the rolling mean.

Rolling maximum

Trailing-window maximum (monotonic deque).

Rolling mean

Trailing-window arithmetic mean (simple moving average).

Rolling median

Trailing-window median.

Rolling median absolute deviation

Rolling median absolute deviation, median(|x - median|), a robust scale estimate.

Rolling minimum

Trailing-window minimum (monotonic deque).

Rolling min and max

Trailing-window minimum and maximum, computed in one pass.

Rolling percentile

Percentile rank (rank / window) of the current value within the trailing window.

Rolling Permutation Entropy

Entropy of the ordinal patterns of a series over a trailing window, from 0 (one pattern repeats) to 1 (every pattern equally often).

Rolling quantile

Trailing-window quantile (e.g. 0.25 = lower quartile).

Rolling range

Trailing-window max minus min.

Rolling rank

Rank of the current value within the trailing window (1-based, average tie rule).

Rolling realized kurtosis

Realized kurtosis of a window of returns, N times the sum of fourth powers of the returns over the squared realized variance.

Rolling realized skewness

Realized skewness of a window of returns, sqrt(N) times the sum of cubed returns over the realized variance to the power 3/2.

Rolling root-mean-square

Trailing-window root-mean-square.

Rolling Seasonal Mean

Mean of the same slot of the last window_size cycles, such as the same hour on each of the last 20 days.

Rolling Seasonal Standard Deviation

Sample standard deviation of the same slot of the last window_size cycles.

Rolling skewness

Trailing-window skewness.

Rolling standard deviation

Trailing-window sample standard deviation (ddof=1).

Rolling sum

Trailing-window sum.

Rolling variance

Trailing-window sample variance (ddof=1).

Rolling Variance Ratio

Lo-MacKinlay variance ratio of a window of returns, near 1 for a random walk, above 1 when returns trend and below 1 when they revert, or its robust z-statistic.

Volatility#

The size of fluctuations and risk: standard deviation and variance, RMS, range-based OHLC estimators, and ATR.

Function

Description

Average True Range (ATR)

Wilder-smoothed average of TrueRange.

Bollinger Bands

Mean +/- num_std rolling standard deviations.

EW Garman-Klass variance

Exponentially weighted Garman-Klass range-based variance estimator (OHLC).

EW Garman-Klass volatility

Exponentially weighted Garman-Klass range-based volatility estimator (OHLC).

Exponentially-weighted Parkinson variance

Exponentially weighted Parkinson range-based variance estimator (high, low).

Exponentially-weighted Parkinson volatility

Exponentially weighted Parkinson range-based volatility estimator (high, low).

Exponentially-weighted RMS

EW root-mean-square.

EW Rogers-Satchell variance

Exponentially weighted Rogers-Satchell drift-robust range-based variance estimator (OHLC).

EW Rogers-Satchell volatility

Exponentially weighted Rogers-Satchell drift-robust range-based volatility estimator (OHLC).

Exponentially-weighted standard deviation

EW standard deviation.

Exponentially-weighted variance

EW variance (pandas adjust=True bias-corrected).

EW Yang-Zhang variance

Exponentially weighted Yang-Zhang range-based variance estimator (OHLC).

EW Yang-Zhang volatility

Exponentially weighted Yang-Zhang range-based volatility estimator (OHLC).

Expanding standard deviation

Running sample standard deviation (ddof=1) over the whole history.

Expanding variance

Running sample variance (ddof=1) over the whole history.

Keltner Channels

Volatility-adapted envelope: EMA midline plus/minus a multiple of ATR.

Normalized ATR (NATR)

ATR scaled to a percentage of the current close.

Rolling Bipower Variation

Jump-robust variance of a window of returns, (pi/2) times the sum of products of adjacent absolute returns, on the scale of the realized variance.

Rolling Downside Deviation

Trailing-window downside semideviation: the RMS of returns falling below a minimum acceptable return.

Rolling Garman-Klass variance

Var form of the Garman-Klass range-based volatility estimator (OHLC).

Rolling Garman-Klass volatility

Vol form of the Garman-Klass range-based volatility estimator (OHLC).

Rolling Jump Share

Share of the realized variance of a window of returns that comes from jumps: max(0, 1 - BV / RV).

Rolling Parkinson variance

Var form of the Parkinson range-based volatility estimator (uses high & low).

Rolling Parkinson volatility

Vol form of the Parkinson range-based volatility estimator (uses high & low).

Rolling range

Trailing-window max minus min.

Rolling root-mean-square

Trailing-window root-mean-square.

Rolling Rogers-Satchell variance

Var form of the Rogers-Satchell drift-robust range-based estimator.

Rolling Rogers-Satchell volatility

Vol form of the Rogers-Satchell drift-robust range-based estimator.

Rolling Seasonal Standard Deviation

Sample standard deviation of the same slot of the last window_size cycles.

Rolling standard deviation

Trailing-window sample standard deviation (ddof=1).

Rolling Upside Deviation

Trailing-window upside semideviation: the RMS of the returns above a minimum acceptable return.

Rolling variance

Trailing-window sample variance (ddof=1).

Rolling Yang-Zhang variance

Var form of the Yang-Zhang estimator (drift + gap robust).

Rolling Yang-Zhang volatility

Vol form of the Yang-Zhang estimator (drift + gap robust).

True Range (Wilder)

Per-bar true range accounting for overnight gaps (Wilder, 1978).

Standardization & normalization#

Put values on a comparable scale: z-scores, affine rescaling, and detrending.

Function

Description

Detrend

x[t] minus its rolling mean.

Exponentially-weighted z-score

Latest sample standardized by the EW mean and std.

Fractional differentiation (FracDiff)

Fractional differencing filter. Removes the trend while keeping more of the series' memory than an integer difference.

Linear (affine)

Affine transform: scale * x + shift.

Rolling Seasonal Z-score

(x - mean) / std over the same slot of the last window_size cycles, x included.

Rolling z-score

Latest sample standardized by the trailing-window mean and standard deviation.

Cumulative#

Running aggregates from the start of the series.

Function

Description

Accumulation/Distribution Line (Chaikin)

Chaikin Accumulation/Distribution Line.

Cumulative maximum

Running maximum from t=0.

Cumulative minimum

Running minimum from t=0.

Cumulative product

Running product from t=0.

Cumulative sum

Running sum from t=0.

Drawdown

Running drawdown from the cumulative peak.

Expanding maximum

Running maximum since the start of the stream.

Expanding minimum

Running minimum since the start of the stream.

Expanding product

Running product since the start of the stream.

Expanding sum

Running sum since the start of the stream.

First finite value

Latch the first finite value seen since reset.

Last finite value

Return the most recent finite value seen since reset.

Maximum drawdown

Worst drawdown experienced so far (since reset).

On-Balance Volume (OBV)

On-Balance Volume: signed cumulative volume by close-direction (Granville, 1963).

Segment-wise operator

Runs an operator on each segment of rows with the same label, resetting it where the label changes.

Correlation & regression#

Relationships between series: correlation, covariance, regression, hedging, pairs, and mean-reversion.

Function

Description

Online Bayesian regression

Online Bayesian linear regression with a forgetting factor: the current slope and intercept, and a one-step-ahead predictive mean and standard deviation.

Exponentially-weighted alpha

EW regression intercept, ewmean(x) - EwBeta(x,y) * ewmean(y).

Exponentially-weighted beta

EW CAPM beta: cov(target, regressor) / var(regressor).

Exponentially-weighted correlation

EW Pearson correlation of two parallel streams.

Exponentially-weighted covariance

EW covariance of two parallel streams.

Kyle's Lambda (exponentially weighted)

Exponentially-weighted price-impact slope of return on signed order flow.

Exponentially-weighted multiple regression

Exponentially weighted least-squares fit of y on k regressors, with the one-step-ahead prediction made before each row enters, R-squared, and the coefficients.

Exponentially-weighted residual std

EW std of the spread x - EwBeta(x, y) * y.

Exponentially-weighted spread

EW hedge-adjusted residual x - EwBeta(x, y) * y.

Expanding multiple regression

Least-squares fit of y on k regressors over every row so far, with the one-step-ahead prediction made before each row enters, R-squared, and the coefficients.

Kalman filter regression (dynamic hedge ratio)

Regression with a random-walk intercept and slope, estimated by a Kalman filter: the dynamic hedge ratio of a pairs trade, its spread, and the spread's predicted deviation.

Rolling augmented Dickey-Fuller statistic

Rolling augmented Dickey-Fuller t-statistic: how strongly a series, such as a pairs spread, reverts to a mean over the last window.

Rolling alpha (regression intercept)

Rolling OLS intercept of a target regressed on a regressor (companion to RollingBeta).

Rolling beta

Rolling regression slope cov(x, y) / var(y) of the first input x (dependent) on the second input y (regressor).

Rolling correlation

Rolling Pearson correlation of two parallel streams.

Rolling covariance

Rolling sample covariance of two parallel streams.

Rolling Hurst Exponent

Rolling-window Hurst exponent via Anis-Lloyd corrected rescaled-range analysis.

Kyle's Lambda (rolling)

Rolling-window price-impact slope of return on signed order flow (Kyle 1985).

Rolling linear regression

Rolling OLS fit of y on x, returning slope, intercept, R-squared and the standard error of the fit.

Rolling multiple regression

Rolling least-squares fit of y on k regressors, with the one-step-ahead prediction made before each row enters, R-squared, and the coefficients.

Rolling Ornstein-Uhlenbeck fit

Rolling MLE fit of a mean-reverting Ornstein-Uhlenbeck process.

Rolling 1st-order polynomial fit

OLS fit y = a + b*t over a trailing window. derivative_order selects value/slope/zero.

Rolling residual std

Standard deviation of the rolling hedge-adjusted residual y - beta * x.

Rolling spread

Rolling hedge-adjusted residual x - beta * y, with beta the rolling regression slope.

Rolling total least squares hedge ratio

Rolling total least squares (orthogonal regression) slope of the first input on the second: a hedge ratio that does not depend on which leg is called dependent.

Rolling Time-Series Forecast (TSF)

Linear regression of the input on time, projected one step ahead (TA-Lib TSF).