scripts/sweep.py --target pos sweeps the position model inference thresholds and ML active management settings. It runs OOS backtests across parameter combinations and ranks them by Score. No retraining required.
Developer/operator lane only. Regular users should run onboarding, select profile 1-5, pull approved model revisions from R2, and run trading.
Usage
# Core sweep: exit_threshold, min_prob_diff, min_bars_held (8 configs, ~5 min)
python scripts/sweep.py --target pos
# Extended sweep: + partial_close + trailing stop (13 configs, ~10 min)
python scripts/sweep.py --target pos --full
# Save results
python scripts/sweep.py --target pos --full --output results/sweep_pos_$(date +%Y%m%d).csv
Swept parameters
Core sweep (default)
| Parameter | Path | Values |
|---|
exit_threshold | ml_config.json → position_model.prediction | 0.55, 0.65, 0.70, 0.75, 0.80 |
min_prob_diff | ml_config.json → position_model.prediction | 0.10, 0.15, 0.20, 0.25 |
min_bars_held | config.json → ml_active_management.position_optimization | 2, 4, 6 |
Extended sweep (--full)
Also sweeps:
| Parameter | Path | Values |
|---|
partial_close.enabled | config.json → ml_active_management | true, false |
ml_trailing_stop.enabled | config.json → ml_active_management | true, false |
CLI flags
| Flag | Default | Description |
|---|
--full | false | Include partial_close and trailing stop combinations |
--output | auto | CSV file path for results |
--balance | 500 | Backtest balance ($) |
--leverage | 500 | Leverage |
--spread | 16.95 | Spread ($ round-turn) |
Current tuned values (Phase 15)
| Parameter | Value | Notes |
|---|
exit_threshold | 0.80 | Fires ~1 exit per 38 days |
min_prob_diff | 0.25 | EXIT must beat HOLD by 25pp |
min_bars_held | 4 | Minimum 4 M15 bars (~1h) before EXIT fires |
These were set by a 13-config sweep on 2026-04-15 (Phase 15.1). Do not change without re-running this sweep.
Interpreting results
High exit_threshold + high min_prob_diff = conservative model, few exits, lets TP-bound trades run.
Low thresholds = more exits, shorter hold times, useful only if the position model has high EXIT precision.
Check EXIT precision and ML_Exit count in the backtest output alongside WR/PF/MaxDD:
Results:
WR: 78.5% PF: 2.43 MaxDD: 1.8% Score: 21.34
ML_Exit count: 1 / 38d
Avg hold: 6.3 bars
The Phase 15 values minimize ML_Exit events, letting the signal model’s TP hit naturally (recent snapshot: 78.5% WR on 37d OOS).
Applying results
The script does not auto-apply. Edit manually:
python3 -c "
import json
ml = json.load(open('ml_config.json'))
pm = ml['position_model']['prediction']
pm['exit_threshold'] = 0.80
pm['min_prob_diff'] = 0.25
with open('ml_config.json', 'w') as f: json.dump(ml, f, indent=2)
print('Applied')
"
Run a final OOS backtest to confirm:
python backtest_config.py \
--balance 500 --no-swap --leverage 500 \
--spread 16.95 --oos-only --no-chart