Class BetaRTIndicator
- All Implemented Interfaces:
Resettable, RTIndicator
Beta measures the sensitivity of an asset's returns (X) to a benchmark's returns (Y). It is defined as:
β = Cov(X, Y) / Var(Y)
Maintains two parallel WindowSeriesStore instances with four
accumulators (sumX, sumY, sumXY, sumYSq).
On eviction the X callback saves the evicted value, then the Y callback
uses it to decrement the cross-term and the Y² accumulator.
Exposes getAlpha() (Jensen's alpha: meanX - β * meanY),
getCovariance(), and mean accessors at zero extra cost.
Returns 0 when the benchmark series has zero variance.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoublegetAlpha()Returns Jensen's alpha:meanX - β * meanY.doubleReturns the current rolling population covariance between X and Y.doublegetMeanX()Returns the current rolling mean of the asset series (X).doublegetMeanY()Returns the current rolling mean of the benchmark series (Y).intbooleanisReady()Returns whether this indicator has received enough data to produce meaningful values.voidreset()doubleupdate(double newValue) Not supported — Beta requires two inputs.doubleupdate(double asset, double benchmark) Updates the indicator with a new (asset, benchmark) pair and returns the current rolling beta.Methods inherited from class AbstractRTIndicator
equals, getDisplayHint, getMeta, getValue, hashCode, hide, isPoison, setValue, toString, toString, withDisplayHint, withMeta
-
Constructor Details
-
BetaRTIndicator
public BetaRTIndicator(int periods)
-
-
Method Details
-
getPeriods
public int getPeriods() -
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
-
getMeanX
public double getMeanX()Returns the current rolling mean of the asset series (X). -
getMeanY
public double getMeanY()Returns the current rolling mean of the benchmark series (Y). -
getCovariance
public double getCovariance()Returns the current rolling population covariance between X and Y. -
getAlpha
public double getAlpha()Returns Jensen's alpha:meanX - β * meanY.The intercept of the regression line of X on Y.
-
update
public double update(double newValue) Not supported — Beta requires two inputs. Useupdate(double, double).- Specified by:
updatein interfaceRTIndicator- Overrides:
updatein classAbstractRTIndicator- Throws:
UnsupportedOperationException- always
-
update
public double update(double asset, double benchmark) Updates the indicator with a new (asset, benchmark) pair and returns the current rolling beta.- Parameters:
asset- the asset value (X)benchmark- the benchmark value (Y)
-
reset
public void reset()- Specified by:
resetin interfaceResettable- Overrides:
resetin classAbstractRTIndicator
-