-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BSEuropeanBinaryOption.gamma returns nan #528
Comments
I think it should be 0 |
It seems error of autogreek
|
Update: This is due to the anomalous gradient of normal cdf and/or d2. The BS European binary price is given by ncdf(d2): pfhedge/pfhedge/nn/functional.py Lines 798 to 813 in e19efce
Gradient of d2 returns import torch
from pfhedge.nn.functional import ncdf
from pfhedge.nn.functional import d2
from pfhedge.nn.functional import bs_european_binary_price
import pfhedge.autogreek as autogreek
s = torch.tensor(1.0)
t = torch.tensor(0.0)
v = torch.tensor(1.0)
price = bs_european_binary_price(s, t, v)
print(price)
# tensor(1.)
d2_grad = autogreek.delta(
d2,
strike=1.0,
log_moneyness=s,
time_to_maturity=t,
volatility=v,
)
print(d2_grad)
# tensor(inf)
delta = autogreek.delta(
bs_european_binary_price,
strike=1.0,
log_moneyness=s,
time_to_maturity=t,
volatility=v,
)
print(delta)
# tensor(nan) |
d2_grad = inf seems to be correct behavior: grad d2 at t=0 is indeed d(logS) / 0=+inf. |
Now I see the cause. The pricing function is |
Thus the grad of There are two ways to take care of this:
I'm not sure which is better. Any thoughts? @masanorihirano |
According to the design concept of #494, I think
is coherent. If the gradient for them is important, it should be reconsidered. |
Is it correctly working?
Returning tensor including nan seems a little bit harmful. (But, I haven't face this issue and have noticed when I make additional tests.)
The text was updated successfully, but these errors were encountered: