Class EwmaVolatilityRTIndicator

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

public class EwmaVolatilityRTIndicator extends AbstractRTIndicator
EWMA (Exponentially Weighted Moving Average) Volatility with O(1) per-tick updates.

Implements the RiskMetrics (JP Morgan 1996) approach to volatility estimation. Unlike rolling-window estimators, EWMA uses exponential decay to weight recent observations more heavily, requiring no window storage.

The EWMA variance is updated recursively:

  σ²_t = λ * σ²_{t-1} + (1 - λ) * r²_t
where r_t = ln(price_t / price_{t-1}) is the log return and λ (lambda) is the decay factor.

The first tick establishes the initial price — no return is produced. The variance is seeded with the first squared return (r²_1).

Maintains only three state variables: prevPrice, variance, and a tick counter — the most memory-efficient volatility estimator in the module.

Common lambda values:

  • 0.94 — RiskMetrics daily (default)
  • 0.97 — RiskMetrics monthly
  • 0.99 — slow decay for longer-horizon estimates

Annualization is supported via withAnnualizationFactor(double).

  • Constructor Details

    • EwmaVolatilityRTIndicator

      public EwmaVolatilityRTIndicator(double lambda)
      Creates an EWMA Volatility indicator with the specified decay factor.
      Parameters:
      lambda - the decay factor (0 < λ < 1). Higher values give more weight to historical observations.
      Throws:
      IllegalArgumentException - if lambda is not in (0, 1)
    • EwmaVolatilityRTIndicator

      public EwmaVolatilityRTIndicator()
      Creates an EWMA Volatility indicator with the RiskMetrics default λ = 0.94.
  • Method Details

    • getLambda

      public double getLambda()
    • 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 EwmaVolatilityRTIndicator withAnnualizationFactor(double factor)
      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)
    • getEwmaVariance

      public double getEwmaVariance()
      Returns the current EWMA variance (squared volatility, before annualization).
    • reset

      public void reset()
      Specified by:
      reset in interface Resettable
      Overrides:
      reset in class AbstractRTIndicator
    • update

      public double update(double price)
      Specified by:
      update in interface RTIndicator
      Overrides:
      update in class AbstractRTIndicator