Class CorrelationRTIndicator
- All Implemented Interfaces:
Resettable, RTIndicator
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoubleReturns the current rolling population covariance:sumXY/n - meanX*meanY.doublegetMeanX()Returns the current rolling mean of the X series.doublegetMeanY()Returns the current rolling mean of the Y series.intbooleanisReady()Returns whether this indicator has received enough data to produce meaningful values.voidreset()doubleupdate(double newValue) Not supported — correlation requires two inputs.doubleupdate(double x, double y) Updates the indicator with a new (x, y) pair and returns the current Pearson r.Methods inherited from class AbstractRTIndicator
equals, getDisplayHint, getMeta, getValue, hashCode, hide, isPoison, setValue, toString, toString, withDisplayHint, withMeta
-
Constructor Details
-
CorrelationRTIndicator
public CorrelationRTIndicator(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
-
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. Useupdate(double, double).- Specified by:
updatein interfaceRTIndicator- Overrides:
updatein classAbstractRTIndicator- 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:
resetin interfaceResettable- Overrides:
resetin classAbstractRTIndicator
-