Class YangZhangVolatilityRTIndicator

java.lang.Object
com.wualabs.qtsurfer.engine.indicators.core.AbstractRTIndicator
com.wualabs.qtsurfer.engine.indicators.statistics.pro.volatility.YangZhangVolatilityRTIndicator
All Implemented Interfaces:
Resettable, RTIndicator

public class YangZhangVolatilityRTIndicator extends AbstractRTIndicator
Yang-Zhang Volatility estimator with O(1) per-tick updates.

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) * σ²_RS
where:
  • σ²_overnight = sample variance of ln(Open_i / Close_{i-1})
  • σ²_close-open = sample variance of ln(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 Details

    • YangZhangVolatilityRTIndicator

      public YangZhangVolatilityRTIndicator(int periods)
  • Method Details

    • getPeriods

      public int getPeriods()
    • isReady

      public boolean isReady()
      Description copied from interface: RTIndicator
      Returns 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 returns true, the indicator's output is statistically valid.

      The default implementation returns true for 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:
      true if the indicator has completed its warmup period
    • withAnnualizationFactor

      public YangZhangVolatilityRTIndicator withAnnualizationFactor(double factor)
      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. Use update(double, double, double, double).
      Specified by:
      update in interface RTIndicator
      Overrides:
      update in class AbstractRTIndicator
      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:
      reset in interface Resettable
      Overrides:
      reset in class AbstractRTIndicator