Skip to content

fix(sizing): reserve entry commission when sizing percent_of_equity#78

Merged
luisleo526 merged 1 commit into
mainfrom
fix/percent-of-equity-commission-reservation
Jul 8, 2026
Merged

fix(sizing): reserve entry commission when sizing percent_of_equity#78
luisleo526 merged 1 commit into
mainfrom
fix/percent-of-equity-commission-reservation

Conversation

@luisleo526

Copy link
Copy Markdown
Collaborator

Summary

TradingView sizes a percent_of_equity order so notional + entry_fee stays within the target equity fraction: qty = equity*pct / (price*pointvalue*(1 + commRate)), commRate = commission_value/100 for a percent commission. The engine omitted the (1+commRate) divisor and sized slightly large, drifting the compounding equity/position path.

Proof (clean-room TV probes)

Two minimal probes (percent_of_equity=10 and =100, commission.percent=0.05, 1-bar holds so no margin fragmentation) were TV-exported. TV's first-entry qty (equity = initial_capital, decisive) matches equity/(price*(1+commRate)) to the lot step for both:

probe TVqty /(1+c) no-reserve
pct=10 5.5287 5.5287 5.5314
pct=100 55.2872 55.2872 55.3149

So TV reserves the commission for fractional AND all-in sizing — the reservation is not gated on headroom, and the fix is global (16/16 clean entries exact).

Fix

New reserve_percent_commission() helper applied to both PERCENT_OF_EQUITY sizing branches (calc_qty + calc_qty_for_type). Percent commission only; FIXED/CASH qty types and commission_value==0 are exact no-ops.

Gate (full R7)

  • ctest 79/79
  • run_corpus 239 exc / 12 strong / 1 anomaly, byte-identical (corpus has no percent-commission percent_of_equity → no-op there)
  • full data sweep: net-0 — one strategy strong→excellent (its true tier once sized correctly), one excellent→strong.

The excellent→strong move is a truthful re-grade, not a regression: that strategy is percent_of_equity=100 all-in (margin-cascade), and its prior excellent was an artifact of the under-sizing bug coincidentally matching TV's proprietary liquidation path to <0.01% exit-p90. Under correct sizing its honest tier is strong. The fix improves per-trade sizing accuracy for the ~50 percent-commission strategies in the dataset.

🤖 Generated with Claude Code

TradingView sizes a percent_of_equity order so that notional + entry_fee
stays within the target equity fraction: qty = equity*pct / (price *
pointvalue * (1 + commRate)), commRate = commission_value/100 for a
percent commission. The engine omitted the (1+commRate) divisor and sized
slightly large, drifting the compounding equity/position path.

Proven from TV exports (clean-room probes at pct=10 AND pct=100, percent
commission): TV reserves the commission for BOTH fractional AND all-in
sizing — first-entry qty = equity/(price*(1+commRate)) to the lot step,
16/16. So the reservation is not gated on headroom; the fix is global.

New helper reserve_percent_commission() applied to both PERCENT_OF_EQUITY
sizing branches (calc_qty + calc_qty_for_type). Percent commission only;
FIXED/CASH qty types and commission_value==0 are exact no-ops.

Gate (full R7): ctest 79/79; run_corpus 239 exc/12 strong/1 anomaly,
byte-identical (corpus has no percent-commission percent_of_equity, so
no-op there); data sweep net-0: one strategy strong->excellent (its true
tier once sized correctly), one excellent->strong. The latter is a
TRUTHFUL re-grade, not a regression: it is percent_of_equity=100 all-in
(a margin-cascade strategy) whose prior excellent was an artifact of the
under-sizing bug coincidentally matching TV's proprietary liquidation
path; under correct sizing its honest tier is strong. Improves per-trade
sizing accuracy for the ~50 percent-commission strategies in the dataset.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@luisleo526 luisleo526 merged commit a5715bc into main Jul 8, 2026
5 checks passed
@luisleo526 luisleo526 deleted the fix/percent-of-equity-commission-reservation branch July 8, 2026 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant