fix: address review backlog#36
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses a review backlog across the backtesting engine by tightening risk-liquidation behavior (broker flattening + idempotent application), simplifying partial-fill affordability via Gatekeeper validation, improving DataFeed timestamp indexing behavior, and cleaning up docs theme overrides—while adding regression tests around these areas.
Changes:
- Route portfolio risk liquidations through
Broker.flatten_all_positions()and make repeated liquidation updates idempotent (RiskManager). - Rework partial-fill affordability to delegate cash/commission validation to
Gatekeeper.validate_order()(incl. minimum-commission coverage). - Normalize/strengthen DataFeed timestamp indexing and update docs/theme + installation instructions; add regression tests.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/test_datafeed_memory.py | Adds regression coverage for signal-only timestamps and mixed slice-length iteration. |
| tests/test_config_wiring.py | Adds tests for minimum-commission partial fills and per_contract commission alias; simplifies default-parity assertion. |
| tests/test_broker.py | Refactors flattening test setup and adds a noop flattening regression test. |
| tests/risk/test_portfolio_manager.py | Adds idempotent liquidation regression test and uses broker-driven position creation helpers. |
| src/ml4t/backtest/types.py | Updates cost_drag docstring wording for clarity. |
| src/ml4t/backtest/risk/portfolio/manager.py | Adds broker typing, idempotent liquidation guard, and resets guard on initialize/reset. |
| src/ml4t/backtest/result.py | Documents and supports exporting spec.yaml via to_parquet(include=...). |
| src/ml4t/backtest/execution/rebalancer.py | Updates FeedSpec typing import path and clarifies leverage/short weight semantics in docstrings. |
| src/ml4t/backtest/execution/fill_executor.py | Adjusts slippage attribution for flipped positions to use per-unit slippage consistently. |
| src/ml4t/backtest/engine.py | Makes OHLC fallbacks explicit per-asset using close/price base selection. |
| src/ml4t/backtest/datafeed.py | Renames internal indices to entity terminology and replaces timestamp indexing implementation. |
| src/ml4t/backtest/core/shared.py | Refines liquidation keyword matching via regex for exit-reason mapping. |
| src/ml4t/backtest/core/fill_engine.py | Replaces affordability math with Gatekeeper-driven validation and bisection search. |
| src/ml4t/backtest/config.py | Adds CommissionType._missing_ aliasing for "per_contract" and makes enum defaults use .value. |
| src/ml4t/backtest/accounting/policy.py | Updates short-cash policy docs to include credit_proceeds. |
| mkdocs.yml | Updates docs hub/library/chapter URLs to absolute production URLs. |
| docs/overrides/main.html | Removes custom theme JS injection block. |
| docs/overrides/assets/stylesheets/ml4t-docs-theme.css | Aligns overrides with updated MkDocs theme class names and comments. |
| docs/overrides/assets/javascripts/ml4t-docs-theme.js | Removes stale theme JS file. |
| docs/getting-started/installation.md | Updates clone instructions to the new repository path and trims dependency list. |
Comments suppressed due to low confidence (1)
src/ml4t/backtest/datafeed.py:344
open/high/lowcurrently fall back toclosewhen those columns are missing, which leaves them asNonewhen a feed providespricebut noclose. That propagatesNonevalues into the per-bar dict and can break downstream consumers that expect OHLC to be usable wheneverpriceis present.
close = row[price_close_idx] if price_close_idx >= 0 else None
price = row[price_price_idx] if price_price_idx >= 0 else close
open_ = row[price_open_idx] if price_open_idx >= 0 else close
high = row[price_high_idx] if price_high_idx >= 0 else close
low = row[price_low_idx] if price_low_idx >= 0 else close
💡 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.
Summary
Verification