# vollib.helper package¶

## vollib.helper.numerical_greeks module¶

### vollib.helper.numerical_greeks¶

A library for option pricing, implied volatility, and greek calculation. vollib is based on lets_be_rational, a Python wrapper for LetsBeRational by Peter Jaeckel as described below.

copyright: © 2015 Iota Technologies Pte Ltd MIT, see LICENSE for more details.

The source code of LetsBeRational resides at www.jaeckel.org/LetsBeRational.7z .

```======================================================================================

Permission to use, copy, modify, and distribute this software is freely granted,
provided that this notice is preserved.

WARRANTY DISCLAIMER
The Software is provided "as is" without warranty of any kind, either express or implied,
including without limitation any implied warranties of condition, uninterrupted use,
merchantability, fitness for a particular purpose, or non-infringement.
======================================================================================
```

### Note about the parameter “b”:¶

```======================================================================================
from Espen Gaarder Haug's
"The Complete Guide to Option Pricing Formulas," Second Edition,
page 90.

+-----------+------------------------------------------------------+
| b = r     |  gives the Black and Scholes (1973) stock option     |
|           |  model                                               |
+-----------+------------------------------------------------------+
| b = r -q  |  gives the Merton (1973) stock option model with     |
|           |  continuous dividend yield q                         |
+-----------+------------------------------------------------------+
| b = 0     |  gives the Black (1976) futures option model         |
+-----------+------------------------------------------------------+
| b = 0 and |  gives the Asay (1982) margined futures option model |
| r = 0     |                                                      |
+-----------+------------------------------------------------------+
======================================================================================
```
`vollib.helper.numerical_greeks.``delta`(flag, S, K, t, r, sigma, b, pricing_function)[source]

Calculate option delta using numerical integration.

Parameters: S (float) – underlying asset price K (float) – strike price sigma (float) – annualized standard deviation, or volatility t (float) – time to expiration in years r (float) – risk-free interest rate b (float) – see above flag (str) – ‘c’ or ‘p’ for call or put. pricing_function (python function object) – any function returning the price of an option
`vollib.helper.numerical_greeks.``gamma`(flag, S, K, t, r, sigma, b, pricing_function)[source]

Calculate option gamma using numerical integration.

Parameters: S (float) – underlying asset price K (float) – strike price sigma (float) – annualized standard deviation, or volatility t (float) – time to expiration in years r (float) – risk-free interest rate b (float) – see above flag (str) – ‘c’ or ‘p’ for call or put. pricing_function (python function object) – any function returning the price of an option
`vollib.helper.numerical_greeks.``rho`(flag, S, K, t, r, sigma, b, pricing_function)[source]

Calculate option rho using numerical integration.

Parameters: S (float) – underlying asset price K (float) – strike price sigma (float) – annualized standard deviation, or volatility t (float) – time to expiration in years r (float) – risk-free interest rate b (float) – see above flag (str) – ‘c’ or ‘p’ for call or put. pricing_function (python function object) – any function returning the price of an option
`vollib.helper.numerical_greeks.``theta`(flag, S, K, t, r, sigma, b, pricing_function)[source]

Calculate option theta using numerical integration.

Parameters: S (float) – underlying asset price K (float) – strike price sigma (float) – annualized standard deviation, or volatility t (float) – time to expiration in years r (float) – risk-free interest rate b (float) – see above flag (str) – ‘c’ or ‘p’ for call or put. pricing_function (python function object) – any function returning the price of an option
`vollib.helper.numerical_greeks.``vega`(flag, S, K, t, r, sigma, b, pricing_function)[source]

Calculate option vega using numerical integration.

Parameters: S (float) – underlying asset price K (float) – strike price sigma (float) – annualized standard deviation, or volatility t (float) – time to expiration in years r (float) – risk-free interest rate b (float) – see above flag (str) – ‘c’ or ‘p’ for call or put. pricing_function (python function object) – any function returning the price of an option

## Module contents¶

### vollib.helper¶

A library for option pricing, implied volatility, and greek calculation. vollib is based on lets_be_rational, a Python wrapper for LetsBeRational by Peter Jaeckel as described below.

copyright: © 2015 Iota Technologies Pte Ltd MIT, see LICENSE for more details.

The source code of LetsBeRational resides at www.jaeckel.org/LetsBeRational.7z .

```======================================================================================

Permission to use, copy, modify, and distribute this software is freely granted,
provided that this notice is preserved.

WARRANTY DISCLAIMER
The Software is provided "as is" without warranty of any kind, either express or implied,
including without limitation any implied warranties of condition, uninterrupted use,
merchantability, fitness for a particular purpose, or non-infringement.
======================================================================================
```
`vollib.helper.``forward_price`(S, t, r)[source]

Calculate the forward price of an underlying asset.

Parameters: S (float) – underlying asset price t (float) – time to expiration in years r (float) – risk-free interest rate
```>>> S = 95
>>> t = .5
>>> r = .02
>>> F = forward_price(S,t,r)
>>> pre_calculated = 95.95476587299596
>>> abs(F-pre_calculated)<.000000001
True
```
`vollib.helper.``pdf`(x)

the probability density function

Parameters: x – a continuous random variable
`vollib.helper.``test_binary_flag`()[source]
```========================================================

Note:  In "Let's be Rational," Peter Jäckel uses θ as a flag
to distinguish between puts and calls.
+1 represents a call, -1 represents a put.

See page 1, Introduction, first paragraph.

Throughout vollib this is replaced with 'c' and 'p'.
========================================================
```
```>>> binary_flag['c']
1
>>> binary_flag['p']
-1
```