Class TreynorRatioRTIndicator

java.lang.Object
com.wualabs.qtsurfer.engine.indicators.core.AbstractRTIndicator
com.wualabs.qtsurfer.engine.indicators.statistics.pro.ratios.TreynorRatioRTIndicator
All Implemented Interfaces:
Resettable, RTIndicator

public class TreynorRatioRTIndicator extends AbstractRTIndicator
Rolling Treynor Ratio with O(1) per-tick updates.

Measures risk-adjusted return using systematic risk (beta) instead of total risk (standard deviation):

  Treynor = (meanAssetReturn - riskFreeRate) / beta
where 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 Details

    • TreynorRatioRTIndicator

      public TreynorRatioRTIndicator(int periods)
  • Method Details

    • getPeriods

      public int getPeriods()
    • isReady

      public boolean isReady()
      Description copied from interface: RTIndicator
      Returns 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 returns true, the indicator's output is statistically valid.

      The default implementation returns true for 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:
      true if the indicator has completed its warmup period
    • withRiskFreeRate

      public TreynorRatioRTIndicator withRiskFreeRate(double rate)
      Sets the per-period risk-free rate. Default is 0.
    • withAnnualizationFactor

      public TreynorRatioRTIndicator withAnnualizationFactor(double factor)
      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. Use update(double, double).
      Specified by:
      update in interface RTIndicator
      Overrides:
      update in class AbstractRTIndicator
      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:
      reset in interface Resettable
      Overrides:
      reset in class AbstractRTIndicator