Class RealizedVolatilityRTIndicator

All Implemented Interfaces:
Resettable, RTIndicator

public class RealizedVolatilityRTIndicator extends AbstractWindowSeriesRTIndicator
Rolling Realized Volatility with O(1) per-tick updates.

Computes the standard deviation of log returns over a rolling window. Each tick produces a log return r = ln(price / prevPrice), which is stored in the window. Dual accumulators (sumR and sumRSq) maintain the running variance of these returns.

Realized volatility is computed as:

  RV = sqrt(sumRSq/n - (sumR/n)^2)

The first tick establishes the initial price — no return is produced, so the window starts filling from the second tick onward.

Annualization is supported via withAnnualizationFactor(double). Common factors: sqrt(252) for daily, sqrt(52) for weekly, sqrt(365*24*60) for per-minute crypto data. When set, the output is RV * factor.

  • Constructor Details

    • RealizedVolatilityRTIndicator

      public RealizedVolatilityRTIndicator(int periods)
  • Method Details

    • onEvict

      protected void onEvict(double evicted)
      Description copied from class: AbstractWindowSeriesRTIndicator
      Called when the window evicts the oldest value. Override to update accumulators.
      Overrides:
      onEvict in class AbstractWindowSeriesRTIndicator
    • onReset

      protected void onReset()
      Description copied from class: AbstractWindowSeriesRTIndicator
      Called after window is cleared. Override to zero accumulators.
      Overrides:
      onReset in class AbstractWindowSeriesRTIndicator
    • withAnnualizationFactor

      public RealizedVolatilityRTIndicator 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)
      • Math.sqrt(52) — weekly bars
    • getMeanReturn

      public double getMeanReturn()
      Returns the current mean log return over the window.
    • getRealizedVariance

      public double getRealizedVariance()
      Returns the current realized variance (squared realized volatility, before annualization).
    • update

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