fix(models): Kelly sizing returns None when historical data is absent (#17)#30
Open
bradsmithmba wants to merge 1 commit into
Open
Conversation
_calculate_kelly_sizing received win_rate/avg_win/avg_loss with call-site defaults of 0.5/1.0/1.0 when a strategy had no historical data. Those defaults yield Kelly = (0.5*1 - 0.5)/1 = 0, so every strategy without backtest data was sized at 0 — indistinguishable from a genuine "no edge" (Kelly = 0) result and presented to the user as "position size: 0%". Take the metrics dict directly and return None when win_rate, avg_win, and avg_loss are not all present. ScoredStrategy.kelly_size becomes Optional[float]; recommendation_engine renders None as "insufficient historical data to size" instead of formatting it as 0.0%. A present-but-no-edge case still returns 0.0, so callers can distinguish "no data" (None) from "no edge" (0.0). Two tests cover both. Closes cloudtrainerwork#17 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Author
|
Dependency note: the scoring-engine tests in this PR pass on their own ( |
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
ScoringEngine._calculate_kelly_sizing()was called with call-site defaults when a strategy had no historical performance data:With those defaults, Kelly =
(0.5*1 - 0.5) / 1 = 0. Every strategy lacking backtest data was sized at exactly 0 — indistinguishable from a genuine "no edge" result (Kelly is also 0 for a true 50/50, 1:1 bet) — and surfaced to the user as "Recommended position size: 0%", which reads as advice rather than missing data.Closes #17.
Fix
_calculate_kelly_sizing(metrics)now takes the metrics dict and returnsOptional[float]:Nonewhenwin_rate,avg_win,avg_lossare not all present (no statistical basis to size).0.0when the data is present but there is genuinely no edge.ScoredStrategy.kelly_sizebecomesOptional[float].recommendation_enginerendersNoneas "insufficient historical data to size" instead of formatting it as0.0%.Tests
Two new tests pin the distinction:
test_kelly_sizing_none_without_historical_data— missing inputs →Nonetest_kelly_sizing_zero_for_no_edge— present inputs, no edge →0.0CI note
src/models/recommendation_engine.pycurrently cannot be imported because it imports the missingsrc.models.integrated_selector(#21), so itsNone-rendering branch can't be exercised in CI yet. The change there is a defensive guard for when #21 lands; the scoring-engine behavior and its tests run independently and pass now.🤖 Generated with Claude Code