feat(tradingbot): Monte-Carlo position-size sanity tester - #17
Conversation
Stress-test a fixed per-trade risk fraction against synthetic trade sequences before any capital is committed. Walks Bernoulli draws under a win-rate / payoff-ratio assumption, tracks peak-to-trough drawdown on each path, and emits p50 / p95 / p99 of the drawdown distribution. Sibling to #9 (equity-curve plotter): #9 plots a single realised curve from `logs/equity.jsonl`; this tester explores the distribution of curves a configuration could produce, so the operator can pick a risk fraction that survives the tail (p99) rather than just the mean. Stdlib only. Deterministic for a given `--seed`. 100 simulations by default; the JSON output's `p50_drawdown_pct` / `p95_drawdown_pct` / `p99_drawdown_pct` keys are monotonically non-decreasing by contract. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
This PR needs an issue link. Add |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6d1c575a0f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
This PR needs an issue link. Add |
|
This PR needs an issue link. Add |
1 similar comment
|
This PR needs an issue link. Add |
|
This PR needs an issue link. Add |
|
This PR needs an issue link. Add |
|
This PR needs an issue link. Add |
1 similar comment
|
This PR needs an issue link. Add |
Summary
monte_carlo.py(flat layout) — stdlib-only CLI that stress-tests a per-trade risk fraction against synthetic trade sequences sampled from a win-rate / payoff-ratio assumption.p50_drawdown_pct,p95_drawdown_pct,p99_drawdown_pct(monotonically non-decreasing by contract), plusworst_drawdown_pct,mean_final_equity_pct, andruined_sim_count.logs/equity.jsonl; this tester explores the distribution of curves a configuration could produce, so the operator can size for the tail (p99) instead of the mean before any capital is committed.Contract
--seed(same inputs → identical percentiles).Usage
Test plan
pytest tests/test_monte_carlo.py— 14 new tests pass (e2e percentile contract, determinism, seed fan-out, risk responsiveness, CLI smoke, 8 validation parametrizations, ruin path).Round/Tick: 2 / 5
Feature idx: 5
Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com