Linear Regression Slope

← strategies

Strategy

Methodology

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.

Methodology

Fits a linear regression line to the last N closes and uses the slope as a trend signal. Enters long when slope turns positive (upward trend), exits when slope turns negative. Provides a statistically clean trend measure.

Implementation

class LinearRegressionSlope(Strategy):
    n = 20

    def init(self):
        self.slope = self.I(_linear_reg_slope, self.data.Close, self.n)

    def next(self):
        if self.slope[-1] > 0 and self.slope[-2] <= 0 and not self.position:
            self.buy()
        elif self.slope[-1] < 0 and self.position:
            self.position.close()

Performance metrics

Total return+9.615%
Net profit$96,153
Gross profit$503,749
Gross loss$399,265
CAGR+1.318%
Annualized return+1.318%
Monthly average return+0.153%
Median monthly return+0.470%
Best month return+9.494%
Worst month return-9.360%
Rolling 1-month return+15.665%
Return per trade+0.292
Log return CAGR+27.816%
Compounded vs simple return difference-5.778%

Equity curves

Chart for symbol:

Charts & distributions

2024-09 → 2026-04 · 5-year daily data

Equity curve vs ^GSPC — buy/sell signals

Strategy equityIndex (normalized)▲ Buy▼ Sell

17 trades · green dashes = buy entries · red dashes = sell exits

Drawdown (underwater)

Rolling 1-month Sharpe

Rolling 1-month return (%)

Period return (≈ monthly)

Return distribution (bar returns)

MAE vs MFE (trades)

Rolling 12m Beta

Rolling 12m correlation

Monthly returns (run)

Performance Matrix

Total return+18.084%
Net profit$180,840
Gross profit$512,430
Gross loss$318,580
CAGR+5.126%
Annualized return+5.126%
Monthly average return+0.438%
Median monthly return+3.446%
Best month return+13.941%
Worst month return-9.315%
Rolling 1-month return+20.976%
Return per trade+0.984
Log return CAGR+57.050%
Compounded vs simple return difference+1.533%