Class VarianceRTIndicator
java.lang.Object
com.wualabs.qtsurfer.engine.indicators.core.AbstractRTIndicator
com.wualabs.qtsurfer.engine.indicators.core.AbstractWindowSeriesRTIndicator
com.wualabs.qtsurfer.engine.indicators.statistics.pro.VarianceRTIndicator
- All Implemented Interfaces:
Resettable, RTIndicator
Rolling variance with O(1) per-tick updates using a single window.
Maintains dual accumulators (sum and sumSq) over a single
window. On eviction both accumulators are decremented,
eliminating the need for a separate SMA object and its duplicate window.
Variance is computed via the algebraic identity:
Var(X) = E(X²) - E(X)² = sumSq/n - (sum/n)²
Population variance by default (standard for trading indicators).
Use withSampleVariance(boolean) to enable Bessel's correction.
Produces identical results to VarianceRTIndicator
(when both use the same variance type) with a single window instead of two.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoublegetMean()Returns the current rolling mean (sum / n).protected voidonEvict(double evicted) Called when the window evicts the oldest value.protected voidonReset()Called after window is cleared.doubleupdate(double newValue) withSampleVariance(boolean sampleVariance) Methods inherited from class AbstractWindowSeriesRTIndicator
getPeriods, isReady, reset, window, windowSizeMethods inherited from class AbstractRTIndicator
equals, getDisplayHint, getMeta, getValue, hashCode, hide, isPoison, setValue, toString, toString, withDisplayHint, withMeta
-
Constructor Details
-
VarianceRTIndicator
public VarianceRTIndicator(int periods)
-
-
Method Details
-
onEvict
protected void onEvict(double evicted) Description copied from class:AbstractWindowSeriesRTIndicatorCalled when the window evicts the oldest value. Override to update accumulators.- Overrides:
onEvictin classAbstractWindowSeriesRTIndicator
-
onReset
protected void onReset()Description copied from class:AbstractWindowSeriesRTIndicatorCalled after window is cleared. Override to zero accumulators.- Overrides:
onResetin classAbstractWindowSeriesRTIndicator
-
getMean
public double getMean()Returns the current rolling mean (sum / n). Useful for composing indicators (e.g. Z-Score) without duplicating state. -
withSampleVariance
-
update
public double update(double newValue) - Specified by:
updatein interfaceRTIndicator- Overrides:
updatein classAbstractRTIndicator
-