Class CovarianceRTIndicator
- All Implemented Interfaces:
Resettable, RTIndicator
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoublegetMeanX()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 — covariance requires two inputs.doubleupdate(double x, double y) Updates the indicator with a new (x, y) pair and returns the current covariance.withSampleCovariance(boolean sampleCovariance) Enables Bessel's correction: divide byn-1instead ofn.Methods inherited from class AbstractRTIndicator
equals, getDisplayHint, getMeta, getValue, hashCode, hide, isPoison, setValue, toString, toString, withDisplayHint, withMeta
-
Constructor Details
-
CovarianceRTIndicator
public CovarianceRTIndicator(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
-
withSampleCovariance
Enables Bessel's correction: divide byn-1instead ofn. -
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. 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 covariance. -
reset
public void reset()- Specified by:
resetin interfaceResettable- Overrides:
resetin classAbstractRTIndicator
-