Skip to content

fix bug of greeks Nan of spot price < 0.01#18

Open
tinix84 wants to merge 3 commits intomarcdemers:mainfrom
tinix84:main
Open

fix bug of greeks Nan of spot price < 0.01#18
tinix84 wants to merge 3 commits intomarcdemers:mainfrom
tinix84:main

Conversation

@tinix84
Copy link

@tinix84 tinix84 commented Apr 24, 2024

No description provided.

tinix84 added 2 commits April 24, 2024 07:11
fix the problem of delta = Nan if S<dS
update all the rest of the greeks for the same problem of delta
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 18, 2026 11:08
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) to 1e-6 and 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants