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+10.242%
Net profit$102,424
Gross profit$506,732
Gross loss$403,200
CAGR+1.385%
Annualized return+1.385%
Monthly average return+0.159%
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.284
Log return CAGR+27.816%
Compounded vs simple return difference-6.405%

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

What this shows: Normalized strategy equity versus benchmark path, with optional buy/sell markers when signal timestamps are available.

How to read it: Track whether the strategy line stays above benchmark through stress periods and whether entries/exits align with major swings.

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

What this shows: The panels below break risk and return into drawdown, rolling quality metrics, return distribution, and optional trade diagnostics.

How to read it: Read them together: a strategy with good total return but unstable rolling Sharpe or deep drawdown concentration may be less robust.

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+20.296%
Net profit$202,960
Gross profit$531,850
Gross loss$318,580
CAGR+5.666%
Annualized return+5.666%
Monthly average return+0.482%
Median monthly return+3.446%
Best month return+13.941%
Worst month return-9.315%
Rolling 1-month return+20.976%
Return per trade+1.095
Log return CAGR+57.050%
Compounded vs simple return difference-0.679%

Risk & trade diagnostics

Drawdown and rolling Sharpe for one symbol at a time appear in the equity charts above. This section adds strategy-specific views: how each index run for linear-regression-slope sits in risk–return space, engine stop / take-profit settings when present, and per-trade MAE/MFE when OHLC trade stats exist in the JSON. Older static portfolio PNGs aggregated every strategy; these plots are scoped to this strategy only.

Stop loss / take-profit (this run)

These rules were applied when opening positions: fixed stop and take-profit prices from entry (backtesting.py sl / tp), plus an optional maximum hold in bars. They change realized outcomes versus signal-only exits; curves and metrics on this page already reflect them.

Stop loss
5%
Take profit
10%
Max hold

SL/TP combinations (this strategy)

These are strategy-specific SL/TP combinations from the sensitivity sweep. The best Sharpe combination is highlighted.

Best Sharpe combo: SL 5% / TP 10% (0.41)

SLTPSharpeReturnMax DDWin %
5%10%0.4120.30%19.65%41.18%
7%10%0.4020.64%19.38%41.18%
5%0%0.3518.28%19.65%41.18%
5%5%0.3412.07%11.21%47.06%
7%0%0.3418.70%19.38%41.18%
0%10%0.3417.40%21.53%41.18%
3%0%0.2913.87%19.74%35.29%
0%0%0.2815.52%21.53%41.18%
5%15%0.2713.51%19.65%41.18%
7%15%0.2713.91%19.38%41.18%
7%5%0.248.41%13.65%47.06%
0%15%0.2110.86%21.53%41.18%
3%15%0.219.29%19.74%35.29%
3%5%0.206.20%10.97%41.18%
3%10%0.208.74%19.74%35.29%
0%5%0.155.52%15.95%47.06%

Performance with these rules (symbol by symbol)

Each row is one run for linear-regression-slope. Values already include the stop / target / max-hold settings shown in the row.

SymbolStop lossTake profitMax holdTotal returnSharpeMax DD
^AXJO (S&P/ASX 200)5%10%-10.35%-0.4719.20%
^BSESN (BSE Sensex)5%10%-6.97%-0.1823.81%
^BVSP (Bovespa)5%10%10.43%0.2219.30%
^DJI (Dow Jones Industrial Average)5%10%5.36%0.1515.25%
^FCHI (CAC 40)5%10%-7.97%-0.2324.56%
^FTSE (FTSE 100)5%10%8.25%0.2811.84%
^GDAXI (DAX)5%10%-8.85%-0.2018.02%
^GSPC (S&P 500)5%10%20.30%0.4819.65%
^GSPTSE (TSX Composite)5%10%7.86%0.288.80%
^HSI (Hang Seng)5%10%-13.41%-0.2432.35%
^IXIC (NASDAQ Composite)5%10%-17.04%-0.4036.73%
^KS11 (KOSPI)5%10%28.23%0.5115.90%
^MERV (Merval)5%10%117.00%1.2314.50%
^N100 (Euronext 100)5%10%-3.90%-0.1220.59%
^N225 (Nikkei 225)5%10%9.38%0.1628.41%
^NSEI (Nifty 50)5%10%-4.88%-0.1221.93%
^RUT (Russell 2000)5%10%2.96%0.0525.67%
^SSMI (Swiss Market)5%10%1.27%0.0518.90%
^STOXX50E (Euro Stoxx 50)5%10%-5.81%-0.1520.13%
^TWII (Taiwan Weighted)5%10%73.00%1.0513.39%

Cross-symbol risk: Sharpe vs max drawdown (this strategy)

One point per index run. X = worst drawdown magnitude (%), Y = Sharpe ratio. Compare how stable the edge is across regions — unlike the site-wide risk report PNGs, this uses only runs for linear-regression-slope.

Trade path: MAE vs MFE

Symbol:
Avg MAE: -3.05%Avg MFE: 4.75%MFE / MAE: 1.56

Each point is one trade: MAE = worst unrealized loss vs entry during the trade; MFE = best unrealized gain. Sample capped in JSON for payload size. With SL/TP enabled, many trades stop out before reaching prior MFE extremes — compare to metrics in the table above.

Strategy comparison

Performance Comparison

Compare variants: other parameter variations of the same base strategy.

MetricLinear Regression SlopeLinear Regression Reversion
Return & Growth
Total return+10.242%+10.989%
Net profit$102,424$109,888
Gross profit$506,732$245,759
Gross loss$403,200$138,574
CAGR+1.385%+2.803%
Annualized return+1.385%+2.803%
Monthly average return+0.159%+0.231%
Median monthly return+0.470%+0.814%
Best month return+9.494%+9.249%
Worst month return-9.360%-5.025%
Rolling 1-month return+15.665%+11.946%
Return per trade+0.284+0.686
Log return CAGR+27.816%+17.473%
Compounded vs simple return difference-6.405%-0.000%
Risk & Drawdown
Maximum drawdown+20.446%+11.025%
Average drawdown+9.925%+4.919%
Median drawdown-7.660%-3.909%
Drawdown duration (max)814.638 days924.503 days
Average drawdown duration39.099 days55.241 days
Ulcer index10.4455.597
Pain index7.6034.108
Pain ratio2.2357.367
Drawdown volatility4.6992.974
Worst peak-to-trough loss+20.446%+11.025%
% time in drawdown+86.733%+87.807%
Drawdown area682.592647.686
Downside deviation+13.377%+16.378%
Semi-variance1.9391.178
Risk-Adjusted Ratios
Sharpe ratio0.1180.325
Rolling 1-month Sharpe1.4291.588
Sortino ratio0.2280.731
Calmar ratio0.1250.351
Sterling ratio0.1250.351
Burke ratio0.2050.338
Return / volatility0.9841.421
Return / downside risk0.8130.792
Return / max drawdown0.8051.440
Trade-Level Statistics
Total trades2314
Win rate+36.538%+64.634%
Loss rate+63.461%+35.366%
Average win+5.963%+2.619%
Average loss-2.800%-2.833%
Win/Loss ratio2.1771.007
Expectancy+0.412%+0.749%
Profit factor1.3322.139
Payoff ratio2.1771.007
Median trade return (approx avg)+0.284%+0.686%
Best trade+11.252%+7.843%
Worst trade-6.546%-5.185%
Trade return standard deviation+3.308%+1.851%
Consecutive wins (max)34
Consecutive losses (max)63
% breakeven trades+0.179%+0.000%
Avg MAE %-3.454%-2.177%
Avg MFE %+4.091%+3.025%
MFE/MAE ratio1.3641.461
Avg R-multiple1.9388.604
R-multiple std5.56323.005
Distribution & Shape
Volatility (annualized)+11.000%+7.376%
Benchmark (Beta, Alpha, IR)
Beta to benchmark0.1160.078
Alpha vs benchmark %-0.499%+1.279%
Information ratio-0.804-0.791
Treynor ratio0.0380.130

Parameter optimization

Parameter optimization

Linear Regression Slope on ^GSPC. Objective: Sharpe Ratio. 4 runs. Metric:

Results by region

Index Performance Statistics

Performance metrics for each index symbol tested with this strategy.

IndexCountryReturn %SharpeSortinoMax DD %Win Rate %TradesProfit FactorVolatility %
MervalArgentina+117.00%1.232.42+14.50%+56.52%234.25+11.87%
S&P/ASX 200Australia-10.35%-0.47-0.55+19.20%+29.41%170.62+9.26%
BovespaBrazil+10.43%0.220.32+19.30%+42.86%281.28+9.00%
TSX CompositeCanada+7.86%0.280.38+8.80%+41.18%171.35+7.88%
Euro Stoxx 50Europe-5.81%-0.15-0.23+20.13%+35.00%200.88+13.35%
Euronext 100Europe-3.90%-0.12-0.18+20.59%+31.82%220.96+10.59%
CAC 40France-7.97%-0.23-0.35+24.56%+23.81%210.79+12.13%
DAXGermany-8.85%-0.20-0.33+18.02%+26.32%190.87+15.45%
Hang SengHong Kong-13.41%-0.24-0.35+32.35%+30.00%300.85+12.08%
BSE SensexIndia-6.97%-0.18-0.23+23.81%+28.57%280.91+8.14%
Nifty 50India-4.88%-0.12-0.16+21.93%+26.67%300.96+8.40%
Nikkei 225Japan+9.38%0.160.24+28.41%+34.38%321.22+11.32%
KOSPISouth Korea+28.23%0.510.77+15.90%+41.94%311.68+9.73%
Swiss MarketSwitzerland+1.27%0.050.06+18.90%+35.29%171.11+9.08%
Taiwan WeightedTaiwan+73.00%1.051.82+13.39%+50.00%282.64+10.05%
FTSE 100UK+8.25%0.280.45+11.84%+28.57%211.40+9.15%
Dow Jones Industrial AverageUS+5.36%0.150.19+15.25%+55.00%201.31+10.54%
NASDAQ CompositeUS-17.04%-0.40-0.42+36.73%+29.41%170.75+14.39%
Russell 2000US+2.96%0.050.07+25.67%+42.86%211.15+16.51%
S&P 500US+20.30%0.480.65+19.65%+41.18%171.67+11.07%