Statistic functions

Linear Regression

Endpoint value of a rolling least-squares regression line.

Engine
TA-Lib
Function
LINEARREG
Input series
close
Outputs
1

How it works

LINEARREG fits a least-squares line to each close window using bar positions 0 through timeperiod-1 and returns the fitted value at the window's final position.

Use case

Use Linear Regression as a responsive rolling trend baseline or to measure deviations from the fitted endpoint value.

Parameters

ParameterTypeDefaultBounds or optionsDescription
Time Periodinteger142…100000Number of closing-price observations used for each least-squares regression.

Outputs

OutputTypeDescription
Linear RegressionnumberFitted regression-line value at the final position of the rolling window.

Reading the result

Linear Regression returns the fitted value at the end of a rolling least-squares line. It is a local model of the selected historical window, not a forecast of a future bar.

The distance between close and the fitted value can describe local deviation from a linear trend. The fitted line can still be a poor summary when the window contains curvature, structural breaks, or large outliers.

Common mistakes

  1. Interpreting the endpoint fit as next-period prediction.
  2. Assuming a good visual line implies stable future behavior.
  3. Comparing outputs from different windows or timeframe durations.
  4. Ignoring sensitivity to outliers and provider revisions.

DataCat workflow notes

Pair the fitted endpoint with Linear Regression Slope when both local level and trend steepness are needed. Any residual or fit-quality metric should be derived explicitly downstream rather than inferred from the endpoint alone.

Resources

Search documentation

Search across 46 documentation pages.