feat(tradingbot): capital allocation optimizer - #15
Conversation
|
This PR needs an issue link. Add |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: eed20d830e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
This PR needs an issue link. Add |
|
This PR needs an issue link. Add |
6 similar comments
|
This PR needs an issue link. Add |
|
This PR needs an issue link. Add |
|
This PR needs an issue link. Add |
|
This PR needs an issue link. Add |
|
This PR needs an issue link. Add |
|
This PR needs an issue link. Add |
Adds optimizer.py — grid-search over the N-simplex of weight vectors, maximizing portfolio Sharpe subject to a historical worst-case drawdown constraint sourced from the black-swan replay harness (round-1 #5). The replay callable is injected (pluggable WorstCaseFn) so tests mock the heavy backtest while production wires in the real harness. Equal- weight fallback when no grid point satisfies the cap, so the function never returns an unallocated portfolio. Proof: pytest tests/test_optimizer.py — 9 passed, including weights- sum-to-1.0 and highest-Sharpe-gets-largest-weight contract checks. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
df442ac to
9ce88a2
Compare
|
This PR needs an issue link. Add |
Round-2 feature #4 for
tradingbot(percampaigns/repo-magic/round-2/03-feature-plans.md§7.4).Given N candidate strategies, recommends portfolio weights that maximize
risk-adjusted return under a historical worst-case drawdown constraint.
Proof
Spec-mandated assertions both green:
test_weights_sum_to_one).fixture (
test_highest_sharpe_gets_largest_weight—mean_reverterwith Sharpe 1.6 wins over
trend_follow1.1 andmomentum0.8).Full repo suite: 32 passed, no regressions.
Round-1 dependency
Worst-case drawdown cap is sourced from the black-swan replay harness
introduced in #5 (
feat(tradingbot): black-swan replay harness for 2008 and COVID windows). The optimizer takesworst_case_fnas a callableparameter so production wires in the real replay while tests mock the
heavy backtest path — keeping this PR test-runnable in CI without
historical market data.
Design
optimizer.pyat repo root (matchesshouldBuy.py,sectorAnalysis.py, etc.).no NumPy/SciPy dep added.
WorstCaseFncallable so the heavy backtest is mocked intests and supplied by the black-swan replay in production.
optimizer never returns an unallocated portfolio.
Touches
optimizer.py(new, 117 LoC)tests/test_optimizer.py(new, 9 tests)Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com