Class EwmaVolatilityRTIndicator
- All Implemented Interfaces:
Resettable, RTIndicator
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 monthly0.99— slow decay for longer-horizon estimates
Annualization is supported via withAnnualizationFactor(double).
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an EWMA Volatility indicator with the RiskMetrics default λ = 0.94.EwmaVolatilityRTIndicator(double lambda) Creates an EWMA Volatility indicator with the specified decay factor. -
Method Summary
Modifier and TypeMethodDescriptiondoubleReturns the current EWMA variance (squared volatility, before annualization).doublebooleanisReady()Returns whether this indicator has received enough data to produce meaningful values.voidreset()doubleupdate(double price) 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
-
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: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.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:
resetin interfaceResettable- Overrides:
resetin classAbstractRTIndicator
-
update
public double update(double price) - Specified by:
updatein interfaceRTIndicator- Overrides:
updatein classAbstractRTIndicator
-