Class ValueAtRiskRTIndicator
java.lang.Object
com.wualabs.qtsurfer.engine.indicators.core.AbstractRTIndicator
com.wualabs.qtsurfer.engine.indicators.core.AbstractWindowSeriesRTIndicator
com.wualabs.qtsurfer.engine.indicators.statistics.pro.ValueAtRiskRTIndicator
- All Implemented Interfaces:
Resettable, RTIndicator
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 - meanwhere
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoubleReturns the mean log return over the current window.doubleReturns the standard deviation of log returns in the current window.doubleReturns the z-score used for the current confidence level.protected voidonEvict(double evicted) Called when the window evicts the oldest value.protected voidonReset()Called after window is cleared.doubleupdate(double price) withAnnualizationFactor(double factor) Sets the annualization factor applied to both mean and stddev.withConfidenceLevel(double confidence) Sets the confidence level (e.g. 0.95, 0.99).Methods inherited from class AbstractWindowSeriesRTIndicator
getPeriods, isReady, reset, window, windowSizeMethods inherited from class AbstractRTIndicator
equals, getDisplayHint, getMeta, getValue, hashCode, hide, isPoison, setValue, toString, toString, withDisplayHint, withMeta
-
Constructor Details
-
ValueAtRiskRTIndicator
public ValueAtRiskRTIndicator(int periods)
-
-
Method Details
-
onEvict
protected void onEvict(double evicted) Description copied from class:AbstractWindowSeriesRTIndicatorCalled when the window evicts the oldest value. Override to update accumulators.- Overrides:
onEvictin classAbstractWindowSeriesRTIndicator
-
onReset
protected void onReset()Description copied from class:AbstractWindowSeriesRTIndicatorCalled after window is cleared. Override to zero accumulators.- Overrides:
onResetin classAbstractWindowSeriesRTIndicator
-
withConfidenceLevel
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
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:
updatein interfaceRTIndicator- Overrides:
updatein classAbstractRTIndicator
-