Skip to main content

Module cointegration

Module cointegration 

Source
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

  1. OLS regression: y = alpha + beta * x + residuals
  2. ADF test on residuals: tests if the spread is mean-reverting
  3. Half-life via Ornstein-Uhlenbeck: hl = -ln(2) / ln(1 + theta)
  4. Pearson correlation between the two price series

Structs§

EngleGrangerResult
Result of an Engle-Granger cointegration test.

Enums§

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