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:
objectCOS 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)
- 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
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:
objectFast Fourier Transform pricer
- 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
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]
tools
Generic helper functions