Class YangZhangVolatilityRTIndicator
- All Implemented Interfaces:
Resettable, RTIndicator
Combines overnight (close-to-open), open-to-close, and Rogers-Satchell variance components into the most efficient OHLC-based estimator, ~14x more efficient than close-to-close (Yang & Zhang 2000).
The Yang-Zhang variance is:
σ²_YZ = σ²_overnight + k * σ²_close-open + (1 - k) * σ²_RSwhere:
σ²_overnight= sample variance ofln(Open_i / Close_{i-1})σ²_close-open= sample variance ofln(Close_i / Open_i)σ²_RS= Rogers-Satchell variance (population)k = 0.34 / (1.34 + (n+1)/(n-1))
Maintains three parallel WindowSeriesStore instances with five
accumulators (sumO, sumOSq, sumC, sumCSq,
sumRS). The first OHLC bar establishes the initial close —
computation starts from the second bar.
Annualization is supported via withAnnualizationFactor(double).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintdoubleReturns the current Yang-Zhang variance (squared volatility, before annualization).booleanisReady()Returns whether this indicator has received enough data to produce meaningful values.voidreset()doubleupdate(double newValue) Not supported — Yang-Zhang requires OHLC inputs.doubleupdate(double open, double high, double low, double close) Updates the indicator with a new OHLC bar and returns the current Yang-Zhang volatility.withAnnualizationFactor(double factor) Sets the annualization factor.Methods inherited from class AbstractRTIndicator
equals, getDisplayHint, getMeta, getValue, hashCode, hide, isPoison, setValue, toString, toString, withDisplayHint, withMeta
-
Constructor Details
-
YangZhangVolatilityRTIndicator
public YangZhangVolatilityRTIndicator(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
-
withAnnualizationFactor
Sets the annualization factor. The output is multiplied by this factor. -
getYangZhangVariance
public double getYangZhangVariance()Returns the current Yang-Zhang variance (squared volatility, before annualization). -
update
public double update(double newValue) Not supported — Yang-Zhang 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 Yang-Zhang volatility. -
reset
public void reset()- Specified by:
resetin interfaceResettable- Overrides:
resetin classAbstractRTIndicator
-