Class NeweyWest

java.lang.Object
com.quantfinlib.alpha.NeweyWest

public final class NeweyWest extends Object
Heteroskedasticity and autocorrelation consistent (HAC) standard errors with Bartlett weights (Newey and West 1987, Econometrica 55(3), eq. 2).

Why it matters here: an IC series computed on overlapping h-bar forward returns is mechanically MA(h−1), and a persistent signal (12-1 momentum, value, low volatility) adds positive autocorrelation on top. The iid standard error s/√n then understates the true one by roughly √((1+ρ)/(1−ρ)) for an AR(1) with coefficient ρ: a factor of three at ρ = 0.8.

The long-run variance of a series x is estimated as

  Ω = γ₀ + 2 Σ_{l=1..L} (1 − l/(L+1)) γ_l,   γ_l = (1/n) Σ_t (x_t − x̄)(x_{t−l} − x̄)

and the standard error of the mean is √(Ω/n). The Bartlett weights keep Ω non-negative. Note γ₀ uses the 1/n divisor, so at L = 0 the result is s_pop/√n, slightly below the sample-variance version for small n.

Lag choice: automaticLag(double[]) is the Andrews (1991, Econometrica 59(3), eq. 6.2 and Table I) AR(1) plug-in bandwidth for the Bartlett kernel; lagFor(double[], int) combines it with the h − 1 floor that overlapping h-bar windows require.

  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    autocorrelation(double[] x, int k)
    Lag-k sample autocorrelation γ_k / γ₀ (0 for a constant series).
    static int
    automaticLag(double[] x)
    Andrews (1991) AR(1) plug-in bandwidth for the Bartlett kernel: S = 1.1447 (α̂ n)^{1/3} with α̂ = 4ρ̂² / ((1−ρ̂)²(1+ρ̂)²), returned as an integer lag floor(S) capped at n/2.
    static int
    lagFor(double[] x, int overlap)
    Lag for a series of statistics computed on overlapping overlap-bar windows: max(overlap − 1, automaticLag(x)).
    static double
    longRunVariance(double[] x, int lag)
    HAC long-run variance Ω of x with Bartlett lag lag.
    static double
    standardErrorOfMean(double[] x, int lag)
    HAC standard error of the sample mean of x.
    static double
    tStat(double[] x, int lag)
    HAC t-statistic of the mean against zero: mean / SE_HAC.

    Methods inherited from class Object

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

    • longRunVariance

      public static double longRunVariance(double[] x, int lag)
      HAC long-run variance Ω of x with Bartlett lag lag.
    • standardErrorOfMean

      public static double standardErrorOfMean(double[] x, int lag)
      HAC standard error of the sample mean of x.
    • tStat

      public static double tStat(double[] x, int lag)
      HAC t-statistic of the mean against zero: mean / SE_HAC. Zero for a constant series with zero mean; ±∞ for a constant non-zero series (no sampling variation at all).
    • autocorrelation

      public static double autocorrelation(double[] x, int k)
      Lag-k sample autocorrelation γ_k / γ₀ (0 for a constant series).
    • automaticLag

      public static int automaticLag(double[] x)
      Andrews (1991) AR(1) plug-in bandwidth for the Bartlett kernel: S = 1.1447 (α̂ n)^{1/3} with α̂ = 4ρ̂² / ((1−ρ̂)²(1+ρ̂)²), returned as an integer lag floor(S) capped at n/2. ρ̂ is clamped to [−0.97, 0.97] so a near-unit-root series cannot request an unbounded window.
    • lagFor

      public static int lagFor(double[] x, int overlap)
      Lag for a series of statistics computed on overlapping overlap-bar windows: max(overlap − 1, automaticLag(x)).