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 |
|---|---|
Rolling mean of |return| / notional (Amihud 2002 illiquidity ratio). |
|
EW excess kurtosis. |
|
Exponentially-weighted moving average (pandas adjust=True). |
|
EW root-mean-square. |
|
EW skewness. |
|
EW standard deviation. |
|
EW variance (pandas adjust=True bias-corrected). |
|
Running bias-corrected excess kurtosis (Fisher) over the whole history. |
|
Running mean over the whole history since the last reset. |
|
Running bias-corrected sample skewness (G1) over the whole history. |
|
Running sample standard deviation (ddof=1) over the whole history. |
|
Running sample variance (ddof=1) over the whole history. |
|
Position of the maximum within the trailing window (0 is the oldest sample). |
|
Position of the minimum within the trailing window (0 is the oldest sample). |
|
Q3 minus Q1 over the trailing window. |
|
Trailing-window excess kurtosis. |
|
Trailing-window mean absolute deviation from the rolling mean. |
|
Trailing-window maximum (monotonic deque). |
|
Trailing-window arithmetic mean (simple moving average). |
|
Trailing-window median. |
|
Rolling median absolute deviation, median(|x - median|), a robust scale estimate. |
|
Trailing-window minimum (monotonic deque). |
|
Trailing-window minimum and maximum, computed in one pass. |
|
Percentile rank (rank / window) of the current value within the trailing window. |
|
Entropy of the ordinal patterns of a series over a trailing window, from 0 (one pattern repeats) to 1 (every pattern equally often). |
|
Trailing-window quantile (e.g. 0.25 = lower quartile). |
|
Trailing-window max minus min. |
|
Rank of the current value within the trailing window (1-based, average tie rule). |
|
Realized kurtosis of a window of returns, N times the sum of fourth powers of the returns over the squared realized variance. |
|
Realized skewness of a window of returns, sqrt(N) times the sum of cubed returns over the realized variance to the power 3/2. |
|
Trailing-window root-mean-square. |
|
Mean of the same slot of the last window_size cycles, such as the same hour on each of the last 20 days. |
|
Sample standard deviation of the same slot of the last window_size cycles. |
|
Trailing-window skewness. |
|
Trailing-window sample standard deviation (ddof=1). |
|
Trailing-window sum. |
|
Trailing-window sample variance (ddof=1). |
|
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 |
|---|---|
Wilder-smoothed average of TrueRange. |
|
Mean +/- num_std rolling standard deviations. |
|
Exponentially weighted Garman-Klass range-based variance estimator (OHLC). |
|
Exponentially weighted Garman-Klass range-based volatility estimator (OHLC). |
|
Exponentially weighted Parkinson range-based variance estimator (high, low). |
|
Exponentially weighted Parkinson range-based volatility estimator (high, low). |
|
EW root-mean-square. |
|
Exponentially weighted Rogers-Satchell drift-robust range-based variance estimator (OHLC). |
|
Exponentially weighted Rogers-Satchell drift-robust range-based volatility estimator (OHLC). |
|
EW standard deviation. |
|
EW variance (pandas adjust=True bias-corrected). |
|
Exponentially weighted Yang-Zhang range-based variance estimator (OHLC). |
|
Exponentially weighted Yang-Zhang range-based volatility estimator (OHLC). |
|
Running sample standard deviation (ddof=1) over the whole history. |
|
Running sample variance (ddof=1) over the whole history. |
|
Volatility-adapted envelope: EMA midline plus/minus a multiple of ATR. |
|
ATR scaled to a percentage of the current close. |
|
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. |
|
Trailing-window downside semideviation: the RMS of returns falling below a minimum acceptable return. |
|
Var form of the Garman-Klass range-based volatility estimator (OHLC). |
|
Vol form of the Garman-Klass range-based volatility estimator (OHLC). |
|
Share of the realized variance of a window of returns that comes from jumps: max(0, 1 - BV / RV). |
|
Var form of the Parkinson range-based volatility estimator (uses high & low). |
|
Vol form of the Parkinson range-based volatility estimator (uses high & low). |
|
Trailing-window max minus min. |
|
Trailing-window root-mean-square. |
|
Var form of the Rogers-Satchell drift-robust range-based estimator. |
|
Vol form of the Rogers-Satchell drift-robust range-based estimator. |
|
Sample standard deviation of the same slot of the last window_size cycles. |
|
Trailing-window sample standard deviation (ddof=1). |
|
Trailing-window upside semideviation: the RMS of the returns above a minimum acceptable return. |
|
Trailing-window sample variance (ddof=1). |
|
Var form of the Yang-Zhang estimator (drift + gap robust). |
|
Vol form of the Yang-Zhang estimator (drift + gap robust). |
|
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 |
|---|---|
x[t] minus its rolling mean. |
|
Latest sample standardized by the EW mean and std. |
|
Fractional differencing filter. Removes the trend while keeping more of the series' memory than an integer difference. |
|
Affine transform: scale * x + shift. |
|
(x - mean) / std over the same slot of the last window_size cycles, x included. |
|
Latest sample standardized by the trailing-window mean and standard deviation. |
Cumulative#
Running aggregates from the start of the series.
Function |
Description |
|---|---|
Chaikin Accumulation/Distribution Line. |
|
Running maximum from t=0. |
|
Running minimum from t=0. |
|
Running product from t=0. |
|
Running sum from t=0. |
|
Running drawdown from the cumulative peak. |
|
Running maximum since the start of the stream. |
|
Running minimum since the start of the stream. |
|
Running product since the start of the stream. |
|
Running sum since the start of the stream. |
|
Latch the first finite value seen since reset. |
|
Return the most recent finite value seen since reset. |
|
Worst drawdown experienced so far (since reset). |
|
On-Balance Volume: signed cumulative volume by close-direction (Granville, 1963). |
|
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 linear regression with a forgetting factor: the current slope and intercept, and a one-step-ahead predictive mean and standard deviation. |
|
EW regression intercept, ewmean(x) - EwBeta(x,y) * ewmean(y). |
|
EW CAPM beta: cov(target, regressor) / var(regressor). |
|
EW Pearson correlation of two parallel streams. |
|
EW covariance of two parallel streams. |
|
Exponentially-weighted price-impact slope of return on signed order flow. |
|
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. |
|
EW std of the spread x - EwBeta(x, y) * y. |
|
EW hedge-adjusted residual x - EwBeta(x, y) * y. |
|
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. |
|
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 t-statistic: how strongly a series, such as a pairs spread, reverts to a mean over the last window. |
|
Rolling OLS intercept of a target regressed on a regressor (companion to RollingBeta). |
|
Rolling regression slope cov(x, y) / var(y) of the first input x (dependent) on the second input y (regressor). |
|
Rolling Pearson correlation of two parallel streams. |
|
Rolling sample covariance of two parallel streams. |
|
Rolling-window Hurst exponent via Anis-Lloyd corrected rescaled-range analysis. |
|
Rolling-window price-impact slope of return on signed order flow (Kyle 1985). |
|
Rolling OLS fit of y on x, returning slope, intercept, R-squared and the standard error of the fit. |
|
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 MLE fit of a mean-reverting Ornstein-Uhlenbeck process. |
|
OLS fit y = a + b*t over a trailing window. derivative_order selects value/slope/zero. |
|
Standard deviation of the rolling hedge-adjusted residual y - beta * x. |
|
Rolling hedge-adjusted residual x - beta * y, with beta the rolling regression slope. |
|
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. |
|
Linear regression of the input on time, projected one step ahead (TA-Lib TSF). |