Class AutocorrelationRTIndicator
- All Implemented Interfaces:
Resettable, RTIndicator
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 Summary
Constructors -
Method Summary
Methods inherited from class AbstractRTIndicator
equals, getDisplayHint, getMeta, getValue, hashCode, hide, isPoison, setValue, toString, toString, withDisplayHint, withMeta
-
Constructor Details
-
AutocorrelationRTIndicator
public AutocorrelationRTIndicator(int periods)
-
-
Method Details
-
getPeriods
public int getPeriods() -
isReady
public boolean isReady()Description copied from interface:RTIndicatorReturns 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 returnstrue, the indicator's output is statistically valid.The default implementation returns
truefor 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:
trueif 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:
resetin interfaceResettable- Overrides:
resetin classAbstractRTIndicator
-
update
public double update(double price) - Specified by:
updatein interfaceRTIndicator- Overrides:
updatein classAbstractRTIndicator
-