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 Bollinger Bands (SMA ± k standard deviations). Enters long when price touches or breaks below the lower band, expecting a reversion to the mean. Exits when price reaches the upper band.
class BollingerBands(Strategy):
n = 20
k = 2
def init(self):
close = self.data.Close
self.upper = self.I(_bb_upper, close, self.n, self.k)
self.lower = self.I(_bb_lower, 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.upper[-1] and self.position:
self.position.close()