Class CointegrationTest

java.lang.Object
com.quantfinlib.hedging.CointegrationTest

public final class CointegrationTest extends Object
Engle-Granger two-step cointegration test: regress one price series on the other, then run an augmented Dickey-Fuller test (no constant) on the residual spread. This is the statistical justification PairsHedger needs before a pairs trade — a high return correlation is not enough; the spread must be stationary.

Critical values: the constants are the Engle-Granger two-variable, no-trend asymptotics -3.90 (1%), -3.34 (5%), -3.04 (10%); criticalValue(double, int) gives MacKinnon's (2010, "Critical values for cointegration tests", Queen's Economics Department WP 1227, Table 2, N = 2, constant) finite-sample response surface τ(T) = τ∞ + τ₁/T + τ₂/T², which engleGranger(double[], double[], int) uses. More negative ADF t-statistics mean stronger evidence of cointegration. The hedge ratio is the OLS slope of A on B, which is not symmetric in the two series (regressing B on A gives a different ratio); total least squares or Johansen would be.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
     
    static final double
     
    static final double
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    adfTStatistic(double[] series)
    Dickey-Fuller t-statistic (no constant, no lags — appropriate for mean-zero regression residuals): regress Δe_t = γ e_{t-1} + u_t and return t = γ̂ / se(γ̂).
    static double
    adfTStatistic(double[] series, int lags)
    Augmented Dickey-Fuller t-statistic without constant (the residuals of a regression with intercept have mean zero): Δe_t = γ·e_{t−1} + Σ_{j=1..p} φ_j·Δe_{t−j} + u_t, OLS over t = p+1 .. n−1; returns γ̂ / se(γ̂).
    static double
    criticalValue(double level, int observations)
    MacKinnon (2010) finite-sample critical value for the two-variable Engle-Granger test with a constant.
    engleGranger(double[] pricesA, double[] pricesB)
    Engle-Granger test with no augmentation lags and the asymptotic critical values (the original behaviour); see engleGranger(double[], double[], int).
    engleGranger(double[] pricesA, double[] pricesB, int lags)
    Engle-Granger test with lags augmentation lags in the ADF regression and MacKinnon finite-sample critical values.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • criticalValue

      public static double criticalValue(double level, int observations)
      MacKinnon (2010) finite-sample critical value for the two-variable Engle-Granger test with a constant.
      Parameters:
      level - 0.01, 0.05 or 0.10
      observations - T, the number of residuals used in the ADF regression
    • engleGranger

      public static CointegrationTest.EngleGrangerResult engleGranger(double[] pricesA, double[] pricesB)
      Engle-Granger test with no augmentation lags and the asymptotic critical values (the original behaviour); see engleGranger(double[], double[], int).
    • engleGranger

      public static CointegrationTest.EngleGrangerResult engleGranger(double[] pricesA, double[] pricesB, int lags)
      Engle-Granger test with lags augmentation lags in the ADF regression and MacKinnon finite-sample critical values.
    • adfTStatistic

      public static double adfTStatistic(double[] series)
      Dickey-Fuller t-statistic (no constant, no lags — appropriate for mean-zero regression residuals): regress Δe_t = γ e_{t-1} + u_t and return t = γ̂ / se(γ̂).
    • adfTStatistic

      public static double adfTStatistic(double[] series, int lags)
      Augmented Dickey-Fuller t-statistic without constant (the residuals of a regression with intercept have mean zero): Δe_t = γ·e_{t−1} + Σ_{j=1..p} φ_j·Δe_{t−j} + u_t, OLS over t = p+1 .. n−1; returns γ̂ / se(γ̂). lags = 0 is adfTStatistic(double[]).