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
| Parameter | Type | Default | Bounds or options | Description |
|---|---|---|---|---|
| Time Period | integer | 14 | 2…100000 | Number of closing-price observations used for each least-squares regression. |
Outputs
| Output | Type | Description |
|---|---|---|
| Linear Regression | number | Fitted 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
- Interpreting the endpoint fit as next-period prediction.
- Assuming a good visual line implies stable future behavior.
- Comparing outputs from different windows or timeframe durations.
- 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.