linreg
forge.tafunctionSince Forge API 1
Functionpython
forge.ta.linreg(source: ArrayLike, period: int = 14) -> np.ndarrayThe regression line at the newest bar of the window: a + b * (period - 1).
Parameters
| Name | Type | Default |
|---|---|---|
| source | ArrayLike | |
| period | int | 14 |
Classpython
forge.ta.LinReg(**inputs: Any) -> NoneLeast squares line fitted to the last N values, read at the newest bar.
Inputs
| Name | Type | Default | Range |
|---|---|---|---|
| source | source | close | |
| period | int | 14 | 2 to 5000 |
Fit a straight line by least squares to the last period values, with t = 0 at the oldest.
b = (period * sum(t*y) - sum(t) * sum(y)) / (period * sum(t^2) - sum(t)^2)
a = (sum(y) - b * sum(t)) / period
LinReg = a + b * (period - 1)