Skip to content

Add ZHMeanReversionStrategy ported from ZH-trading repo#82

Open
ZhuRong818 wants to merge 3 commits into
mlsys-io:mainfrom
ZhuRong818:main
Open

Add ZHMeanReversionStrategy ported from ZH-trading repo#82
ZhuRong818 wants to merge 3 commits into
mlsys-io:mainfrom
ZhuRong818:main

Conversation

@ZhuRong818
Copy link
Copy Markdown

  • Port the mean reversion strategy from
    [ZH-trading/strategies/v2/meanrev.py](https://github.com/Z
    huRong818/ZH-trading/blob/main/strategies/v2/meanrev.py)
    to freqtrade IStrategy interface for backtesting
  • Register the strategy in benchmark_all.py for
    inclusion in the full benchmark suite
  • Strategy buys when price drops below rolling mean by
    entry_threshold, exits on reversion to mean, with
    dynamic stoploss via stop_multiple

Logic Mapping

ZH-trading PortfolioBench (backtest)
MarketContext.mid_price dataframe["close"]
np.mean(prices[-window:]) close.rolling(20).mean()
deviation < -entry_threshold → BUY enter_long = 1
mid >= moving_avg - exit_threshold → EXIT exit_long = 1
kelly_size() freqtrade default stake (Kelly-compatible params)
stop = mid - abs(dev) * stop_multiple custom_stoploss returns -entry_threshold × stop_multiple
Category Timeframe Return Sharpe Trades Win Rate Max DD
crypto 5m +0.67% 15.22 46 65.2% 0.57%
crypto 4h +0.16% 3.90 3 100% 0.0%
crypto 1d +0.23% 0.05 12 58.3% 0.30%
stocks 5m -2.57% -45.91 48 39.6% 2.95%
stocks 4h +0.21% 1.40 4 75.0% 0.11%
stocks 1d +0.16% 0.04 13 53.8% 0.29%
indices 5m -0.11% -2.65 20 50.0% 0.42%
indices 4h +0.27% 4.77 3 100% 0.0%
indices 1d -0.18% -0.04 9 44.4% 0.32%
mixed 5m +0.55% 14.19 21 66.7% 0.23%
mixed 4h 0.00% 0 0 0.0%
mixed 1d +0.31% 0.10 6 66.7% 0.11%

Key findings:

  • Best performance on crypto 5m (Sharpe 15.2, 65% win
    rate) — matches the strategy's original design for
    high-frequency mean reversion on volatile assets
  • Decent on longer-term stocks/indices (4h/1d) with
    positive returns but few trades
  • Poor on stocks 5m — intraday stocks trend rather
    than mean-revert

ZhuRong818 and others added 3 commits May 13, 2026 11:42
Port the mean reversion strategy from ZH-trading/strategies/v2/meanrev.py
to freqtrade IStrategy interface for backtesting. Buys when price drops
below rolling mean by entry_threshold, exits on reversion. Includes
dynamic stoploss via stop_multiple and Kelly-compatible parameter space.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The workflow subcommand (mlsys-io#10) introduced a positional argument that
crashed the CLI argument parser on every command. This was fixed
upstream in mlsys-io/freqtrade#11. Update the submodule pointer
from ab093ff to 2607696.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Upgrade from pure mean reversion to hybrid strategy with multi-signal
confirmation. Adds Bollinger Band lower band touch, RSI oversold, and
volume spike as entry filters, plus trailing stop for better exits.

Key results vs v1:
- Stocks 5m: -2.57% → -1.13%, win rate 40% → 56%
- Indices 5m: -0.11% → +0.18% (turned profitable)
- Stocks 1d: win rate 54% → 75%
- Mixed 1d: win rate 67% → 88%

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant