Expand description
Engle-Granger cointegration test and pair-trading statistics.
Pure math — no I/O, no async, no external dependencies beyond std + rust_decimal.
§Algorithm
- OLS regression:
y = alpha + beta * x + residuals - ADF test on residuals: tests if the spread is mean-reverting
- Half-life via Ornstein-Uhlenbeck:
hl = -ln(2) / ln(1 + theta) - Pearson correlation between the two price series
Structs§
- Engle
Granger Result - Result of an Engle-Granger cointegration test.
Enums§
- Cointegration
Math Error - Errors from cointegration computation.
Constants§
- MIN_
OBSERVATIONS - Minimum number of observations for a meaningful cointegration test.
Functions§
- engle_
granger - Run an Engle-Granger cointegration test on two price series.
- pearson_
correlation - Pearson correlation coefficient between two series.
- spread_
stats_ to_ decimal - Convert spread mean and std from f64 to Decimal for the port layer.