Class SimpleLinearRegressionRTIndicator
java.lang.Object
com.wualabs.qtsurfer.engine.indicators.core.AbstractRTIndicator
com.wualabs.qtsurfer.engine.indicators.core.AbstractWindowSeriesRTIndicator
com.wualabs.qtsurfer.engine.indicators.statistics.pro.SimpleLinearRegressionRTIndicator
- All Implemented Interfaces:
Resettable, RTIndicator
Full rolling OLS regression with O(1) per-tick updates.
Fits a least-squares line to the last n values using x-positions
0, 1, ..., n-1. Returns the slope as the primary value, with
accessors for all regression statistics:
getSlope()— rate of change per tick (=AbstractRTIndicator.getValue())getIntercept()— y-intercept of the fitted linegetRSquared()— coefficient of determination (goodness of fit)getStandardError()— standard error of the estimategetMean()— rolling mean of y valuesforecast(int)— project the regression line forward
Maintains three accumulators (sumY, sumYSq, sumXY)
over a single window. The x-axis constants (sumX,
sumXSq, denom) are precomputed and constant once the window
is full.
R² is computed as:
SSreg = (n*sumXY - sumX*sumY)² / denom SStot = n*sumYSq - sumY² R² = SSreg / SStot
Standard Error is:
SE = sqrt((SStot - SSreg) / (n * (n - 2)))
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoubleforecast(int ahead) Projects the regression line forward.doubleReturns the y-intercept:meanY - slope * meanX.doublegetMean()Returns the current rolling mean of y values.doubleReturns the coefficient of determination (R²).doublegetSlope()Returns the slope (same asAbstractRTIndicator.getValue()).doubleReturns the standard error of the estimate.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
-
SimpleLinearRegressionRTIndicator
public SimpleLinearRegressionRTIndicator(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
-
getSlope
public double getSlope()Returns the slope (same asAbstractRTIndicator.getValue()). -
getMean
public double getMean()Returns the current rolling mean of y values. -
getIntercept
public double getIntercept()Returns the y-intercept:meanY - slope * meanX. -
getRSquared
public double getRSquared()Returns the coefficient of determination (R²).Measures how well the linear fit explains the variance in y. R² = 1 means perfect linear fit; R² = 0 means no linear relationship. Returns 0 when the window has fewer than 2 values or y is constant.
-
getStandardError
public double getStandardError()Returns the standard error of the estimate.SE = sqrt(SSres / (n - 2))whereSSres = SStot - SSreg. Returns 0 when window has fewer than 3 values. -
forecast
public double forecast(int ahead) Projects the regression line forward.forecast = intercept + slope * (n - 1 + ahead) -
update
public double update(double newValue) - Specified by:
updatein interfaceRTIndicator- Overrides:
updatein classAbstractRTIndicator
-