Strategy
This strategy is backtested on daily OHLCV price data across major US equity indices and ETFs. Entry and exit signals are generated from the strategy's indicators with no lookahead bias — trades execute at the open of the bar following the signal.
Performance metrics are computed per symbol and shown individually. The parameter optimization section (where available) runs a grid search over the strategy's key parameters, optimizing for Sharpe ratio. Transaction costs and slippage are not modeled.
The signal logic and indicator code for this strategy is shown in the methodology code section below.
Mean-reversion using linear regression bands. Enters long when price falls below the lower regression band (statistically cheap), exits when price returns to the regression midline.
class LinearRegressionReversion(Strategy):
n = 20
k = 2
def init(self):
self.upper = self.I(_lr_upper, self.data.Close, self.n, self.k)
self.mid = self.I(_lr_mid, self.data.Close, self.n)
self.lower = self.I(_lr_lower, self.data.Close, self.n, self.k)
def next(self):
if self.data.Close[-1] <= self.lower[-1] and not self.position:
self.buy()
elif self.data.Close[-1] >= self.mid[-1] and self.position:
self.position.close()| Total return | +11.048% |
| Net profit | $110,484 |
| Gross profit | $245,759 |
| Gross loss | $138,004 |
| CAGR | +2.852% |
| Annualized return | +2.852% |
| Monthly average return | +0.233% |
| Median monthly return | +0.818% |
| Best month return | +9.249% |
| Worst month return | -5.044% |
| Rolling 1-month return | +11.946% |
| Return per trade | +0.693 |
| Log return CAGR | +17.556% |
| Compounded vs simple return difference | +0.000% |
19 trades · green dashes = buy entries · red dashes = sell exits
| Total return | +16.570% |
| Net profit | $165,700 |
| Gross profit | $331,780 |
| Gross loss | $167,900 |
| CAGR | +4.719% |
| Annualized return | +4.719% |
| Monthly average return | +0.363% |
| Median monthly return | +2.298% |
| Best month return | +11.294% |
| Worst month return | -8.759% |
| Rolling 1-month return | +14.790% |
| Return per trade | +0.813 |
| Log return CAGR | +25.352% |
| Compounded vs simple return difference | +0.000% |