fix(features): correct debit-spread max profit, width - debit (#16)#28
Open
bradsmithmba wants to merge 1 commit into
Open
fix(features): correct debit-spread max profit, width - debit (#16)#28bradsmithmba wants to merge 1 commit into
bradsmithmba wants to merge 1 commit into
Conversation
Position.calculate_max_profit() for BULL_CALL_SPREAD / BEAR_PUT_SPREAD used max(spread_width - debit, debit). Whenever the net debit exceeded half the spread width, this returned the debit itself — which is the position's max loss, and can exceed the spread width — instead of the correct max profit. Max profit for a debit spread is always spread_width - net_debit. Replace the max() fallback with that formula and add a regression test using a debit greater than half the width (1000c width, 800c debit -> 200c profit; the old code returned 800c). Verified via Position.calculate_max_profit(): bug case 200 (was 800), normal case 650. Closes cloudtrainerwork#16 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Author
|
Merge-ordering note: the regression test added here lives in |
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
Position.calculate_max_profit()(src/features/position_models.py) computed the max profit of aBULL_CALL_SPREAD/BEAR_PUT_SPREADas:For a debit spread, max profit is always
spread_width - net_debit. Themax(..., debit)fallback returns the debit (the position's max loss) whenever the debit exceeds half the spread width — a value that can even exceed the spread width and is never a valid max profit.Closes #16.
Fix
Verification
Exercised through the real
calculate_max_profit():A regression test (
test_debit_spread_max_profit_when_debit_exceeds_half_width) is added totests/test_position_state.pyusing the 800c-debit case.CI note
tests/test_position_state.pyimportssrc.features.position_state, which transitively imports the data layer that is missing until #1 (PR #19) merges, so this test file cannot be collected onmasteryet. The fix itself was verified by invokingPosition.calculate_max_profit()directly (the method has no such dependency). The new test will run in CI once #1 lands.🤖 Generated with Claude Code