Class AutocorrelationRTIndicator

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

public class AutocorrelationRTIndicator extends AbstractRTIndicator
Rolling Lag-1 Autocorrelation with O(1) per-tick updates.

Measures the Pearson correlation between consecutive log returns within a rolling window — a key signal for mean-reversion vs momentum:

  • Positive autocorrelation → momentum (trending)
  • Negative autocorrelation → mean-reversion
  • Near zero → random walk

Given a window of returns [r₀, r₁, ..., r_{n-1}], forms n-1 consecutive pairs (rᵢ, rᵢ₋₁) and computes their Pearson correlation using five accumulators: sumX, sumY, sumXY, sumXSq, sumYSq over the pairs.

On window roll, the oldest return is evicted and its pair (r₁, r₀) is removed from the accumulators. The new pair (rₙ, rₙ₋₁) is added. This yields O(1) per tick.

Requires periods >= 4 (minimum for meaningful correlation with 3+ pairs). Returns 0 when fewer than 3 pairs exist or when either series has zero variance.

  • Constructor Details

    • AutocorrelationRTIndicator

      public AutocorrelationRTIndicator(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
    • getPairCount

      public int getPairCount()
      Returns the number of pairs in the current window.
    • reset

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

      public double update(double price)
      Specified by:
      update in interface RTIndicator
      Overrides:
      update in class AbstractRTIndicator