Class CorrelationRTIndicator

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

public class CorrelationRTIndicator extends AbstractRTIndicator
Rolling Pearson Correlation coefficient with O(1) per-tick updates.

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

Pearson r is computed via:

  r = (n*sumXY - sumX*sumY) / sqrt((n*sumXSq - sumX^2) * (n*sumYSq - sumY^2))

Returns 0 when either series has zero variance (denominator ≤ 0). Clamps result to [-1, 1] for floating-point safety.

  • Constructor Details

    • CorrelationRTIndicator

      public CorrelationRTIndicator(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 X series.
    • getMeanY

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

      public double getCovariance()
      Returns the current rolling population covariance: sumXY/n - meanX*meanY.
    • update

      public double update(double newValue)
      Not supported — correlation 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 Pearson r.
    • reset

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