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.
Standard Deviation Bands place bands at SMA ± k standard deviations (identical to Bollinger Bands but used here for mean-reversion). Enters long at the lower band, exits at the midline.
class StdDevBands(Strategy):
n = 20; k = 2
def init(self):
upper, mid, lower = _std_bands(self.data.Close, self.n, self.k)
self.mid = self.I(lambda: mid, name="Mid")
self.lower = self.I(lambda: lower, name="Lower")
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 | +30.331% |
| Net profit | $303,307 |
| Gross profit | $527,447 |
| Gross loss | $244,799 |
| CAGR | +7.742% |
| Annualized return | +7.742% |
| Monthly average return | +0.613% |
| Median monthly return | +2.750% |
| Best month return | +12.340% |
| Worst month return | -3.582% |
| Rolling 1-month return | +16.050% |
| Return per trade | +1.333 |
| Log return CAGR | +50.893% |
| Compounded vs simple return difference | -5.139% |
19 trades · green dashes = buy entries · red dashes = sell exits
| Total return | +23.818% |
| Net profit | $238,180 |
| Gross profit | $437,570 |
| Gross loss | $207,800 |
| CAGR | +6.635% |
| Annualized return | +6.635% |
| Monthly average return | +0.502% |
| Median monthly return | +2.476% |
| Best month return | +5.581% |
| Worst month return | -1.801% |
| Rolling 1-month return | +13.534% |
| Return per trade | +1.134 |
| Log return CAGR | +31.611% |
| Compounded vs simple return difference | +0.000% |