Class TreynorRatioRTIndicator
- All Implemented Interfaces:
Resettable, RTIndicator
Measures risk-adjusted return using systematic risk (beta) instead of total risk (standard deviation):
Treynor = (meanAssetReturn - riskFreeRate) / betawhere
beta = Cov(X, Y) / Var(Y), X = asset log returns,
Y = benchmark log returns.
Dual-input indicator: call update(double, double) with
(asset price, benchmark price). Internally computes log returns and
maintains two parallel WindowSeriesStore instances with four
accumulators (sumX, sumY, sumXY, sumYSq).
Returns 0 when beta is zero or when window has fewer than 2 returns.
Configurable risk-free rate via withRiskFreeRate(double) and
annualization via withAnnualizationFactor(double).
Exposes getBeta(), getMeanReturn(), and
getMeanBenchmarkReturn() accessors.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoublegetBeta()Returns the current rolling beta (Cov(X,Y) / Var(Y)).doubleReturns the mean log return of the benchmark over the current window.doubleReturns the mean log return of the asset over the current window.intbooleanisReady()Returns whether this indicator has received enough data to produce meaningful values.voidreset()doubleupdate(double newValue) Not supported — Treynor requires two inputs.doubleupdate(double assetPrice, double benchmarkPrice) Updates with a new (asset price, benchmark price) pair and returns the current rolling Treynor Ratio.withAnnualizationFactor(double factor) Sets the annualization factor.withRiskFreeRate(double rate) Sets the per-period risk-free rate.Methods inherited from class AbstractRTIndicator
equals, getDisplayHint, getMeta, getValue, hashCode, hide, isPoison, setValue, toString, toString, withDisplayHint, withMeta
-
Constructor Details
-
TreynorRatioRTIndicator
public TreynorRatioRTIndicator(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
-
withRiskFreeRate
Sets the per-period risk-free rate. Default is 0. -
withAnnualizationFactor
Sets the annualization factor. Mean return is scaled by this factor. Default is 1.0 (no annualization). -
getMeanReturn
public double getMeanReturn()Returns the mean log return of the asset over the current window. -
getMeanBenchmarkReturn
public double getMeanBenchmarkReturn()Returns the mean log return of the benchmark over the current window. -
getBeta
public double getBeta()Returns the current rolling beta (Cov(X,Y) / Var(Y)). -
update
public double update(double newValue) Not supported — Treynor requires two inputs. Useupdate(double, double).- Specified by:
updatein interfaceRTIndicator- Overrides:
updatein classAbstractRTIndicator- Throws:
UnsupportedOperationException- always
-
update
public double update(double assetPrice, double benchmarkPrice) Updates with a new (asset price, benchmark price) pair and returns the current rolling Treynor Ratio. -
reset
public void reset()- Specified by:
resetin interfaceResettable- Overrides:
resetin classAbstractRTIndicator
-