Skip to content

feat: portfolio signal contract + by-ref loader + sizing#63

Merged
ArthurBernard merged 1 commit into
developfrom
feat/portfolio-signal
Jun 29, 2026
Merged

feat: portfolio signal contract + by-ref loader + sizing#63
ArthurBernard merged 1 commit into
developfrom
feat/portfolio-signal

Conversation

@ArthurBernard

Copy link
Copy Markdown
Owner

Summary

  • application.portfolio — the multi-asset analogue of the single-instrument signal:
    • PortfolioSignalFn = (asof_ms, {Symbol: frame}) -> {Symbol: weight} (weight = signed fraction of capital);
    • PortfolioStrategy (frozen: universe + signal + capital + optional gross_cap);
    • weights_to_signals(weights, *, prices, capital, asof_ms) — pure sizer, qty = weight × capital / priceSignal.target_qty (exact Decimal, never float);
    • load_portfolio_signal(ref) — safe module:function loader (importlib+getattr, no loose-file exec).
  • Reusable fake PortfolioSignalFn fixture (tests/fixtures/fake_book.py) for downstream leaves.

Why

LS1 (first validated multi-asset strategy) is a vector of target weights over ~10 coins, gross-capped 2×; the single-instrument (bars) -> Signal can't express it, and a per-coin |w|>1 (leverage) would be rejected by a bounded [-1,1] exposure signal. An explicit-quantity signal carries its own scale, so the runner diffs it against live positions with no reference_qty. The loader stays by-reference so the engine is generic (LS1 lives in config). See ADR.

Changes

  • trading_bot/application/portfolio.py (new), application/__init__.py (exports).
  • trading_bot/tests/fixtures/{__init__,fake_book}.py (new), tests/application/test_portfolio_signal.py (new, 20 tests).

Changelog

Added under [Unreleased] (0.3.0): application.portfolio weight-vector contract + sizer + loader.

Test plan

  • .venv/bin/python -m pytest — 637 passed, 7 deselected
  • .venv/bin/ruff check trading_bot/ — clean
  • .venv/bin/mypy trading_bot/ — clean
  • CI green

Leaf 01 of portfolio-strategy (doc/dev/plans/portfolio-strategy/). Leaves 02 (feed) and 03 (runner) depend on this.

@ArthurBernard ArthurBernard force-pushed the feat/portfolio-signal branch from 8048b96 to cd3d0e3 Compare June 28, 2026 20:56
@ArthurBernard ArthurBernard merged commit 5e9c174 into develop Jun 29, 2026
3 checks passed
@ArthurBernard ArthurBernard deleted the feat/portfolio-signal branch June 29, 2026 05:23
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.

1 participant