fix(sizing): reserve entry commission when sizing percent_of_equity#78
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TradingView sizes a
percent_of_equityorder sonotional + entry_feestays within the target equity fraction:qty = equity*pct / (price*pointvalue*(1 + commRate)),commRate = commission_value/100for 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=10and=100,commission.percent=0.05, 1-bar holds so no margin fragmentation) were TV-exported. TV's first-entry qty (equity = initial_capital, decisive) matchesequity/(price*(1+commRate))to the lot step for both:/(1+c)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 bothPERCENT_OF_EQUITYsizing branches (calc_qty+calc_qty_for_type). Percent commission only;FIXED/CASHqty types andcommission_value==0are exact no-ops.Gate (full R7)
run_corpus239 exc / 12 strong / 1 anomaly, byte-identical (corpus has no percent-commissionpercent_of_equity→ no-op there)The excellent→strong move is a truthful re-grade, not a regression: that strategy is
percent_of_equity=100all-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