Class GarmanKlassVolatilityRTIndicator
java.lang.Object
com.wualabs.qtsurfer.engine.indicators.core.AbstractRTIndicator
com.wualabs.qtsurfer.engine.indicators.core.AbstractWindowSeriesRTIndicator
com.wualabs.qtsurfer.engine.indicators.statistics.pro.volatility.GarmanKlassVolatilityRTIndicator
- All Implemented Interfaces:
Resettable, RTIndicator
Garman-Klass Volatility estimator with O(1) per-tick updates.
Uses the full OHLC bar to estimate volatility, incorporating both the high-low range and the open-close movement. Garman & Klass (1980) showed this estimator is ~7.4x more efficient than the classical close-to-close estimator, and more efficient than Parkinson's range-based estimator because it also captures overnight drift.
The Garman-Klass variance for each bar is:
GK_i = 0.5 * ln(H_i / L_i)² - (2 * ln(2) - 1) * ln(C_i / O_i)²
The rolling estimator averages over n bars:
σ² = (1/n) * Σ GK_i
Maintains a single accumulator (sumGK) over a
window storing per-bar GK values.
On eviction the accumulator is decremented.
Annualization is supported via withAnnualizationFactor(double).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoubleReturns the current Garman-Klass variance (squared volatility, before annualization).protected voidonEvict(double evicted) Called when the window evicts the oldest value.protected voidonReset()Called after window is cleared.doubleupdate(double newValue) Not supported — Garman-Klass requires OHLC inputs.doubleupdate(double open, double high, double low, double close) Updates the indicator with a new OHLC bar and returns the current Garman-Klass volatility.withAnnualizationFactor(double factor) Sets the annualization factor.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
-
GarmanKlassVolatilityRTIndicator
public GarmanKlassVolatilityRTIndicator(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
-
withAnnualizationFactor
Sets the annualization factor. The output is multiplied by this factor.Common values:
Math.sqrt(252)— daily bars (trading days/year)Math.sqrt(365)— daily bars (calendar days/year)
-
getGarmanKlassVariance
public double getGarmanKlassVariance()Returns the current Garman-Klass variance (squared volatility, before annualization). -
update
public double update(double newValue) Not supported — Garman-Klass requires OHLC inputs. Useupdate(double, double, double, double).- Specified by:
updatein interfaceRTIndicator- Overrides:
updatein classAbstractRTIndicator- Throws:
UnsupportedOperationException- always
-
update
public double update(double open, double high, double low, double close) Updates the indicator with a new OHLC bar and returns the current Garman-Klass volatility.
-