Class CovarianceRTIndicator

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

public class CovarianceRTIndicator extends AbstractRTIndicator
Rolling population covariance with O(1) per-tick updates.

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

Population covariance is computed via:

  Cov(X,Y) = sumXY/n - (sumX/n) * (sumY/n)

Leaner than CorrelationRTIndicator — omits the per-series squared accumulators (sumXSq, sumYSq) needed only for the Pearson r denominator.

Use withSampleCovariance(boolean) to enable Bessel's correction (dividing by n-1 instead of n).

  • Constructor Details

    • CovarianceRTIndicator

      public CovarianceRTIndicator(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
    • withSampleCovariance

      public CovarianceRTIndicator withSampleCovariance(boolean sampleCovariance)
      Enables Bessel's correction: divide by n-1 instead of n.
    • getMeanX

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

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

      public double update(double newValue)
      Not supported — covariance 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 x, double y)
      Updates the indicator with a new (x, y) pair and returns the current covariance.
    • reset

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