Skip to content

feat(tradingbot): Monte-Carlo position-size sanity tester - #17

Merged
wranngle merged 8 commits into
mainfrom
feat/monte-carlo-position-sizer
May 19, 2026
Merged

feat(tradingbot): Monte-Carlo position-size sanity tester#17
wranngle merged 8 commits into
mainfrom
feat/monte-carlo-position-sizer

Conversation

@wranngle

Copy link
Copy Markdown
Owner

Summary

  • New 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.
  • 100 seeded simulations by default; output JSON includes p50_drawdown_pct, p95_drawdown_pct, p99_drawdown_pct (monotonically non-decreasing by contract), plus worst_drawdown_pct, mean_final_equity_pct, and ruined_sim_count.
  • Sibling to feat(tradingbot): equity-curve JSONL emit + SVG plotter #9 (equity-curve JSONL + SVG plotter): feat(tradingbot): equity-curve JSONL emit + SVG 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 size for the tail (p99) instead of the mean before any capital is committed.

Contract

  • Deterministic for a given --seed (same inputs → identical percentiles).
  • Drawdown percentiles monotonically non-decreasing.
  • Riskier position sizes produce strictly worse p99 drawdown (responsiveness check).
  • Input validation rejects out-of-range risk / win-rate / payoff / trades / sims.

Usage

python monte_carlo.py --risk 0.02 --win-rate 0.55 --payoff 1.8 \
  --trades 250 --sims 100 --seed 42

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).
  • Full suite green: 37 passed (14 new + 23 existing, no regressions).
  • CLI smoke: default config emits p50=13.19% / p95=19.92% / p99=25.39% — monotonic.

Round/Tick: 2 / 5
Feature idx: 5

Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com

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>
@github-actions github-actions Bot added the pr-needs-issue PR has no Closes/Fixes/Resolves reference; auto-applied by pr-link-check label May 15, 2026
@github-actions

Copy link
Copy Markdown

This PR needs an issue link.

Add Closes #N / Fixes #N / Resolves #N to the description — or file an issue first via gh-issue.sh. Convention: every PR has an audit trail back to a problem statement.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread monte_carlo.py
Comment thread monte_carlo.py
Comment thread monte_carlo.py
@github-actions

Copy link
Copy Markdown

This PR needs an issue link.

Add Closes #N / Fixes #N / Resolves #N to the description — or file an issue first via gh-issue.sh. Convention: every PR has an audit trail back to a problem statement.

@wranngle
wranngle enabled auto-merge (squash) May 19, 2026 03:04
@github-actions

Copy link
Copy Markdown

This PR needs an issue link.

Add Closes #N / Fixes #N / Resolves #N to the description — or file an issue first via gh-issue.sh. Convention: every PR has an audit trail back to a problem statement.

1 similar comment
@github-actions

Copy link
Copy Markdown

This PR needs an issue link.

Add Closes #N / Fixes #N / Resolves #N to the description — or file an issue first via gh-issue.sh. Convention: every PR has an audit trail back to a problem statement.

@github-actions

Copy link
Copy Markdown

This PR needs an issue link.

Add Closes #N / Fixes #N / Resolves #N to the description — or file an issue first via gh-issue.sh. Convention: every PR has an audit trail back to a problem statement.

@github-actions

Copy link
Copy Markdown

This PR needs an issue link.

Add Closes #N / Fixes #N / Resolves #N to the description — or file an issue first via gh-issue.sh. Convention: every PR has an audit trail back to a problem statement.

@github-actions

Copy link
Copy Markdown

This PR needs an issue link.

Add Closes #N / Fixes #N / Resolves #N to the description — or file an issue first via gh-issue.sh. Convention: every PR has an audit trail back to a problem statement.

1 similar comment
@github-actions

Copy link
Copy Markdown

This PR needs an issue link.

Add Closes #N / Fixes #N / Resolves #N to the description — or file an issue first via gh-issue.sh. Convention: every PR has an audit trail back to a problem statement.

@wranngle
wranngle merged commit 6d2d9f3 into main May 19, 2026
11 checks passed
@wranngle
wranngle deleted the feat/monte-carlo-position-sizer branch May 19, 2026 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-needs-issue PR has no Closes/Fixes/Resolves reference; auto-applied by pr-link-check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant