Parity hardening + coverage hardening - #2
Merged
Conversation
When initial_cash is passed as int (e.g., 100000), the equity curve starts with int then transitions to float values. Polars strict mode rejects this mixed-type list. Ensure all values are float. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- to_tearsheet() was using to_returns_series() (bar-level), which inflates Sharpe for intraday data. Now uses to_daily_returns() for correct metrics. - Added calendar parameter for session alignment (crypto, CME futures). - Pass equity_curve to generate_backtest_tearsheet() so portfolio-level charts can render. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Delete analysis.py shim module (414 lines) - Remove SizingMethod enum, BacktestEngine/TrailHwmSource aliases - Remove 6 deprecated property aliases (Trade.asset/.commission/.mfe/.mae, Position.avg_entry_price) - Remove dict-like access on BacktestResult (__getitem__, __contains__, get) - Remove deprecated equity metrics (sharpe/sortino/calmar methods) - Simplify fill_executor exit reason parsing - Update all tests for new API
There was a problem hiding this comment.
Pull request overview
This PR focuses on parity hardening (cross-engine validation infrastructure) and coverage hardening (error path testing). The changes significantly improve the codebase's architecture and testability without introducing breaking changes to the public API.
Changes:
- Validation Import Bridge: Created
_validation_imports.pymodule to provide legacy imports for validation scripts without widening public API - Profile System: Moved framework presets from inline code to centralized
profiles.pywith strict validation - Contract Tests: Added cross-engine parity tests and property-based tests for accounting/ordering invariants
- Result.py Coverage: Added error-path tests for config export failures, import errors, and edge cases
- Broker Decomposition: Split broker into specialized engines (FillEngine, ExecutionEngine, RiskEngine, OrderBook, PortfolioLedger)
- Config Hardening: Added strict validation with allowlist-based section/key checking
Reviewed changes
Copilot reviewed 141 out of 145 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/ml4t/backtest/_validation_imports.py |
New validation-only import bridge |
src/ml4t/backtest/profiles.py |
Centralized framework behavior profiles |
src/ml4t/backtest/config.py |
Strict config validation, enum migrations |
src/ml4t/backtest/core/*.py |
Broker decomposition into specialized engines |
tests/contracts/*.py |
New cross-engine parity and property tests |
tests/test_result.py |
Error-path coverage improvements |
validation/run_all_correctness.py |
ML4T_PROFILE environment variable support |
| 60+ validation scripts | Updated to use _validation_imports |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Includes parity config wiring, contract tests, and result.py error-path coverage improvements.