Skip to main content
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)

ParameterPathValues
exit_thresholdml_config.json → position_model.prediction0.55, 0.65, 0.70, 0.75, 0.80
min_prob_diffml_config.json → position_model.prediction0.10, 0.15, 0.20, 0.25
min_bars_heldconfig.json → ml_active_management.position_optimization2, 4, 6

Extended sweep (--full)

Also sweeps:
ParameterPathValues
partial_close.enabledconfig.json → ml_active_managementtrue, false
ml_trailing_stop.enabledconfig.json → ml_active_managementtrue, false

CLI flags

FlagDefaultDescription
--fullfalseInclude partial_close and trailing stop combinations
--outputautoCSV file path for results
--balance500Backtest balance ($)
--leverage500Leverage
--spread16.95Spread ($ round-turn)

Current tuned values (Phase 15)

ParameterValueNotes
exit_threshold0.80Fires ~1 exit per 38 days
min_prob_diff0.25EXIT must beat HOLD by 25pp
min_bars_held4Minimum 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