LinearRegressionIntercept — Linear Regression Intercept
The fitted value at the window’s first bar: where the regression line starts. Paired with the slope it reconstructs the whole line, and the gap between intercept and current price is how far the window has travelled along its own trend.
Signature
LinearRegressionIntercept(period, on=<source>)| Argument | Type | Required | Notes |
|---|---|---|---|
period |
int Param or literal | Yes | Regression window. Default 14, bounds 2–400. |
on= |
symbol, OHLCV field, or indicator | No | Source. Defaults to the trade symbol’s close. |
Formula
$$ \text{intercept} = \frac{\sum C - \text{slope}\sum i}{n} $$
with i = 0 at the oldest bar in the window.
Warmup
period bars; tracks the close until then.
Reading the value
lri.valueself.trade.close - lri.value # total move along the fitted lineExample
class TrendTravel(Strategy): """Enter when the window has travelled far from where its trend began.""" trade = Symbol() sizing = FixedCapital()
def execute(self): lri = LinearRegressionIntercept(20, on=self.trade) if self.trade.close > lri.value * 1.03 and self.trade.is_flat: self.buy(self.trade, reason="Trend has covered ground") if self.trade.close < lri.value and self.trade.is_long: self.sell(self.trade, self.trade.position, reason="Back to the start of the fit")Notes
- TA-Lib LINEARREG_INTERCEPT.
- Proven by an assert-via-trade run on SPY daily (matched a strategy-side OLS intercept to 1e-3 on every bar; zero alarm trades).
- The intercept is anchored to the oldest bar in the window, so it moves as the window rolls — it is not a fixed anchor.