fix bug of greeks Nan of spot price < 0.01#18
Open
tinix84 wants to merge 3 commits intomarcdemers:mainfrom
Open
fix bug of greeks Nan of spot price < 0.01#18tinix84 wants to merge 3 commits intomarcdemers:mainfrom
tinix84 wants to merge 3 commits intomarcdemers:mainfrom
Conversation
fix the problem of delta = Nan if S<dS
update all the rest of the greeks for the same problem of delta
ortap
approved these changes
Nov 25, 2024
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the repository’s positioning (as a reference fork) and adjusts numerical Greeks calculations to use a smaller, relative finite-difference bump.
Changes:
- Add a top-level README note clarifying this is a personal reference fork and not actively maintained.
- Change the finite-difference bump (
dS) to1e-6and switch delta/gamma calculations from absolute bumps to relative bumps (x*(1±dS)). - Update delta/gamma denominators accordingly (e.g.,
2*F*dS,(S*dS)^2).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| README.md | Adds a banner note indicating the fork is for reference only. |
| py_vollib_vectorized/_numerical_greeks.py | Switches delta/gamma finite differences to relative bumps and reduces bump magnitude. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| from ._model_calls import black, black_scholes, black_scholes_merton | ||
|
|
||
| dS = .01 | ||
| dS = 1e-6 |
Comment on lines
+31
to
+32
| delta = (black(F*(1+dS), K, sigma, t, flag) - black(F*(1-dS), K, sigma, t, flag)) / ( | ||
| 2*F*dS) |
Comment on lines
+79
to
+80
| gamma = (black(flag, F*(1+dS), K, t, r, sigma) - 2. * black(flag, F, K, t, r, sigma) + \ | ||
| black(flag, F*(1-dS), K, t, r, sigma)) / (F*dS) ** 2. |
Comment on lines
+108
to
+109
| delta = (black_scholes(flag, S*(1+dS), K, t, r, sigma) - black_scholes(flag, S*(1-dS), K, t, r, sigma)) / ( | ||
| 2 * S*dS) |
Comment on lines
+155
to
+156
| gamma = (black_scholes(flag, S*(1+dS), K, t, r, sigma) - 2. * black_scholes(flag, S, K, t, r, sigma) + \ | ||
| black_scholes(flag, S*(1-dS), K, t, r, sigma)) / (S*dS) ** 2. |
Comment on lines
+186
to
+190
| delta = (black_scholes_merton(flag, S*(1+dS), K, t, r, sigma, r - b) - black_scholes_merton(flag, S*(1-dS), K, | ||
| t, r, | ||
| sigma, | ||
| r - b)) / ( | ||
| 2 * dS) | ||
| 2 * dS*S) |
Comment on lines
+246
to
+250
| gamma = (black_scholes_merton(flag, S*(1+dS), K, t, r, sigma, r - b) - 2. * black_scholes_merton(flag, S, K, | ||
| t, r, | ||
| sigma, | ||
| r - b) + \ | ||
| black_scholes_merton(flag, S - dS, K, t, r, sigma, r - b)) / dS ** 2. | ||
| black_scholes_merton(flag, S*(1-dS), K, t, r, sigma, r - b)) / (S*dS) ** 2. |
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.
No description provided.