Skip to main content
Pro Feature. Requires a Pro or Ultra subscription. Get started at api.mathematicalcompany.com

Spread Convergence

Track the price spread between two correlated markets. Enter when the spread deviates beyond a z-score threshold, exit when it reverts to the mean.

How It Works

  1. Compute spread = price_a - price_b each cycle
  2. Maintain a rolling window of spread values
  3. Compute z-score of current spread vs historical mean/std
  4. Enter when |z| > entry_zscore, exit when |z| < exit_zscore

Pipeline: spread_convergence

SpreadSignal

Stored in ctx.params["last_spread_signal"].

Signal Logic

Example

For more rigorous pairs trading with cointegration testing and half-life filtering, see Statistical Arb.