Class BetaRTIndicator

java.lang.Object
com.wualabs.qtsurfer.engine.indicators.core.AbstractRTIndicator
com.wualabs.qtsurfer.engine.indicators.statistics.pro.BetaRTIndicator
All Implemented Interfaces:
Resettable, RTIndicator

public class BetaRTIndicator extends AbstractRTIndicator
Rolling Beta coefficient with O(1) per-tick updates.

Beta measures the sensitivity of an asset's returns (X) to a benchmark's returns (Y). It is defined as:

  β = Cov(X, Y) / Var(Y)

Maintains two parallel WindowSeriesStore instances with four accumulators (sumX, sumY, sumXY, sumYSq). On eviction the X callback saves the evicted value, then the Y callback uses it to decrement the cross-term and the Y² accumulator.

Exposes getAlpha() (Jensen's alpha: meanX - β * meanY), getCovariance(), and mean accessors at zero extra cost.

Returns 0 when the benchmark series has zero variance.

  • Constructor Details

    • BetaRTIndicator

      public BetaRTIndicator(int periods)
  • Method Details

    • getPeriods

      public int getPeriods()
    • isReady

      public boolean isReady()
      Description copied from interface: RTIndicator
      Returns whether this indicator has received enough data to produce meaningful values.

      During the warmup period, RTIndicator.getValue() may return 0 or a partial estimate that should not be used for trading decisions. Once this method returns true, the indicator's output is statistically valid.

      The default implementation returns true for backward compatibility. Indicators with warmup requirements should override this method.

      For composite indicators (e.g. Bollinger Bands, MACD), readiness is determined by the slowest internal component.

      Returns:
      true if the indicator has completed its warmup period
    • getMeanX

      public double getMeanX()
      Returns the current rolling mean of the asset series (X).
    • getMeanY

      public double getMeanY()
      Returns the current rolling mean of the benchmark series (Y).
    • getCovariance

      public double getCovariance()
      Returns the current rolling population covariance between X and Y.
    • getAlpha

      public double getAlpha()
      Returns Jensen's alpha: meanX - β * meanY.

      The intercept of the regression line of X on Y.

    • update

      public double update(double newValue)
      Not supported — Beta requires two inputs. Use update(double, double).
      Specified by:
      update in interface RTIndicator
      Overrides:
      update in class AbstractRTIndicator
      Throws:
      UnsupportedOperationException - always
    • update

      public double update(double asset, double benchmark)
      Updates the indicator with a new (asset, benchmark) pair and returns the current rolling beta.
      Parameters:
      asset - the asset value (X)
      benchmark - the benchmark value (Y)
    • reset

      public void reset()
      Specified by:
      reset in interface Resettable
      Overrides:
      reset in class AbstractRTIndicator