Stochastic-Alpha-Beta-Rho (SABR) Model

Created on Tue Oct 10 @author: jaehyuk

class SabrChoiWu2021H(sigma, vov=0.0, rho=0.0, beta=1.0, intr=0.0, divr=0.0, is_fwd=False, vol_beta=None)[source]

The CEV volatility approximation of the SABR model based on Theorem 1 of Choi & Wu (2019)

References

  • Choi, J., & Wu, L. (2019). The equivalent constant-elasticity-of-variance (CEV) volatility of the stochastic-alpha-beta-rho (SABR) model. ArXiv:1911.13123 [q-Fin]. https://arxiv.org/abs/1911.13123

Examples

>>> import numpy as np
>>> import pyfeng as pf
>>> m = pf.SabrChoiWu2021H(sigma=2, vov=0.2, rho=-0.3, beta=0.5)
>>> m.vol_for_price(np.arange(80, 121, 10), 100, 1.2)
array([2.07833214, 2.03698255, 2.00332   , 1.97692259, 1.95735019])
>>> m.price(np.arange(80, 121, 10), 100, 1.2)
array([22.04897988, 14.56240351,  8.74169054,  4.72340753,  2.28876105])
base_model(vol, is_fwd=None)

Create base model based on _base_beta value: Norm for 0, Cev for (0,1), and Bsm for 1 If _base_beta is None, use base instead.

Parameters
  • vol – base model volatility

  • is_fwd – if True, treat spot as forward price. False by default.

Returns: model

delta(strike, spot, texp, cp=1)

Option model delta (sensitivity to price) by finite difference

Parameters
  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

Returns

delta value

delta_numeric(strike, spot, texp, cp=1)

Option model delta (sensitivity to price) by finite difference

Parameters
  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

Returns

delta value

forward(spot, texp)

Forward price

Parameters
  • spot – spot price

  • texp – time to expiry

Returns

forward price

gamma(strike, spot, texp, cp=1)

Option model gamma (2nd derivative to price) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

Delta with numerical derivative

gamma_numeric(strike, spot, texp, cp=1)

Option model gamma (2nd derivative to price) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

Delta with numerical derivative

impvol(price, strike, spot, texp, cp=1, setval=False)

Implied volatility using Brent’s method. Slow but robust implementation.

Parameters
  • price – option price

  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put

  • setval – if True, sigma is set with the solved implied volatility

Returns

implied volatility

impvol_brentq(price, strike, spot, texp, cp=1, setval=False)

Implied volatility using Brent’s method. Slow but robust implementation.

Parameters
  • price – option price

  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put

  • setval – if True, sigma is set with the solved implied volatility

Returns

implied volatility

classmethod init_benchmark(set_no=None)

Initiate a SABR model with stored benchmark parameter sets

Parameters

set_no – set number

Returns

Dataframe of all test cases if set_no = None (model, Dataframe of result, params) if set_no is specified

References

  • Antonov, Alexander, Konikov, M., & Spector, M. (2013). SABR spreads its wings. Risk, 2013(Aug), 58–63.

  • Antonov, Alexandre, Konikov, M., & Spector, M. (2019). Modern SABR Analytics. Springer International Publishing. https://doi.org/10.1007/978-3-030-10656-0

  • Antonov, Alexandre, & Spector, M. (2012). Advanced analytics for the SABR model. Available at SSRN. https://ssrn.com/abstract=2026350

  • Cai, N., Song, Y., & Chen, N. (2017). Exact Simulation of the SABR Model. Operations Research, 65(4), 931–951. https://doi.org/10.1287/opre.2017.1617

  • Korn, R., & Tang, S. (2013). Exact analytical solution for the normal SABR model. Wilmott Magazine, 2013(7), 64–69. https://doi.org/10.1002/wilm.10235

  • Lewis, A. L. (2016). Option valuation under stochastic volatility II: With Mathematica code. Finance Press.

  • von Sydow, L., …, Haentjens, T., & Waldén, J. (2018). BENCHOP - SLV: The BENCHmarking project in Option Pricing – Stochastic and Local Volatility problems. International Journal of Computer Mathematics, 1–14. https://doi.org/10.1080/00207160.2018.1544368

mass_zero(spot, texp, log=False)[source]

Probability mass absorbed at the zero boundary (K=0)

Parameters
  • spot – spot (or forward) price

  • texp – time to expiry

  • log – log value if True

Returns

(log) probability mass at zero

mass_zero_t0(spot, texp)[source]

Limit value of -T log(M_T) as T -> 0, where M_T is the mass at zero. See Corollary 3.1 of Choi & Wu (2019)

Parameters
  • spot – spot (or forward) price

  • texp – time to expiry

Returns

-lim_{T->0} T log(M_T)

params_kw()

Model parameters in dictionary

pdf_numeric(strike, spot, texp, cp=- 1, h=0.001)

Probability density functin (PDF) at strike

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

probability densitiy

price(strike, spot, texp, cp=1)

Call/put option price.

Parameters
  • strike – strike price.

  • spot – spot (or forward) price.

  • texp – time to expiry.

  • cp – 1/-1 for call/put option.

Returns

option price

theta(strike, spot, texp, cp=1)

Option model thegta (sensitivity to time-to-maturity) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

theta value

theta_numeric(strike, spot, texp, cp=1)

Option model thegta (sensitivity to time-to-maturity) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

theta value

vanna(strike, spot, texp, cp=1)

Option model vanna (cross-derivative to price and volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

vanna value

vanna_numeric(strike, spot, texp, cp=1)

Option model vanna (cross-derivative to price and volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

vanna value

vega(strike, spot, texp, cp=1)

Option model vega (sensitivity to volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

Returns

vega value

vega_numeric(strike, spot, texp, cp=1)

Option model vega (sensitivity to volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

Returns

vega value

vol_for_price(strike, spot, texp)[source]

Equivalent volatility of the SABR model

Parameters
  • strike – strike price

  • spot – spot (or forward)

  • texp – time to expiry

Returns

equivalent volatility

vol_from_mass_zero(strike, spot, texp, mass=None)

Implied volatility from positive mass at zero from DMHJ (2017) If mass is given, use the given value. If None (by default), compute model implied value.

Parameters
  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • mass – probability mass at zero (None by default)

Returns

implied BSM volatility

References

De Marco, S., Hillairet, C., & Jacquier, A. (2017). Shapes of Implied Volatility with Positive Mass at Zero. SIAM Journal on Financial Mathematics, 8(1), 709–737. https://doi.org/10.1137/14098065X

vol_smile(strike, spot, texp, cp=1, model=None)

Equivalent volatility smile for a given model

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

  • model – {‘bsm’, ‘norm’} ‘bsm’ (by default) for Black-Scholes-Merton, ‘norm’ for Bachelier

Returns

volatility smile under the specified model

volga(strike, spot, texp, cp=1)

Option model volga (2nd derivative to volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

volga value

volga_numeric(strike, spot, texp, cp=1)

Option model volga (2nd derivative to volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

volga value

class SabrChoiWu2021P(sigma, vov=0.0, rho=0.0, beta=1.0, intr=0.0, divr=0.0, is_fwd=False, vol_beta=None)[source]

The CEV volatility approximation of the SABR modelbased on Theorem 2 of Choi & Wu (2019)

References

  • Choi, J., & Wu, L. (2019). The equivalent constant-elasticity-of-variance (CEV) volatility of the stochastic-alpha-beta-rho (SABR) model. ArXiv:1911.13123 [q-Fin]. https://arxiv.org/abs/1911.13123

Examples

>>> import numpy as np
>>> import pyfeng as pf
>>> m = pf.SabrChoiWu2021P(sigma=2, vov=0.2, rho=-0.3, beta=0.5)
>>> m.vol_for_price(np.arange(80, 121, 10), 100, 1.2)
array([2.07761123, 2.03665311, 2.00332   , 1.97718783, 1.95781579])
>>> m.price(np.arange(80, 121, 10), 100, 1.2)
array([22.0470526 , 14.56114825,  8.74169054,  4.72447547,  2.29018838])
base_model(vol, is_fwd=None)

Create base model based on _base_beta value: Norm for 0, Cev for (0,1), and Bsm for 1 If _base_beta is None, use base instead.

Parameters
  • vol – base model volatility

  • is_fwd – if True, treat spot as forward price. False by default.

Returns: model

delta(strike, spot, texp, cp=1)

Option model delta (sensitivity to price) by finite difference

Parameters
  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

Returns

delta value

delta_numeric(strike, spot, texp, cp=1)

Option model delta (sensitivity to price) by finite difference

Parameters
  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

Returns

delta value

forward(spot, texp)

Forward price

Parameters
  • spot – spot price

  • texp – time to expiry

Returns

forward price

gamma(strike, spot, texp, cp=1)

Option model gamma (2nd derivative to price) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

Delta with numerical derivative

gamma_numeric(strike, spot, texp, cp=1)

Option model gamma (2nd derivative to price) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

Delta with numerical derivative

impvol(price, strike, spot, texp, cp=1, setval=False)

Implied volatility using Brent’s method. Slow but robust implementation.

Parameters
  • price – option price

  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put

  • setval – if True, sigma is set with the solved implied volatility

Returns

implied volatility

impvol_brentq(price, strike, spot, texp, cp=1, setval=False)

Implied volatility using Brent’s method. Slow but robust implementation.

Parameters
  • price – option price

  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put

  • setval – if True, sigma is set with the solved implied volatility

Returns

implied volatility

classmethod init_benchmark(set_no=None)

Initiate a SABR model with stored benchmark parameter sets

Parameters

set_no – set number

Returns

Dataframe of all test cases if set_no = None (model, Dataframe of result, params) if set_no is specified

References

  • Antonov, Alexander, Konikov, M., & Spector, M. (2013). SABR spreads its wings. Risk, 2013(Aug), 58–63.

  • Antonov, Alexandre, Konikov, M., & Spector, M. (2019). Modern SABR Analytics. Springer International Publishing. https://doi.org/10.1007/978-3-030-10656-0

  • Antonov, Alexandre, & Spector, M. (2012). Advanced analytics for the SABR model. Available at SSRN. https://ssrn.com/abstract=2026350

  • Cai, N., Song, Y., & Chen, N. (2017). Exact Simulation of the SABR Model. Operations Research, 65(4), 931–951. https://doi.org/10.1287/opre.2017.1617

  • Korn, R., & Tang, S. (2013). Exact analytical solution for the normal SABR model. Wilmott Magazine, 2013(7), 64–69. https://doi.org/10.1002/wilm.10235

  • Lewis, A. L. (2016). Option valuation under stochastic volatility II: With Mathematica code. Finance Press.

  • von Sydow, L., …, Haentjens, T., & Waldén, J. (2018). BENCHOP - SLV: The BENCHmarking project in Option Pricing – Stochastic and Local Volatility problems. International Journal of Computer Mathematics, 1–14. https://doi.org/10.1080/00207160.2018.1544368

mass_zero(spot, texp, log=False)

Probability mass absorbed at the zero boundary (K=0)

Parameters
  • spot – spot (or forward) price

  • texp – time to expiry

  • log – log value if True

Returns

(log) probability mass at zero

mass_zero_t0(spot, texp)

Limit value of -T log(M_T) as T -> 0, where M_T is the mass at zero. See Corollary 3.1 of Choi & Wu (2019)

Parameters
  • spot – spot (or forward) price

  • texp – time to expiry

Returns

-lim_{T->0} T log(M_T)

params_kw()

Model parameters in dictionary

pdf_numeric(strike, spot, texp, cp=- 1, h=0.001)

Probability density functin (PDF) at strike

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

probability densitiy

price(strike, spot, texp, cp=1)

Call/put option price.

Parameters
  • strike – strike price.

  • spot – spot (or forward) price.

  • texp – time to expiry.

  • cp – 1/-1 for call/put option.

Returns

option price

theta(strike, spot, texp, cp=1)

Option model thegta (sensitivity to time-to-maturity) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

theta value

theta_numeric(strike, spot, texp, cp=1)

Option model thegta (sensitivity to time-to-maturity) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

theta value

vanna(strike, spot, texp, cp=1)

Option model vanna (cross-derivative to price and volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

vanna value

vanna_numeric(strike, spot, texp, cp=1)

Option model vanna (cross-derivative to price and volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

vanna value

vega(strike, spot, texp, cp=1)

Option model vega (sensitivity to volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

Returns

vega value

vega_numeric(strike, spot, texp, cp=1)

Option model vega (sensitivity to volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

Returns

vega value

vol_for_price(strike, spot, texp)[source]

Equivalent volatility of the SABR model

Parameters
  • strike – strike price

  • spot – spot (or forward)

  • texp – time to expiry

Returns

equivalent volatility

vol_from_mass_zero(strike, spot, texp, mass=None)

Implied volatility from positive mass at zero from DMHJ (2017) If mass is given, use the given value. If None (by default), compute model implied value.

Parameters
  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • mass – probability mass at zero (None by default)

Returns

implied BSM volatility

References

De Marco, S., Hillairet, C., & Jacquier, A. (2017). Shapes of Implied Volatility with Positive Mass at Zero. SIAM Journal on Financial Mathematics, 8(1), 709–737. https://doi.org/10.1137/14098065X

vol_smile(strike, spot, texp, cp=1, model=None)

Equivalent volatility smile for a given model

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

  • model – {‘bsm’, ‘norm’} ‘bsm’ (by default) for Black-Scholes-Merton, ‘norm’ for Bachelier

Returns

volatility smile under the specified model

volga(strike, spot, texp, cp=1)

Option model volga (2nd derivative to volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

volga value

volga_numeric(strike, spot, texp, cp=1)

Option model volga (2nd derivative to volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

volga value

class SabrHagan2002(sigma, vov=0.0, rho=0.0, beta=1.0, intr=0.0, divr=0.0, is_fwd=False)[source]

SABR model with Hagan’s implied volatility approximation for 0<beta<=1.

References

Hagan, P. S., Kumar, D., Lesniewski, A. S., & Woodward, D. E. (2002). Managing Smile Risk. Wilmott, September, 84–108.

Examples

>>> import numpy as np
>>> import pyfeng as pf
>>> m = pf.SabrHagan2002(sigma=2, vov=0.2, rho=-0.3, beta=0.5)
>>> m.vol_for_price(np.arange(80, 121, 10), 100, 1.2)
array([0.21976016, 0.20922027, 0.200432  , 0.19311113, 0.18703486])
>>> m.price(np.arange(80, 121, 10), 100, 1.2)
array([22.04862858, 14.56226187,  8.74170415,  4.72352155,  2.28891776])
base_model(vol, is_fwd=None)

Create base model based on _base_beta value: Norm for 0, Cev for (0,1), and Bsm for 1 If _base_beta is None, use base instead.

Parameters
  • vol – base model volatility

  • is_fwd – if True, treat spot as forward price. False by default.

Returns: model

calibrate3(price_or_vol3, strike3, spot, texp, cp=1, setval=False, is_vol=True)[source]

Given option prices or implied vols at 3 strikes, compute the sigma, vov, rho to fit the data using scipy.optimize.root. If prices are given (is_vol=False) convert the prices to vol first.

Parameters
  • price_or_vol3 – 3 prices or 3 volatilities (depending on is_vol)

  • strike3 – 3 strike prices

  • spot – spot price

  • texp – time to expiry

  • cp – cp

  • setval – if True, set sigma, vov, rho values

  • is_vol – if True, price_or_vol3 are volatilities.

Returns

Dictionary of sigma, vov, and rho.

delta(strike, spot, texp, cp=1)

Option model delta (sensitivity to price) by finite difference

Parameters
  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

Returns

delta value

delta_numeric(strike, spot, texp, cp=1)

Option model delta (sensitivity to price) by finite difference

Parameters
  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

Returns

delta value

forward(spot, texp)

Forward price

Parameters
  • spot – spot price

  • texp – time to expiry

Returns

forward price

gamma(strike, spot, texp, cp=1)

Option model gamma (2nd derivative to price) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

Delta with numerical derivative

gamma_numeric(strike, spot, texp, cp=1)

Option model gamma (2nd derivative to price) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

Delta with numerical derivative

impvol(price, strike, spot, texp, cp=1, setval=False)

Implied volatility using Brent’s method. Slow but robust implementation.

Parameters
  • price – option price

  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put

  • setval – if True, sigma is set with the solved implied volatility

Returns

implied volatility

impvol_brentq(price, strike, spot, texp, cp=1, setval=False)

Implied volatility using Brent’s method. Slow but robust implementation.

Parameters
  • price – option price

  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put

  • setval – if True, sigma is set with the solved implied volatility

Returns

implied volatility

classmethod init_benchmark(set_no=None)

Initiate a SABR model with stored benchmark parameter sets

Parameters

set_no – set number

Returns

Dataframe of all test cases if set_no = None (model, Dataframe of result, params) if set_no is specified

References

  • Antonov, Alexander, Konikov, M., & Spector, M. (2013). SABR spreads its wings. Risk, 2013(Aug), 58–63.

  • Antonov, Alexandre, Konikov, M., & Spector, M. (2019). Modern SABR Analytics. Springer International Publishing. https://doi.org/10.1007/978-3-030-10656-0

  • Antonov, Alexandre, & Spector, M. (2012). Advanced analytics for the SABR model. Available at SSRN. https://ssrn.com/abstract=2026350

  • Cai, N., Song, Y., & Chen, N. (2017). Exact Simulation of the SABR Model. Operations Research, 65(4), 931–951. https://doi.org/10.1287/opre.2017.1617

  • Korn, R., & Tang, S. (2013). Exact analytical solution for the normal SABR model. Wilmott Magazine, 2013(7), 64–69. https://doi.org/10.1002/wilm.10235

  • Lewis, A. L. (2016). Option valuation under stochastic volatility II: With Mathematica code. Finance Press.

  • von Sydow, L., …, Haentjens, T., & Waldén, J. (2018). BENCHOP - SLV: The BENCHmarking project in Option Pricing – Stochastic and Local Volatility problems. International Journal of Computer Mathematics, 1–14. https://doi.org/10.1080/00207160.2018.1544368

params_kw()

Model parameters in dictionary

pdf_numeric(strike, spot, texp, cp=- 1, h=0.001)

Probability density functin (PDF) at strike

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

probability densitiy

price(strike, spot, texp, cp=1)

Call/put option price.

Parameters
  • strike – strike price.

  • spot – spot (or forward) price.

  • texp – time to expiry.

  • cp – 1/-1 for call/put option.

Returns

option price

theta(strike, spot, texp, cp=1)

Option model thegta (sensitivity to time-to-maturity) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

theta value

theta_numeric(strike, spot, texp, cp=1)

Option model thegta (sensitivity to time-to-maturity) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

theta value

vanna(strike, spot, texp, cp=1)

Option model vanna (cross-derivative to price and volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

vanna value

vanna_numeric(strike, spot, texp, cp=1)

Option model vanna (cross-derivative to price and volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

vanna value

vega(strike, spot, texp, cp=1)

Option model vega (sensitivity to volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

Returns

vega value

vega_numeric(strike, spot, texp, cp=1)

Option model vega (sensitivity to volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

Returns

vega value

vol_for_price(strike, spot, texp)[source]

Equivalent volatility of the SABR model

Parameters
  • strike – strike price

  • spot – spot (or forward)

  • texp – time to expiry

Returns

equivalent volatility

vol_smile(strike, spot, texp, cp=1, model=None)

Equivalent volatility smile for a given model

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

  • model – {‘bsm’, ‘norm’} ‘bsm’ (by default) for Black-Scholes-Merton, ‘norm’ for Bachelier

Returns

volatility smile under the specified model

volga(strike, spot, texp, cp=1)

Option model volga (2nd derivative to volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

volga value

volga_numeric(strike, spot, texp, cp=1)

Option model volga (2nd derivative to volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

volga value

class SabrLorig2017(sigma, vov=0.0, rho=0.0, beta=1.0, intr=0.0, divr=0.0, is_fwd=False)[source]

Third-order BSM volatilty approximation of the SABR model by Lorig et al. (2017)

References

Lorig, M., Pagliarani, S., & Pascucci, A. (2017). Explicit Implied Volatilities for Multifactor Local-Stochastic Volatility Models. Mathematical Finance, 27(3), 926–960. https://doi.org/10.1111/mafi.12105

base_model(vol, is_fwd=None)

Create base model based on _base_beta value: Norm for 0, Cev for (0,1), and Bsm for 1 If _base_beta is None, use base instead.

Parameters
  • vol – base model volatility

  • is_fwd – if True, treat spot as forward price. False by default.

Returns: model

delta(strike, spot, texp, cp=1)

Option model delta (sensitivity to price) by finite difference

Parameters
  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

Returns

delta value

delta_numeric(strike, spot, texp, cp=1)

Option model delta (sensitivity to price) by finite difference

Parameters
  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

Returns

delta value

forward(spot, texp)

Forward price

Parameters
  • spot – spot price

  • texp – time to expiry

Returns

forward price

gamma(strike, spot, texp, cp=1)

Option model gamma (2nd derivative to price) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

Delta with numerical derivative

gamma_numeric(strike, spot, texp, cp=1)

Option model gamma (2nd derivative to price) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

Delta with numerical derivative

impvol(price, strike, spot, texp, cp=1, setval=False)

Implied volatility using Brent’s method. Slow but robust implementation.

Parameters
  • price – option price

  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put

  • setval – if True, sigma is set with the solved implied volatility

Returns

implied volatility

impvol_brentq(price, strike, spot, texp, cp=1, setval=False)

Implied volatility using Brent’s method. Slow but robust implementation.

Parameters
  • price – option price

  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put

  • setval – if True, sigma is set with the solved implied volatility

Returns

implied volatility

classmethod init_benchmark(set_no=None)

Initiate a SABR model with stored benchmark parameter sets

Parameters

set_no – set number

Returns

Dataframe of all test cases if set_no = None (model, Dataframe of result, params) if set_no is specified

References

  • Antonov, Alexander, Konikov, M., & Spector, M. (2013). SABR spreads its wings. Risk, 2013(Aug), 58–63.

  • Antonov, Alexandre, Konikov, M., & Spector, M. (2019). Modern SABR Analytics. Springer International Publishing. https://doi.org/10.1007/978-3-030-10656-0

  • Antonov, Alexandre, & Spector, M. (2012). Advanced analytics for the SABR model. Available at SSRN. https://ssrn.com/abstract=2026350

  • Cai, N., Song, Y., & Chen, N. (2017). Exact Simulation of the SABR Model. Operations Research, 65(4), 931–951. https://doi.org/10.1287/opre.2017.1617

  • Korn, R., & Tang, S. (2013). Exact analytical solution for the normal SABR model. Wilmott Magazine, 2013(7), 64–69. https://doi.org/10.1002/wilm.10235

  • Lewis, A. L. (2016). Option valuation under stochastic volatility II: With Mathematica code. Finance Press.

  • von Sydow, L., …, Haentjens, T., & Waldén, J. (2018). BENCHOP - SLV: The BENCHmarking project in Option Pricing – Stochastic and Local Volatility problems. International Journal of Computer Mathematics, 1–14. https://doi.org/10.1080/00207160.2018.1544368

params_kw()

Model parameters in dictionary

pdf_numeric(strike, spot, texp, cp=- 1, h=0.001)

Probability density functin (PDF) at strike

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

probability densitiy

price(strike, spot, texp, cp=1)

Call/put option price.

Parameters
  • strike – strike price.

  • spot – spot (or forward) price.

  • texp – time to expiry.

  • cp – 1/-1 for call/put option.

Returns

option price

theta(strike, spot, texp, cp=1)

Option model thegta (sensitivity to time-to-maturity) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

theta value

theta_numeric(strike, spot, texp, cp=1)

Option model thegta (sensitivity to time-to-maturity) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

theta value

vanna(strike, spot, texp, cp=1)

Option model vanna (cross-derivative to price and volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

vanna value

vanna_numeric(strike, spot, texp, cp=1)

Option model vanna (cross-derivative to price and volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

vanna value

vega(strike, spot, texp, cp=1)

Option model vega (sensitivity to volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

Returns

vega value

vega_numeric(strike, spot, texp, cp=1)

Option model vega (sensitivity to volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

Returns

vega value

vol_for_price(strike, spot, texp)[source]

Equivalent volatility of the SABR model

Parameters
  • strike – strike price

  • spot – spot (or forward)

  • texp – time to expiry

Returns

equivalent volatility

vol_smile(strike, spot, texp, cp=1, model=None)

Equivalent volatility smile for a given model

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

  • model – {‘bsm’, ‘norm’} ‘bsm’ (by default) for Black-Scholes-Merton, ‘norm’ for Bachelier

Returns

volatility smile under the specified model

volga(strike, spot, texp, cp=1)

Option model volga (2nd derivative to volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

volga value

volga_numeric(strike, spot, texp, cp=1)

Option model volga (2nd derivative to volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

volga value

class SabrNormVolApprox(sigma, vov=0.0, rho=0.0, beta=None, intr=0.0, divr=0.0, is_fwd=False, is_atmvol=False)[source]

Noram SABR model (beta=0) with normal volatility approximation.

Examples

>>> import numpy as np
>>> import pyfeng as pf
>>> m = pf.SabrNormVolApprox(sigma=20, vov=0.8, rho=-0.3)
>>> m.vol_for_price(np.arange(80, 121, 10), 100, 1.2)
array([24.97568842, 22.78062691, 21.1072    , 20.38569729, 20.78963436])
>>> m.price(np.arange(80, 121, 10), 100, 1.2)
array([23.70791426, 15.74437409,  9.22425529,  4.78754361,  2.38004685])
base_model(vol, is_fwd=None)

Create base model based on _base_beta value: Norm for 0, Cev for (0,1), and Bsm for 1 If _base_beta is None, use base instead.

Parameters
  • vol – base model volatility

  • is_fwd – if True, treat spot as forward price. False by default.

Returns: model

delta(strike, spot, texp, cp=1)

Option model delta (sensitivity to price) by finite difference

Parameters
  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

Returns

delta value

delta_numeric(strike, spot, texp, cp=1)

Option model delta (sensitivity to price) by finite difference

Parameters
  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

Returns

delta value

forward(spot, texp)

Forward price

Parameters
  • spot – spot price

  • texp – time to expiry

Returns

forward price

gamma(strike, spot, texp, cp=1)

Option model gamma (2nd derivative to price) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

Delta with numerical derivative

gamma_numeric(strike, spot, texp, cp=1)

Option model gamma (2nd derivative to price) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

Delta with numerical derivative

impvol(price, strike, spot, texp, cp=1, setval=False)

Implied volatility using Brent’s method. Slow but robust implementation.

Parameters
  • price – option price

  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put

  • setval – if True, sigma is set with the solved implied volatility

Returns

implied volatility

impvol_brentq(price, strike, spot, texp, cp=1, setval=False)

Implied volatility using Brent’s method. Slow but robust implementation.

Parameters
  • price – option price

  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put

  • setval – if True, sigma is set with the solved implied volatility

Returns

implied volatility

classmethod init_benchmark(set_no=None)

Initiate a SABR model with stored benchmark parameter sets

Parameters

set_no – set number

Returns

Dataframe of all test cases if set_no = None (model, Dataframe of result, params) if set_no is specified

References

  • Antonov, Alexander, Konikov, M., & Spector, M. (2013). SABR spreads its wings. Risk, 2013(Aug), 58–63.

  • Antonov, Alexandre, Konikov, M., & Spector, M. (2019). Modern SABR Analytics. Springer International Publishing. https://doi.org/10.1007/978-3-030-10656-0

  • Antonov, Alexandre, & Spector, M. (2012). Advanced analytics for the SABR model. Available at SSRN. https://ssrn.com/abstract=2026350

  • Cai, N., Song, Y., & Chen, N. (2017). Exact Simulation of the SABR Model. Operations Research, 65(4), 931–951. https://doi.org/10.1287/opre.2017.1617

  • Korn, R., & Tang, S. (2013). Exact analytical solution for the normal SABR model. Wilmott Magazine, 2013(7), 64–69. https://doi.org/10.1002/wilm.10235

  • Lewis, A. L. (2016). Option valuation under stochastic volatility II: With Mathematica code. Finance Press.

  • von Sydow, L., …, Haentjens, T., & Waldén, J. (2018). BENCHOP - SLV: The BENCHmarking project in Option Pricing – Stochastic and Local Volatility problems. International Journal of Computer Mathematics, 1–14. https://doi.org/10.1080/00207160.2018.1544368

params_kw()

Model parameters in dictionary

pdf_numeric(strike, spot, texp, cp=- 1, h=0.001)

Probability density functin (PDF) at strike

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

probability densitiy

price(strike, spot, texp, cp=1)

Call/put option price.

Parameters
  • strike – strike price.

  • spot – spot (or forward) price.

  • texp – time to expiry.

  • cp – 1/-1 for call/put option.

Returns

option price

theta(strike, spot, texp, cp=1)

Option model thegta (sensitivity to time-to-maturity) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

theta value

theta_numeric(strike, spot, texp, cp=1)

Option model thegta (sensitivity to time-to-maturity) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

theta value

vanna(strike, spot, texp, cp=1)

Option model vanna (cross-derivative to price and volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

vanna value

vanna_numeric(strike, spot, texp, cp=1)

Option model vanna (cross-derivative to price and volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

vanna value

vega(strike, spot, texp, cp=1)

Option model vega (sensitivity to volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

Returns

vega value

vega_numeric(strike, spot, texp, cp=1)

Option model vega (sensitivity to volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot (or forward) price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

Returns

vega value

vol_for_price(strike, spot, texp)[source]

Equivalent volatility of the SABR model

Parameters
  • strike – strike price

  • spot – spot (or forward)

  • texp – time to expiry

Returns

equivalent volatility

vol_smile(strike, spot, texp, cp=1, model=None)

Equivalent volatility smile for a given model

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put option

  • model – {‘bsm’, ‘norm’} ‘bsm’ (by default) for Black-Scholes-Merton, ‘norm’ for Bachelier

Returns

volatility smile under the specified model

volga(strike, spot, texp, cp=1)

Option model volga (2nd derivative to volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

volga value

volga_numeric(strike, spot, texp, cp=1)

Option model volga (2nd derivative to volatility) by finite difference

Parameters
  • strike – strike price

  • spot – spot price

  • texp – time to expiry

  • cp – 1/-1 for call/put

Returns

volga value