Skip to content

Fix percent-equity fee and margin lifecycle parity#133

Merged
luisleo526 merged 1 commit into
mainfrom
codex/van007-equity-short-matrix-20260723
Jul 23, 2026
Merged

Fix percent-equity fee and margin lifecycle parity#133
luisleo526 merged 1 commit into
mainfrom
codex/van007-equity-short-matrix-20260723

Conversation

@luisleo526

Copy link
Copy Markdown
Collaborator

Summary

  • size percent-of-equity orders and broker margin from fee-net live equity, including paid commission on surviving open lots
  • preserve commissioned all-in short provenance across broker margin trims while invalidating it on script-driven reductions and later adds
  • handle close-then-open affordability checkpoints and reset reversal state before sizing the new side
  • add direct clean-room Pine v6 quantity oracles and lifecycle regression coverage

Validation

  • CTest: 120/120 passed
  • focused assertions: 613 passed, 0 failed
  • source-faithful van007 validation: Moderate to Excellent, 100% match, count delta 0, entry P90 0, exit P90 0, PnL P90 0.0398
  • final engine archive SHA-256: 1f2fa93e0d00b050260e8837110c3f4628227ce2f10463e6ea69262683fe3a4f
  • high-risk collateral: 4/4 completed, 1 Strong to Excellent, 0 tier regressions
  • exploratory exhaustive 2^5 characterization: 32/32 cells completed; publication-grade preregistered rerun is being prepared separately

No strategy-specific runtime override or target identifier is present in production code.

Copilot AI review requested due to automatic review settings July 23, 2026 00:09

Copilot AI 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.

Pull request overview

Aligns PineForge’s percent-of-equity sizing and broker margin-call math with TradingView by using a fee-net “live equity” ledger (subtracting already-paid percent entry fees on still-open lots) and by tightening the lifecycle/provenance rules around close-then-open reversals and commissioned default-sized shorts.

Changes:

  • Introduce fee-net equity helpers (surviving_open_percent_commission_account, percent_commission_live_equity) and use them for percent-of-equity sizing snapshots and adverse-margin equity checks.
  • Refine margin-call lifecycle/provenance handling for commissioned default-sized shorts (including close-then-short “opening then adverse retry” sequencing) and invalidate that provenance on script-driven partial reductions/adds while preserving it across broker-driven margin trims.
  • Add new clean-room quantity oracles and regression tests covering fee-net sizing, FIFO fee snapshot scaling, reversals, and the new lifecycle behaviors.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/test_percent_equity_open_entry_fee.cpp New regression coverage for fee-net percent-of-equity sizing and margin-call equity behavior, including clean-room quantity oracles.
tests/test_margin_call.cpp Adds extensive lifecycle/provenance regression tests for commissioned default-sized close-then-open behavior and floor-zero edges.
tests/CMakeLists.txt Registers the new percent-equity fee test target.
src/engine_strategy_commands.cpp Freezes default-sized market order sizing equity from fee-net live equity.
src/engine_orders.cpp Tracks partial-reduction cause to preserve/clear commissioned short lifecycle provenance appropriately.
src/engine_fills.cpp Implements fee-net equity helpers; updates margin-call logic to use fee-net equity and adds the close-then-short “adverse retry” sequencing and lifecycle floor-zero handling.
include/pineforge/engine.hpp Documents updated sizing-equity semantics; declares new helpers; adds new provenance/lifecycle flags and partial-reduction cause plumbing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@luisleo526
luisleo526 merged commit a12cdbc into main Jul 23, 2026
8 checks passed
@luisleo526
luisleo526 deleted the codex/van007-equity-short-matrix-20260723 branch July 23, 2026 02:34
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.

2 participants