Skip to content

Commit

Permalink
Update black_scholes.py
Browse files Browse the repository at this point in the history
Add vanna and vomma
  • Loading branch information
jkirkby3 authored Apr 21, 2024
1 parent 5d2fd34 commit 787f443
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions fypy/pricing/analytical/black_scholes.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,46 @@ def black76_vega(F: float,
d_1 = (np.log(F / K) + 0.5 * vol_st ** 2) / vol_st
return disc * F * norm.pdf(d_1) * np.sqrt(T)

def black76_vanna(F: float,
K: Union[float, np.ndarray],
vol: Union[float, np.ndarray],
disc: float,
T: float) -> Union[float, np.ndarray]:
"""
Vanna(s) for strike(s)
:param F: float, forward price
:param K: float or array, the Strike(s)
:param vol: float or array, the Volatility(ies) ... if float, all strikes get same vol, else a vol smile
:param disc: float, the discount factor, e.g. 0.99
:param T: float, time to maturity of option
:return: float or np.ndarray, same shape as strikes
"""
vol_st = vol * np.sqrt(T)
d_1 = (np.log(F / K) + 0.5 * vol_st ** 2) / vol_st
d_2 = d_1 - vol_st
return -disc * norm.pdf(d_1) * d_2 / vol


def black76_vomma(F: float,
K: Union[float, np.ndarray],
vol: Union[float, np.ndarray],
disc: float,
T: float) -> Union[float, np.ndarray]:
"""
Vomma(s) for strike(s)
:param F: float, forward price
:param K: float or array, the Strike(s)
:param vol: float or array, the Volatility(ies) ... if float, all strikes get same vol, else a vol smile
:param disc: float, the discount factor, e.g. 0.99
:param T: float, time to maturity of option
:return: float or np.ndarray, same shape as strikes
"""
sqt = np.sqrt(T)
vol_st = vol * sqt
d_1 = (np.log(F / K) + 0.5 * vol_st ** 2) / vol_st
d_2 = d_1 - vol_st
vega = disc * F * norm.pdf(d_1) * sqt
return vega * d_1 * d_2 / vol

def black76_delta(F: float,
K: Union[float, np.ndarray],
Expand Down

0 comments on commit 787f443

Please sign in to comment.