LinearRegressionCurve — Linear Regression Curve
The fitted regression value plotted at each bar. Numerically identical to LSMA; it ships
under both names because charting platforms use both, and a strategy reading “the regression
curve” should find it by that name.
Signature
LinearRegressionCurve(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{value}_t = \text{intercept}_t + \text{slope}_t,(n-1) $$
recomputed on each bar’s window.
Warmup
period bars; the raw close until the window fills.
Reading the value
lrc.valueself.trade.close > lrc.valueExample
class RegressionBaseline(Strategy): """Trade around the regression curve as a fair-value line.""" trade = Symbol() sizing = FixedCapital()
def execute(self): lrc = LinearRegressionCurve(20, on=self.trade) if self.trade.close < lrc.value * 0.97 and self.trade.is_flat: self.buy(self.trade, reason="Below the fit") if self.trade.close > lrc.value and self.trade.is_long: self.sell(self.trade, self.trade.position, reason="Back at the fit")Notes
- Same computation as
LSMA(different default period). Pick one name and stay with it inside a strategy. - Proven by an assert-via-trade run on SPY daily (matched a strategy-side OLS reference to 1e-3 on every bar; zero alarm trades).
- For the slope or fit quality, use
LinearRegressionSlopeorLinearRegression.