TSF — Time Series Forecast
תוכן זה אינו זמין עדיין בשפה שלך.
The least-squares regression line extended one bar ahead: what the fit predicts the next close
will be. Leads LSMA by exactly one slope-step.
Signature
TSF(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{TSF} = \text{intercept} + \text{slope},n $$
(LSMA evaluates the same line at n-1.)
Warmup
period bars; the raw close until the window fills.
Reading the value
tsf.valuetsf.value > self.trade.closeExample
class ForecastGap(Strategy): """Enter when the forecast sits meaningfully above the current close.""" trade = Symbol() sizing = FixedCapital()
def execute(self): tsf = TSF(14, on=self.trade) if tsf.value > self.trade.close * 1.01 and self.trade.is_flat: self.buy(self.trade, reason="Forecast above price") if tsf.value < self.trade.close and self.trade.is_long: self.sell(self.trade, self.trade.position, reason="Forecast rolled over")Notes
- Standard time series forecast (TA-Lib TSF).
- A forecast, not a prophecy: it is the straight-line extension of the last
nbars, so it is exactly as good as the assumption that the trend continues. - 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).