feat: portfolio signal contract + by-ref loader + sizing#63
Merged
Conversation
8048b96 to
cd3d0e3
Compare
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
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 + optionalgross_cap);weights_to_signals(weights, *, prices, capital, asof_ms)— pure sizer,qty = weight × capital / price→Signal.target_qty(exactDecimal, never float);load_portfolio_signal(ref)— safemodule:functionloader (importlib+getattr, no loose-file exec).PortfolioSignalFnfixture (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) -> Signalcan'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 noreference_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.portfolioweight-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/— cleanLeaf 01 of portfolio-strategy (
doc/dev/plans/portfolio-strategy/). Leaves 02 (feed) and 03 (runner) depend on this.