Class LinearRegressionSlopeRTIndicator
java.lang.Object
com.wualabs.qtsurfer.engine.indicators.core.AbstractRTIndicator
com.wualabs.qtsurfer.engine.indicators.core.AbstractWindowSeriesRTIndicator
com.wualabs.qtsurfer.engine.indicators.statistics.pro.LinearRegressionSlopeRTIndicator
- All Implemented Interfaces:
Resettable, RTIndicator
Rolling Linear Regression Slope with O(1) per-tick updates.
Fits a least-squares line to the last n values using x-positions
0, 1, ..., n-1. The slope measures the rate of change per tick.
Maintains two accumulators (sumY and sumXY) over a single
window. The denominator n*sumXSq - sumX^2 is
constant once the window is full, so the per-tick cost is O(1).
Rolling update when the window evicts oldest value y0 and adds yNew:
sumXY = sumXY - sumY + evicted + (n-1) * newValue sumY = sumY - evicted + newValue slope = (n * sumXY - sumX * sumY) / denom
The shift identity: when all values move one index down, each value's
x-contribution decreases by 1, so Sigma(i*yi) decreases by Sigma(yi).
Bonus accessors at zero extra cost:
getIntercept()— y-intercept of the fitted linegetMean()— rolling mean of the windowforecast(int)— project the regression line forward
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoubleforecast(int ahead) Projects the regression line forward byaheadticks beyond the last value in the window.doubleReturns the y-intercept of the fitted regression line.doublegetMean()Returns the current rolling mean (sumY / n).protected voidonEvict(double evicted) Called when the window evicts the oldest value.protected voidonReset()Called after window is cleared.doubleupdate(double newValue) 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
-
LinearRegressionSlopeRTIndicator
public LinearRegressionSlopeRTIndicator(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
-
getMean
public double getMean()Returns the current rolling mean (sumY / n). -
getIntercept
public double getIntercept()Returns the y-intercept of the fitted regression line.intercept = meanY - slope * meanX -
forecast
public double forecast(int ahead) Projects the regression line forward byaheadticks beyond the last value in the window.forecast = intercept + slope * (n - 1 + ahead)- Parameters:
ahead- number of ticks ahead (1 = next tick)
-
update
public double update(double newValue) - Specified by:
updatein interfaceRTIndicator- Overrides:
updatein classAbstractRTIndicator
-