numerical

cosmethod

Implementation of the COS method

This implementation is based on the paper ‘A novel pricing method for European options based on Fourier-cosine series expansions’ by Fang and Osterlee.

class COSPricer(model: LevyModel, n: int = 10000, l: int = 10)[source]

Bases: object

COS pricer object: this method can price vanilla options for any stochastic process for which the characteristic function is known in analytically form.

Note

Extension for Bermudan/American products is not yet implemented.

__init__(model: LevyModel, n: int = 10000, l: int = 10)[source]
Parameters
  • model – Lévy stochastic model

  • n – number of points used in the pricing method

  • l – cut-off

density_log(time: float, u: array)[source]

Log-density function of the Lévy stochastic process :param time: time :param u: space parameter :return: the value of the log-density function in (t,u)

density(time: float, s: array)[source]

Density function of the Lévy stochastic process :param time: time :param s: space parameter :return: the value of the density function in (t,s)

cdf(time: float, x: float)[source]

Cumulative distribution function of the Lévy stochastic process i.e. P(S_t < x) where S_t = S_0 exp(X_t) and X_t is a Lévy process :param time: time :param x: space parameter :return: the value of the cumulative function in (t,x)

static psi(ks: ndarray[Any, dtype[int]], a: float, b: float, c: float, d: float)[source]
static xi(k: ndarray[Any, dtype[int]], a: float, b: float, c: float, d: float)[source]
static u_put(k, a, b)[source]
forward(strikes, time)[source]
Parameters
  • strikes – vector of strikes

  • time – time maturity

Returns

the price vector of the forward contracts with the given strikes

put(strikes, time)[source]
Parameters
  • strikes – strike vector

  • time – time maturity

Returns

the price vector of the put options with the given strikes

call(strikes, time)[source]
Parameters
  • strikes – strike vector

  • time – time maturity

Returns

the price vector of the call options with the given strikes

Note

the call-put parity formula is used in this case

butterfly(strike1, strike2, strike3, time)[source]

Price of a butterfly option

Parameters
  • strike1 – left strike

  • strike2 – middle strike

  • strike3 – right strike

  • time – time maturity

Returns

the price of the butterfly option

digital(strikes, time)[source]

Price of a digital option which, at the time maturity, pays 1 if S_T > K else 0

Parameters
  • strikes – digital strike

  • time – digital maturity

Returns

the price vector of the digital options with the given strikes

price(product: Product) Union[float, array][source]

Generic function to price vanilla options with the COS method.

Parameters

product – vanilla product

Returns

the price of the product given by the COS method

Note

only Forward, Call and Put options are supported for now.

fft

Fast-Fourier Transform pricer

This is the implementation of call/put pricing from ‘Option Valuation Using the Fast Fourier Transform’ by Carr and Madan

class FFTPricer(model: LevyModel)[source]

Bases: object

Fast Fourier Transform pricer

__init__(model: LevyModel)[source]
Parameters

model – Lévy model

call(strike: Union[float, list[float]], maturity: float) float[source]

Call price

Parameters
  • strike – call strike

  • maturity – call maturity

Returns

the value of the call option

put(strike: Union[float, list[float]], maturity: float) float[source]

Put price calculated from the call/put parity formula

Parameters
  • strike – put strike

  • maturity – put maturity

Returns

the value of the put option

density(time, u)[source]

Density function implied from the FFT method

numbers

Functions related to number theory

functions inv_guess_a and upper_bound_a_n are inspired from http://www.mac-guyver.com/switham/2020/03/HyperbolicPairing/hyperbolic_pairing_v0.5.pdf

a_n(n)[source]

See https://oeis.org/A006218 for more details

Returns

the sequence of the sum of the divisor of k for k in [1,n]

inv_guess_a(c)[source]

Helper function

upper_bound_a_n(z)[source]

Find the “inverse” of a_n defined as n such that a_n(n-1) <= z

We know that a_n is an increasing function

tools

Generic helper functions

sign(x)[source]
sign(x: float)
interval_I(x: float) tuple[float, float][source]
Returns

left or right interval depending on the sign of x