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 the Stochastic oscillator (%K and %D). Enters long when %K crosses above %D in oversold territory (below 20). Exits when %K crosses below %D in overbought territory (above 80).
class StochasticReversion(Strategy):
n = 14
d = 3
def init(self):
k_vals = _stoch_k(self.data.High, self.data.Low, self.data.Close, self.n)
self.stoch_k = self.I(lambda: k_vals, name="K")
self.stoch_d = self.I(_stoch_d, k_vals, self.d)
def next(self):
if self.stoch_k[-1] > self.stoch_d[-1] and self.stoch_k[-1] < 20 and not self.position:
self.buy()
elif self.stoch_k[-1] < self.stoch_d[-1] and self.stoch_k[-1] > 80 and self.position:
self.position.close()| Total return | +20.502% |
| Net profit | $205,018 |
| Gross profit | $500,715 |
| Gross loss | $298,140 |
| CAGR | +5.212% |
| Annualized return | +5.212% |
| Monthly average return | +0.438% |
| Median monthly return | +1.236% |
| Best month return | +11.484% |
| Worst month return | -7.052% |
| Rolling 1-month return | +18.513% |
| Return per trade | +1.499 |
| Log return CAGR | +39.949% |
| Compounded vs simple return difference | -4.270% |
12 trades · green dashes = buy entries · red dashes = sell exits
| Total return | +24.669% |
| Net profit | $246,690 |
| Gross profit | $529,400 |
| Gross loss | $267,170 |
| CAGR | +6.855% |
| Annualized return | +6.855% |
| Monthly average return | +0.555% |
| Median monthly return | +1.785% |
| Best month return | +18.387% |
| Worst month return | -10.090% |
| Rolling 1-month return | +27.668% |
| Return per trade | +1.861 |
| Log return CAGR | +37.621% |
| Compounded vs simple return difference | -0.000% |