vp.finance.implied_vol
The implied volatility of one quote, or NaN when the price is outside the no-arbitrage bounds. Newton steps on log(otm(s)) - log(target) in s = sigma sqrt(T), kept inside a bracket [lo, hi] that every evaluation shrinks; a step that leaves it is replaced by bisection (or doubling while hi is unknown). Stops when a step is below 4 × 10−16 of s.
Part of the distribution vipyr; it runs from a checkout of the
repository. Planned on PyPI as pip install vipyr.
Signature
vp.finance.implied_vol(price, S, K, T, r, q, is_call) Parameters
- price : float, required
- S : float, required
- K : float, required
- T : float, required
- r : float, required
- q : float, required
- is_call : bool, required
Returns
A frozen ImpliedVolResult. Iterating it gives the fields below in order; it also has
params, tests, log and check().
- sigma : float
- The volatility that reproduces the price, per unit sqrt(year); NaN outside the no-arbitrage bounds.
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.implied_vol(price=4.7594, S=42.0, K=40.0, T=0.5, r=0.1, q=0.0, is_call=True)
print(r.sigma) # 0.2
assert r.check() 0.19999745922096207Each example ran as written when these pages were generated, and the output shown is what it printed.
Checked against
- Reference
- A round trip through bs_price on a 1080-quote grid: worst relative error 8.8 × 10−13 on the 898 quotes with time value above 10−5 of the price, tolerance 10−12 (examples/options/test_options.py).
Source
- Viv: examples/options/bs.viv
- The defs it reaches and the calls between them: map of the code