vp.finance.bs_greeks
Black-Scholes delta, gamma and vega of one option. Delta and vega are grad of bs_price; gamma is vega / (S^2 sigma T), which holds for Black-Scholes calls and puts alike.
Part of the distribution vipyr; it runs from a checkout of the
repository. Planned on PyPI as pip install vipyr.
Signature
vp.finance.bs_greeks(S, K, T, r, q, sigma, is_call) Parameters
- S : float, required
- K : float, required
- T : float, required
- r : float, required
- q : float, required
- sigma : float, required
- is_call : bool, required
Returns
A frozen BsGreeksResult. Iterating it gives the fields below in order; it also has
params, tests, log and check().
- delta : float
- DV/dS.
- gamma : float
- D2V/dS2, per unit of S.
- vega : float
- DV/dsigma.
Raises
- TypeError
- An argument of the wrong type, or an unknown keyword.
- vipyr.VivBuildError
- An ImportError: no C compiler, or the program's C does not build.
Examples
import vipyr as vp
r = vp.finance.bs_greeks(S=100.0, K=100.0, T=1.0, r=0.05, q=0.0, sigma=0.2, is_call=True)
print(r.delta, r.gamma, r.vega)
assert r.check() 0.6368306511756193 0.01876201734584689 37.524034691693785Each example ran as written when these pages were generated, and the output shown is what it printed.
Checked against
- Reference
- The closed-form Black-Scholes Greeks (examples/options/test_options.py, test_bs_greeks_by_autodiff); delta and vega come from Viv's reverse-mode
grad.
Source
- Viv: examples/options/greeks.viv
- The defs it reaches and the calls between them: map of the code