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

Window-offset of the trailing-window maximum (TA-Lib MAXINDEX).

Rolling argmin

Window-offset of the trailing-window minimum (TA-Lib MININDEX).

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 (min, max) returned as a 2-tuple per step.

Rolling percentile

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

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 root-mean-square

Trailing-window root-mean-square.

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).

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

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

EW Garman-Klass volatility

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

Exponentially-weighted Parkinson variance

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

Exponentially-weighted Parkinson volatility

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

Exponentially-weighted RMS

EW root-mean-square.

EW Rogers-Satchell variance

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

EW Rogers-Satchell volatility

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

Exponentially-weighted standard deviation

EW standard deviation.

Exponentially-weighted variance

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

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.

Normalised ATR (NATR)

ATR scaled to a percentage of the current close.

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 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 standard deviation

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

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 standardised by EW mean and std.

Linear (affine)

Affine transform: scale * x + shift.

Rolling z-score

Latest sample standardised by trailing-window mean and std.

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 from t=0.

Expanding minimum

Running minimum from t=0.

Expanding product

Running product from t=0.

Expanding sum

Running sum from t=0.

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).

Correlation & regression#

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

Function

Description

Online Bayesian univariate regression (2->4 posterior fit)

Causal one-step-ahead predictive mean and std plus current slope and intercept via Normal-Inverse-Gamma posterior.

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.

Rolling alpha (regression intercept)

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

Rolling beta

cov(x, y) / var(y) - regression slope of x on y.

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 (2->4 OLS fit)

Full OLS fit returning (slope, intercept, r_squared, stderr).

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

x - beta(x,y) * y - hedge-adjusted residual.

Rolling Time-Series Forecast (TSF)

Linear regression of y on time, projected one step ahead. TA-Lib's TSF.