Skip to content

Release v8.8.0 — TWR metrics, broker balance tracker, stop orders#535

Merged
MDUYN merged 15 commits into
mainfrom
dev
May 9, 2026
Merged

Release v8.8.0 — TWR metrics, broker balance tracker, stop orders#535
MDUYN merged 15 commits into
mainfrom
dev

Conversation

@MDUYN
Copy link
Copy Markdown
Collaborator

@MDUYN MDUYN commented May 9, 2026

Release v8.8.0 — TWR metrics, broker balance tracker, stop orders

This PR rolls up the work currently on dev into main. It adds three
major capabilities and a number of supporting pieces of plumbing.

Highlights

1. Broker balance tracker + Context.sync_portfolio()

  • New BrokerBalanceTracker for managing scheduled deposits/withdrawals
  • Context.sync_portfolio() reconciles local portfolio state against
    the broker and records cash flows on every sync event
  • Cash flows are now first-class so they can be subtracted from
    performance metrics (TWR)
  • New docs page: docusaurus/docs/Advanced Concepts/portfolio-sync.md

2. Stop and stop-limit orders

  • StopOrderType enum + validation
  • Order model gains stop_price / limit_price fields
  • CCXT executor maps to exchange-native stop orders
  • Backtest order service simulates trigger conditions per bar
  • Docs updated in docusaurus/docs/Getting Started/orders.md

3. Time-weighted return (TWR) metrics

TWR variants for CAGR, Sharpe, volatility, returns, drawdown, and
equity curve. All TWR metrics consume snapshot.cash_flow to scrub
external deposits/withdrawals from performance, giving a true alpha-only
view.

New BacktestMetrics fields:

  • twr_equity_curve
  • twr_drawdown_series
  • twr_max_drawdown
  • twr_max_drawdown_duration

4. HTML reporting

  • TWR_EQ / TWR_DD per run in dashboard data
  • Dashed alpha-only overlay on the equity and drawdown charts
  • Scalar metrics surface twr_max_drawdown and twr_max_drawdown_duration

5. Vector backtest scheduled deposits

  • Vector engine honours BrokerBalanceTracker schedules so DCA-style
    accumulation strategies can be backtested with realistic external
    cash flows
  • New scenario test: tests/scenarios/vectorized_backtests/test_deposit_schedule.py

6. Examples

  • examples/strategies_showcase/ — 26 reference strategies
  • examples/advanced_tutorials/cross-sectional-pipelines/
  • examples/rust_vs_python_benchmark/

Commits

feat(portfolio): broker balance tracker + sync_portfolio with cash-flow tracking
feat(orders):    stop and stop-limit order support
feat(metrics):   time-weighted return (TWR) metrics
feat(reporting): TWR overlays + new metrics in HTML dashboard
feat(backtest):  scheduled deposits in vector backtest
chore(tests):    regenerate backtest fixtures for new TWR metrics
chore:           v8.8.0 — re-exports, DI wiring, examples

Test status

Full suite: 1668 passed, 42 skipped locally.

Compatibility

  • BacktestMetrics adds new fields with defaults — from_dict() is
    forward/backward compatible (unknown keys are dropped, missing keys
    default).
  • Backtest fixtures under tests/resources/backtest_reports_for_testing/
    were regenerated to include the new twr_* fields.
  • Version bump: 8.7.3 → 8.8.0.

MDUYN and others added 15 commits May 7, 2026 14:29
…ow tracking

Adds BrokerBalanceTracker for managing scheduled deposits/withdrawals
and Context.sync_portfolio() for reconciling local portfolio state
against broker balances. Cash flows are now recorded on every sync
event so they can be subtracted from performance metrics (TWR).
Adds StopOrderType enum + validation for stop and stop-limit orders.
Order model gains stop_price/limit_price fields, ccxt executor maps
them to exchange-native stop orders, backtest service simulates
trigger conditions per bar.
…al analysis

Introduces TWR variants for CAGR, Sharpe, volatility, returns, drawdown
and equity curve. All TWR metrics consume snapshot.cash_flow to scrub
external deposits/withdrawals from performance, giving a true alpha-only
view. Adds new BacktestMetrics fields: twr_equity_curve, twr_drawdown_series,
twr_max_drawdown, twr_max_drawdown_duration.
Backtest HTML dashboard now ships TWR_EQ / TWR_DD per run and overlays
the alpha-only curve as a dashed line on the equity and drawdown charts.
Scalar metrics gain twr_max_drawdown and twr_max_drawdown_duration.
Vector backtest engine now honours BrokerBalanceTracker schedules so
DCA-style accumulation strategies can be backtested with realistic
external cash flows. Adds scenario test for deposit schedules.
Updates serialized metrics.json/run.json fixtures to include the new
twr_* fields so round-trip serialization tests stay green.
Bumps version 8.7.3 -> 8.8.0. Wires new BrokerBalanceTracker into the
dependency container and event loop, exposes new public symbols from
package __init__, adds OperationalException for sync errors, updates
docs sidebar, and ships example strategies showcasing TWR metrics,
DCA accumulation, and stop/stop-limit orders.
CI runs the suite under stdlib unittest (not pytest), so the bare
'import pytest' caused a ModuleNotFoundError on the runner.
Follow-up to #529:

* Extract a single url_cache_key(url, headers) helper in
  base_url.py so the in-memory provider dict on Context and the
  on-disk cache filename hash use the exact same canonical
  serialization. Prevents future drift where an in-memory hit
  could read the wrong on-disk file.

* Add a note to the headers= docstrings on Context.fetch_csv /
  fetch_json / fetch_parquet and DataSource.from_csv / from_json /
  from_parquet documenting that header values are redacted to
  '***' in to_dict() so secrets do not leak into diagnostic
  payloads.
…-test

Optimize README example scenario test
@MDUYN MDUYN merged commit 0dbd880 into main May 9, 2026
8 checks passed
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