Screamer#

Screamer is a fast C++ library for time series in finance and signal processing: indicators, filters, order flow, costed backtests and significance tests, with the same functions on arrays, on live streams and in JavaScript.

pip install screamer

Start the Guide

Detect a trend in four lines#

The example fits a straight line to the last 100 values and keeps the sign of its slope: +1 while the series is rising, -1 while it is falling.

from screamer import RollingPoly1, Sign

slope = RollingPoly1(window_size=100, derivative_order=1)
sign = Sign()

trend = sign(slope(close))
import { ready, RollingPoly1, Sign } from "@screamer-labs/screamer";

await ready();

const slope = RollingPoly1(100, 1);   // windowSize, derivativeOrder
const sign = Sign();

const trend = sign(slope(close));     // close: Float64Array

The plot applies it to daily BTC closes from 2022 to 2026: green where the trend is up, red where it is down. The trend uses only past prices, so it turns a few weeks after the market does.

Guide#

Part 0: Basics

  1. First steps: Install screamer, apply a function to arrays and DataFrames, and handle NaN values and warmup.

  2. Get your data in: Load OHLCV data, build bars from ticks, and replace pandas, TA-Lib and mlfinlab (AFML) code.

Part 1: Understand a series

  1. Smooth and denoise a series: Moving averages, low-lag and adaptive smoothers (Hull, KAMA, MAMA), Kalman and Butterworth filters, Hampel despiking, and robust outlier detection (median absolute deviation, sigma clipping).

  2. Measure volatility: Close-to-close and OHLC estimators (Yang-Zhang), average true range (ATR), jumps (bipower variation), and weekday seasonality (seasonal z-score, also for hours of the day).

  3. Detect a trend: Rolling slope (linear regression), moving-average crossover, ADX and directional movement (DMI), and trend mode.

  4. Compute classic technical indicators: Momentum oscillators (Stochastic RSI, Williams %R, CCI, TRIX, Ultimate Oscillator), MACD, the stochastic oscillator and rate of change (ROC), volume indicators (OBV, MFI, accumulation/distribution, VWAP), and Keltner Channels next to Bollinger Bands (squeeze).

  5. Detect mean reversion: Variance ratio test, Hurst exponent, Ornstein-Uhlenbeck (OU) half-life, and z-score bands.

  6. Find cycles: Dominant cycle period (Ehlers, Hilbert transform, roofing filter) and cycle turning points (sinewave indicator).

  7. Detect regimes and change points: Hidden Markov models (HMM), Bayesian online changepoint detection, CUSUM filter events, and permutation entropy.

  8. Read order flow and liquidity: Trade signing (tick rule), order-flow imbalance (OFI), price impact (Kyle's lambda), Amihud illiquidity, bid-ask spread from bars (EDGE, Corwin-Schultz, Abdi-Ranaldo, Roll), effective and realized spread, VPIN toxicity, micro-price and queue imbalance, and Hawkes trade arrivals.

Part 2: Build a strategy

  1. Turn a signal into a position: Sign of a signal, entry and exit bands (hysteresis, Schmitt trigger), holding periods, and volatility position sizing.

  2. Backtest a strategy: Backtests on bars, tick trades and bid-ask quotes (L1), the backtest report, fees and slippage, limit and market orders, volume caps (participation), portfolio reports, drawdown, and liquidation distance.

  3. Measure performance and risk: Rolling Sharpe, Sortino, Calmar and Omega ratios, the information ratio, CVaR (expected shortfall) and downside deviation, beta and alpha against a benchmark, and multi-factor regressions.

  4. Strategy templates: Trend following, breakouts, RSI and Bollinger Band reversion, pairs trading, cross-sectional momentum, funding carry, and volatility targeting.

  5. Stops and exits: Stop-loss, take-profit and trailing-stop exits on a backtest.

  6. Portfolios of many assets: Multi-asset backtests and sizing, cross-sectional z-scores, demeaning and winsorizing, and calculations that restart per day, contract or group (Segment).

Part 3: Test a strategy

  1. Check that a backtest result is not luck: Randomization and Monte Carlo permutation tests, block shuffles, time-shifted signals, synthetic price paths, walk-forward testing, parameter grids, and the deflated Sharpe ratio.

  2. Prepare data for machine learning: Features, labels (triple barrier), training sets, purged time series cross-validation, and fractional differencing.

Part 4: Run a strategy live

  1. Run on live data: Streaming one value at a time, aligning streams, pipelines, a live trading loop, saving and resuming a strategy, and JavaScript in the browser.

Why screamer#

  • Fast: rolling statistics in constant time per sample, see Performance.

  • Causal: every output uses only current and past inputs, see Conventions.

  • One code path: the same function runs on a stored array and on a live feed, see Streams in depth.