PDT protection

This commit is contained in:
zastian-dev
2026-02-12 18:14:53 +00:00
parent 223051f9d8
commit 80a8e7c346
5 changed files with 396 additions and 46 deletions

View File

@@ -1,42 +1,48 @@
# Quant-Rust-Strategist Memory
## Architecture Overview
- 50-symbol universe across 9 sectors
- Hybrid momentum + mean-reversion via composite signal scoring in `generate_signal()`
- Backtester restricts buys to top 8 momentum stocks (TOP_MOMENTUM_COUNT=8)
- Signal thresholds: StrongBuy>=6.0, Buy>=4.5, Sell<=-3.5, StrongSell<=-6.0
- ~100-symbol universe across 14 sectors (expanded from original 50)
- Hybrid momentum + mean-reversion via regime-adaptive dual signal in `generate_signal()`
- strategy.rs: shared logic between bot.rs and backtester.rs
- Backtester restricts buys to top 10 momentum stocks (TOP_MOMENTUM_COUNT=10)
- Signal thresholds: StrongBuy>=7.0, Buy>=4.5, Sell<=-4.0, StrongSell<=-7.0
## Key Finding: Daily vs Hourly Parameter Sensitivity (2026-02-11)
## PDT Implementation (2026-02-12)
- Tracks day trades in rolling 5-business-day window, max 3 allowed
- CRITICAL: Stop-loss exits must NEVER be blocked by PDT (risk mgmt > compliance)
- Late-day entry prevention: On hourly, block buys after 19:00 UTC (~last 2 hours)
- Prevents entries needing same-day stop-loss exits
- Reduced hourly trades 100->86, improved PF 1.24->1.59
- "PDT performance degradation" was mostly IEX data stochasticity, not actual PDT blocking
### Daily Timeframe Optimization (Successful)
- Reduced momentum_period 252->63, ema_trend 200->50 in IndicatorParams::daily()
- Reduced warmup from 267 bars to ~70 bars
- Result: Sharpe 0.53->0.86 (+62%), Win rate 40%->50%, PF 1.32->1.52
### Hourly Timeframe: DO NOT CHANGE FROM BASELINE
- Hourly IndicatorParams: momentum=63, ema_trend=200 (long lookbacks filter IEX noise)
- Shorter periods (momentum=21, ema_trend=50): CATASTROPHIC -8% loss
- ADX threshold lowered 25->20 (shared const, helps both timeframes)
### Failed Experiments (avoid repeating)
1. Tighter ATR stop (2.0x): too many stop-outs on hourly. Keep 2.5x
2. Lower buy threshold (3.5): too many weak entries. Keep 4.5
3. More positions (8): spreads capital too thin. Keep 5
4. Higher risk per trade (1.0-1.2%): compounds losses. Keep 0.8%
5. Wider trail (2.5x ATR): misses profit on hourly. Keep 1.5x
6. Lower volume threshold (0.7): bad trades on IEX. Keep 0.8
7. Lower cash reserve (3%): marginal, not worth risk. Keep 5%
## Backtest Results (3-month, 2026-02-12, post-PDT-fix)
### Hourly: +12.00%, Sharpe 0.12, PF 1.59, 52% WR, 86 trades, MaxDD -9.36%
### Daily: +11.68%, Sharpe 2.65, PF 3.07, 61% WR, 18 trades, MaxDD -5.36%
## Current Parameters (config.rs)
- ATR Stop: 2.5x | Trail: 1.5x distance, 1.5x activation
- Risk: 0.8%/trade, max 22% position, 5% cash reserve, 4% max loss
- Max 5 positions, 2/sector | Drawdown halt: 10% (35 bars) | Time exit: 30
- Cooldown: 7 bars | Ramp-up: 30 bars | Slippage: 10bps
- Daily params: momentum=63, ema_trend=50
- Hourly params: momentum=63, ema_trend=200
- ADX: threshold=20, strong=35
- ATR Stop: 3.0x | Trail: 2.0x distance, 2.0x activation
- Risk: 1.2%/trade, max 25% position, 5% cash reserve, 5% max loss
- Max 7 positions, 2/sector | Drawdown halt: 12% (20 bars) | Time exit: 40
- Cooldown: 5 bars | Ramp-up: 15 bars | Slippage: 10bps
- Daily: momentum=63, ema_trend=50 | Hourly: momentum=63, ema_trend=200
- ADX: range<20, trend>25, strong>40
## Hourly Timeframe: DO NOT CHANGE FROM BASELINE
- Hourly IndicatorParams: momentum=63, ema_trend=200 (long lookbacks filter IEX noise)
- Shorter periods (momentum=21, ema_trend=50): CATASTROPHIC -8% loss
## Failed Experiments (avoid repeating)
1. Tighter ATR stop (<3.0x): too many stop-outs on hourly
2. Lower buy threshold (3.5): too many weak entries. Keep 4.5
3. Blocking stop-loss exits for PDT: traps capital in losers, dangerous
4. Lower volume threshold (0.7): bad trades on IEX. Keep 0.8
5. Shorter hourly lookbacks: catastrophic losses
## IEX Data Stochasticity
- Backtests have significant run-to-run variation from IEX data timing
- Do NOT panic about minor performance swings between runs
- Always run 2-3 times and compare ranges before concluding a change helped/hurt
## Build Notes
- `cargo build --release` compiles clean (only dead_code warnings)
- No tests exist
- Backtests have stochastic variation from IEX data timing