Documentation Index
Fetch the complete documentation index at: https://mathematicalcompany.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Pro Feature. Requires a Pro or Ultra subscription. Get started at api.mathematicalcompany.com
Statistical Arbitrage
A more rigorous version of Spread Convergence. Uses OLS hedge ratio, ADF stationarity testing, and half-life filtering to identify truly cointegrated pairs.How It Works
- Collect price histories for both markets
- Compute OLS hedge ratio:
beta = cov(a,b) / var(b) - Compute residuals:
r = a - beta * b - Run ADF test on residuals (more negative = more stationary)
- Check
signal_half_life()on residuals (reject if outside bounds) - Compute z-score of current residual
- Generate entry/exit/stop signals
Rust Functions
cointegration_test
spread_zscore
StatArbConfig
| Parameter | Type | Default | Description |
|---|---|---|---|
pair | tuple[str, str] | required | Market IDs |
feeds | tuple[str, str] | required | Feed names |
lookback | int | 200 | Price history window |
entry_zscore | float | 2.0 | Entry threshold |
exit_zscore | float | 0.5 | Exit threshold |
stop_zscore | float | 4.0 | Stop-loss threshold |
recalibrate_every | int | 50 | Ticks between recalibration |
min_half_life | float | 5.0 | Min half-life (reject if faster) |
max_half_life | float | 200.0 | Max half-life (reject if slower) |
Pipeline: stat_arb
StatArbResult in ctx.params["last_stat_arb"].
StatArbResult
| Field | Type | Description |
|---|---|---|
pair | tuple[str, str] | Market pair |
hedge_ratio | float | OLS hedge ratio |
zscore | float | Current residual z-score |
half_life | float | Mean-reversion half-life |
adf_stat | float | ADF test statistic |
signal | str | "long_a_short_b", "long_b_short_a", "exit", "stop", or "hold" |
Signal Logic
| Condition | Position | Signal | ||
|---|---|---|---|---|
z > entry_zscore | flat | long_b_short_a | ||
z < -entry_zscore | flat | long_a_short_b | ||
| ` | z | < exit_zscore` | positioned | exit |
| ` | z | > stop_zscore` | positioned | stop |
| otherwise | any | hold |
Example
ADF critical values (n > 100): 1% = -3.43, 5% = -2.862, 10% = -2.567. More negative values indicate stronger stationarity evidence.