fix(api): use N(d2) for probability of profit, not N(d1) (#8)#27
Open
bradsmithmba wants to merge 1 commit into
Open
fix(api): use N(d2) for probability of profit, not N(d1) (#8)#27bradsmithmba wants to merge 1 commit into
bradsmithmba wants to merge 1 commit into
Conversation
_calculate_probability_above() returned norm.cdf(d1) as the probability that the underlying finishes above a target. The risk-neutral probability P[S_T > K] is N(d2), not N(d1); N(d1) is the call delta and is always larger, so every probability-of-profit figure was overstated. Every POP value in the system flows through this method (directly and via _calculate_probability_below / _between), so the bias was system-wide. Compute d2 = d1 - sigma*sqrt(t) and return N(d2). For S=100, K=105, vol=0.25, 30d, r=0.05 this corrects 0.2784 -> 0.2549 (a 2.35 pt overstatement removed). Closes cloudtrainerwork#8 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
_calculate_probability_above()insrc/api/enhanced_strategy_recommender.pyreturnednorm.cdf(d1)as the probability that the underlying finishes above a target price. The correct risk-neutral probabilityP[S_T > K]isN(d2), notN(d1).N(d1)is the call delta — always larger thanN(d2)— so every probability-of-profit figure in the system was overstated.Closes #8.
Blast radius
This method is the single source of POP in the recommender.
_calculate_probability_below()and_calculate_probability_between()both delegate to it, and strategy POP/prob_profitfields are computed from it, so the bias propagated everywhere POP is shown or used for ranking.Fix
Verification
For S=100, K=105, vol=0.25, 30 days, r=0.05:
No existing test asserts the previous (incorrect) value, so nothing else changes.
🤖 Generated with Claude Code