Skip to content

feat: add broker equity accessor#24

Merged
stefan-jansen merged 1 commit into
mainfrom
fix/public-broker-equity-accessor
Jun 12, 2026
Merged

feat: add broker equity accessor#24
stefan-jansen merged 1 commit into
mainfrom
fix/public-broker-equity-accessor

Conversation

@stefan-jansen

Copy link
Copy Markdown
Contributor

Summary

  • add Broker.equity() as the preferred public account-equity accessor
  • keep get_account_value() as an existing compatibility spelling that delegates to equity()
  • document the accessor and add broker coverage

Validation

  • uv run ruff check .
  • uv run ruff format --check .
  • uv run ty check
  • pre-commit run --all-files
  • uv run pytest tests/ -q
  • uv build

Copilot AI review requested due to automatic review settings June 12, 2026 16:44

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

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 delegate get_account_value() to it.
  • Add test coverage ensuring equity reflects current mark prices and that get_account_value() matches equity().
  • 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 thread tests/test_broker.py
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()
@stefan-jansen stefan-jansen merged commit 877332b into main Jun 12, 2026
8 checks passed
@stefan-jansen stefan-jansen deleted the fix/public-broker-equity-accessor branch June 12, 2026 16:52
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