Forecasting & ML#

Training sets and labels from time-series data, online regression and filtering that forecast as they update, and regime and change-point models.

Supervised learning & online forecasting#

Forecasting training sets from causal features and targets, labels such as the triple barrier, and regressions and filters that update and forecast at every step.

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

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.

forecast_pairs

Build a forecasting training set where row t holds the features at t and the target over the horizon after t.

Scalar Kalman filter

Scalar 1-D Kalman filter for a noisy random-walk model.

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.

Triple-barrier label on a price series

A three-state label over a window: +1 when the price reaches the upper barrier first, -1 when it reaches the lower barrier first, 0 when it reaches neither within horizon steps.

Triple-barrier label on OHLC bars

A three-state label over a window of OHLC bars: +1 when the upper barrier is reached first, -1 when the lower barrier is reached first, 0 when neither is reached within horizon bars; barriers are tested on each bar's open, high, and low.

Regimes & change points#

Detect a change in a series' behaviour: hidden Markov regimes, Bayesian change points, CUSUM events, and tests for persistence, jumps, and randomness.

Function

Description

Bayesian online changepoint detection

Online Bayesian changepoint detection (Adams-MacKay) on a series with Gaussian segments of unknown mean and variance; the expected run length since the last change and a predictive mean and standard deviation.

CUSUM event filter

Symmetric CUSUM event filter: +1 when the cumulative rise since the last event passes a threshold, -1 for a fall, 0 otherwise.

Rolling two-state hidden Markov model

Two-state hidden Markov model of a series, refit on a trailing window and filtered forward each step; the probability of the high-variance (or more persistent) state and a one-step predictive mean and standard deviation.

Rolling Jump Share

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

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