Trading metrics + equity curve in backtest report (ABI v2)#31
Merged
Conversation
…ndex fields, pf_abi_version (PF_ABI_VERSION=2) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…rsion C-side; document include-order Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…, reset-safe Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…t tests Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…arpe/sortino, cagr/calmar) + unit tests Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…oracles; document tz-lock contract Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…_version pf_report_t grew in ABI v2 (pf_metrics_t by value + equity_curve ptr + int64 len appended; pf_trade_t gained commission + entry/exit bar indices). pf_report_t is CALLER-allocated, so every ctypes harness that allocated it from the old field list would under-size the buffer and let the runtime write past it. Updated every ctypes mirror in the repo and added an ABI guard at every CDLL load site (pf_abi_version() must equal 2; a missing symbol means a pre-v2 .so and is rejected with a rebuild hint): - scripts/run_strategy.py (corpus harness; trade dicts now also carry commission + entry/exit bar_index) - tutorial/run.py (mirrors + reusable check_abi) - tutorial/run_mtf.py (guard via run.check_abi) - tutorial/run_advanced.py (guard via run.check_abi) - docker/run_json.py (codegen-mcp container harness) - benchmarks/throughput/grid_search_repro.py Mirror layouts verified against include/pineforge/pineforge.h: ctypes sizeof matches the C side exactly (trade 96, trade_stats 216, equity_stats 120, metrics 768, equity_point 24, report 944; metrics/ equity_curve/equity_curve_len offsets 160/928/936). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…pty-curve coverage Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…urve, pf_abi_version) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…c reference from source comment Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…n-cost pnl_pct, independent largest-%, inclusive avg bars Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…SOP in CLAUDE.md Co-Authored-By: Claude Fable 5 <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.
What
Adds a comprehensive trading-metrics suite and the raw per-script-bar equity curve to
pf_report_t, validated against a real TradingView export and two independent quant libraries.PF_ABI_VERSION 2):pf_metrics_t(trade-stat blocks for All/Long/Short + equity stats) andpf_equity_point_t* equity_curveappended topf_report_t;commission/entry_bar_index/exit_bar_indexappended topf_trade_t. Newpf_abi_version()export —pf_report_tis caller-allocated, so every harness now asserts the version before running (old mirror = silent stack corruption).pineforge.hdoxygen.ab.bar.timestamp; pinned by a magnifier on/off bit-identity test), reset-safe for handle reuse.src/engine_metrics.cpp(no engine dependency), dd/run-up walk mirrorsupdate_equity_extremes(enforced by integration test + reciprocal comments).composite-4emarsi-integration-01, 336 trades): per-tradepnl_pctis now net return-on-cost (closes long-standing O5 finding; TV trade #258: 102.44 USD / 2276.66 entry ⇒ 4.50%, old price-ratio formula said 4.72%);largest_*_pcttracked independently of the largest-USD trade;avg_barscounted inclusively.scripts/run_strategy.py, tutorials,docker/run_json.py, bench script. Docs FFI pages (Python/Rust) and report schema synced.scripts/crossvalidate_metrics.py(venv-based, no repo deps).Validation
test_metrics: 1200+ checks incl. closed-form Sharpe/Sortino oracles 19/20 and 114/61, non-UTC month bucketing, magnifier bit-identity, handle-reuse reset, engine-vs-walk drawdown invariant). ASan clean.Net PnL %column (expected from the pnl_pct correction; verified across all 158 changed files).Known deltas / follow-ups
pineforge-codegen-ossbranchfeat/abi-v2-metrics(compile-test fix for the newversion.hinclude) must merge in lockstep; codegen-mcp docker image needs a rebuild.engine_trades.csvfiles (Net PnL % column) — submodule bump intentionally left out of this PR.🤖 Generated with Claude Code