Class KalmanBeta

java.lang.Object
com.quantfinlib.microstructure.KalmanBeta

public final class KalmanBeta extends Object
TIME-VARYING regression by Kalman filter — the pairs desk's upgrade over a static OLS hedge ratio. The state [α, β] follows a random walk (relationships DRIFT: index compositions change, business mixes shift, a hedge ratio fitted on last year is stale by spring), and each observation y = α + β·x + ε nudges the estimate by exactly as much as its information content warrants:
  state:       [α, β]_t = [α, β]_{t-1} + noise(q)
  observation:  y_t = α_t + β_t·x_t + noise(r)
The knobs mean something: processNoise (q) is how fast you believe the relationship drifts — 0 collapses to recursive least squares (β converges and freezes), large q chases every tick; observationNoise (r) is how noisy each print is. Their RATIO is what matters. betaVariance() is the filter's own uncertainty — a hedge sized off a β the filter itself distrusts is a position, not a hedge.

Pairs workflow: hedging.CointegrationTest (is there a relationship?) → this class (what is the ratio NOW?) → OrnsteinUhlenbeck on the resulting spread (how fast does it revert?) → execution.SpreadExecutionAlgo (execute with the legging cap). O(1) per observation, allocation-free after construction, deterministic; research/warm lane.

  • Constructor Summary

    Constructors
    Constructor
    Description
    KalmanBeta(double initialBeta, double initialVariance, double processNoise, double observationNoise)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    The current intercept estimate.
    double
    The current hedge ratio estimate.
    double
    The filter's own uncertainty about β — size hedges accordingly.
    long
     
    double
    onObservation(double x, double y)
    One observation pair: y ≈ α + β·x.

    Methods inherited from class java.lang.Object

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

    • KalmanBeta

      public KalmanBeta(double initialBeta, double initialVariance, double processNoise, double observationNoise)
      Parameters:
      initialBeta - starting hedge ratio (an OLS fit is a fine seed)
      initialVariance - how much to distrust the seed, > 0
      processNoise - per-step state drift variance q, ≥ 0 (0 = the relationship never drifts: RLS)
      observationNoise - per-observation noise variance r, > 0
  • Method Details

    • onObservation

      public double onObservation(double x, double y)
      One observation pair: y ≈ α + β·x.
      Returns:
      the innovation (observation minus prediction) — the filter's own surprise, useful as a spread signal
    • alpha

      public double alpha()
      The current intercept estimate.
    • beta

      public double beta()
      The current hedge ratio estimate.
    • betaVariance

      public double betaVariance()
      The filter's own uncertainty about β — size hedges accordingly.
    • observations

      public long observations()