feat: add broker equity accessor#24
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new preferred public accessor (Broker.equity()) for marked account equity while keeping the existing get_account_value() method as a backward-compatible alias, and updates documentation/tests to reflect the new API surface.
Changes:
- Introduce
Broker.equity()as the primary account-equity accessor and delegateget_account_value()to it. - Add test coverage ensuring equity reflects current mark prices and that
get_account_value()matchesequity(). - Update user guide/API docs to document the new accessor and clarify compatibility behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/test_broker.py | Adds a test verifying equity() uses current mark prices and matches get_account_value(). |
| src/ml4t/backtest/broker.py | Implements equity() and makes get_account_value() delegate to it. |
| docs/user-guide/stateful-strategies.md | Documents equity() as the preferred accessor and notes get_account_value() compatibility. |
| docs/api/index.md | Exposes equity in the generated Broker API members list. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+60
to
+68
| broker_with_position._update_time( | ||
| datetime(2024, 1, 2, 9, 30), | ||
| {"AAPL": 155.0}, | ||
| {"AAPL": 154.0}, | ||
| {"AAPL": 156.0}, | ||
| {"AAPL": 153.0}, | ||
| {"AAPL": 1000.0}, | ||
| {}, | ||
| ) |
Comment on lines
743
to
+745
| def get_account_value(self) -> float: | ||
| """Calculate total account value (cash + position values).""" | ||
| return self._portfolio_ledger.get_account_value() | ||
| return self.equity() |
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
Validation