Class ValueAtRiskRTIndicator

All Implemented Interfaces:
Resettable, RTIndicator

public class ValueAtRiskRTIndicator extends AbstractWindowSeriesRTIndicator
Rolling parametric (Gaussian) Value at Risk with O(1) per-tick updates.

Estimates the worst expected loss at a given confidence level assuming normally-distributed log returns:

  VaR = -(mean - z * stddev) = z * stddev - mean
where z is the inverse-normal quantile for the confidence level (e.g. 1.6449 for 95%, 2.3263 for 99%).

A positive VaR represents a potential loss. Maintains dual accumulators (sumR, sumRSq) over a single window for O(1) mean/variance computation. The first tick establishes the initial price.

Default confidence level is 95%. Configurable via withConfidenceLevel(double). Supports annualization via withAnnualizationFactor(double).

  • Constructor Details

    • ValueAtRiskRTIndicator

      public ValueAtRiskRTIndicator(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
    • withConfidenceLevel

      public ValueAtRiskRTIndicator withConfidenceLevel(double confidence)
      Sets the confidence level (e.g. 0.95, 0.99).

      Internally converts to the corresponding z-score via an approximation of the inverse normal CDF.

    • withAnnualizationFactor

      public ValueAtRiskRTIndicator withAnnualizationFactor(double factor)
      Sets the annualization factor applied to both mean and stddev.

      For daily returns: mean is scaled by factor, stddev by sqrt(factor). Default is 1.0 (no annualization).

    • getMeanReturn

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

      public double getStdDev()
      Returns the standard deviation of log returns in the current window.
    • getZScore

      public double getZScore()
      Returns the z-score used for the current confidence level.
    • update

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