Class SharpeRatioRTIndicator
java.lang.Object
com.wualabs.qtsurfer.engine.indicators.core.AbstractRTIndicator
com.wualabs.qtsurfer.engine.indicators.core.AbstractWindowSeriesRTIndicator
com.wualabs.qtsurfer.engine.indicators.statistics.pro.ratios.SharpeRatioRTIndicator
- All Implemented Interfaces:
Resettable, RTIndicator
Rolling Sharpe Ratio with O(1) per-tick updates.
Computes the risk-adjusted return over a rolling window of log returns:
Sharpe = (meanReturn - riskFreeRate) / stddev(returns)
Each tick produces a log return r = ln(price / prevPrice).
Dual accumulators (sumR and sumRSq) maintain the running
variance of these returns. The first tick establishes the initial price.
The risk-free rate defaults to 0 (excess returns). Set via
withRiskFreeRate(double) — should be expressed per period
(e.g. daily rate for daily data).
Annualization is supported via withAnnualizationFactor(double).
The standard annualized Sharpe is Sharpe * sqrt(periodsPerYear).
Returns 0 when standard deviation is zero or window has fewer than 2 returns.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoubleReturns the current mean log return over the window.doubleReturns the current standard deviation of log returns over the window.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.withRiskFreeRate(double rate) Sets the per-period risk-free rate.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
-
SharpeRatioRTIndicator
public SharpeRatioRTIndicator(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
-
withRiskFreeRate
Sets the per-period risk-free rate. Default is 0.For example, if using daily bars and the annual risk-free rate is 5%, set this to
0.05 / 252. -
withAnnualizationFactor
Sets the annualization factor. The output is multiplied by this factor.Common values:
Math.sqrt(252)— daily barsMath.sqrt(52)— weekly barsMath.sqrt(12)— monthly bars
-
getMeanReturn
public double getMeanReturn()Returns the current mean log return over the window. -
getStdDev
public double getStdDev()Returns the current standard deviation of log returns over the window. -
update
public double update(double price) - Specified by:
updatein interfaceRTIndicator- Overrides:
updatein classAbstractRTIndicator
-