Class VarianceRTIndicator
java.lang.Object
com.wualabs.qtsurfer.engine.indicators.core.AbstractRTIndicator
com.wualabs.qtsurfer.engine.indicators.core.AbstractIncrementalRTIndicator
com.wualabs.qtsurfer.engine.indicators.core.AbstractDecorableIncrementalRTIndicator
com.wualabs.qtsurfer.engine.indicators.statistics.VarianceRTIndicator
- All Implemented Interfaces:
ClockAware, Resettable, RTIndicator
Variance RTIndicator
In periodic mode, computes rolling variance in O(1) per tick using the algebraic identity
Var(X) = E(X²) - E(X)², maintaining a running sum of squares with rolling eviction.
-
Constructor Summary
ConstructorsConstructorDescriptionVarianceRTIndicator(int periods) VarianceRTIndicator(RTIndicator indicator) VarianceRTIndicator(RTIndicator indicator, int periods) -
Method Summary
Modifier and TypeMethodDescriptiongetSma()protected doublenextValue(double prevValue, double newValue) Non-periodic (2-period) variance: running average of squared deviations.voidreset()protected doubletickValue(int tick, boolean init, boolean endPeriod, double newValue) Periodic variance computation using O(1) incremental sum-of-squares tracking.withAverageSample(boolean averageSample) Methods inherited from class AbstractDecorableIncrementalRTIndicator
getIndicator, setClockSupplier, updateMethods inherited from class AbstractIncrementalRTIndicator
getLastUpdateValue, getPeriodCycles, getPeriods, getPrevValue, initValue, isPeriodic, isReady, prevNextValue, setPeriodsMethods inherited from class AbstractRTIndicator
equals, getDisplayHint, getMeta, getValue, hashCode, hide, isPoison, setValue, toString, toString, withDisplayHint, withMeta
-
Constructor Details
-
VarianceRTIndicator
public VarianceRTIndicator() -
VarianceRTIndicator
public VarianceRTIndicator(int periods) -
VarianceRTIndicator
-
VarianceRTIndicator
-
-
Method Details
-
reset
public void reset()- Specified by:
resetin interfaceResettable- Overrides:
resetin classAbstractDecorableIncrementalRTIndicator
-
withAverageSample
-
tickValue
protected double tickValue(int tick, boolean init, boolean endPeriod, double newValue) Periodic variance computation using O(1) incremental sum-of-squares tracking. Maintains a runningsumSq = Σx²that is updated on each add and adjusted on window eviction. Variance is computed asVar = sumSq/n - mean²(population) or with Bessel's correction(sumSq - n×mean²)/(n-1)(sample). Returns 0 until the first complete period.- Overrides:
tickValuein classAbstractIncrementalRTIndicator- Parameters:
tick- current tick within the periodinit- true on the very first updateendPeriod- true when this tick completes a periodnewValue- the new input value- Returns:
- the computed variance, or 0 if insufficient data
-
nextValue
protected double nextValue(double prevValue, double newValue) Non-periodic (2-period) variance: running average of squared deviations.- Overrides:
nextValuein classAbstractDecorableIncrementalRTIndicator- Parameters:
prevValue- the previous variance valuenewValue- the new input value- Returns:
- the smoothed variance
-
getSma
-