Class Ols

java.lang.Object
com.quantfinlib.alpha.Ols

public final class Ols extends Object
Ordinary least squares by Householder QR, with classical and Newey-West HAC standard errors.

QR rather than the normal equations: solving XᵀX b = Xᵀy squares the condition number of X, which matters for factor return streams that are 0.6 to 0.9 correlated. The coefficient covariance uses (XᵀX)⁻¹ = R⁻¹R⁻ᵀ from the same factorisation.

  • Classical: V = σ̂² (XᵀX)⁻¹, σ̂² = e'e/(n − p).
  • HAC (Newey and West 1987): V = (XᵀX)⁻¹ S (XᵀX)⁻¹ with S = Σ_t e_t² x_t x_tᵀ + Σ_{l=1..L} w_l Σ_t e_t e_{t−l} (x_t x_{t−l}ᵀ + x_{t−l} x_tᵀ), w_l = 1 − l/(L+1). No small-sample degrees-of-freedom correction is applied.
  • Method Details

    • fit

      public static Ols.Fit fit(double[][] x, double[] y, int hacLag)
      Fits y = X b + e. The caller includes an intercept column if one is wanted.
      Parameters:
      x - design matrix, x[t][j], n rows by p columns, n > p
      y - response, length n
      hacLag - Bartlett lag for the HAC errors (0 = White heteroskedasticity-robust errors)
      Throws:
      IllegalArgumentException - on misaligned input, non-finite values or a rank-deficient design