distribution

Simulation algorithms and tools for sampling of univariates and variates

levycopula

Lévy Copula

For general definitions and properties, see the seminal paper ‘Characterization of dependence of multidimensional Lévy processes using Lévy copulas’ by Kallsen and Tankov

class LevyCopula[source]

Bases: object

Lévy copula function

conditional_distribution(eps: float, x: array) array[source]

The conditional distribution \(F_{\mathcal{E}}(x)\) as defined in ‘Lévy copulas: review of recent results’ by Peter Tankov

inverse_conditional_distribution(eps: array, x: array) array[source]
x_first_derivative(u: array) float[source]

Derivative of the Lévy copula with regard to \(u_i, u_j,\dots\) times the product \(u_i*u_j*\dots\)

Param

\(u\) -> variables \(u_i, u_j,\dots\)

class ClaytonCopula(theta: float, eta: float)[source]

Bases: LevyCopula

The Clayton copula function is parametrised by theta and eta. See formula (7) in ‘Lévy copulas: review of recent results’ by Peter Tankov

__init__(theta: float, eta: float)[source]
property theta
conditional_distribution(eps: float, x: array) array[source]

The conditional distribution \(F_{\mathcal{E}}(x)\) as defined in ‘Lévy copulas: review of recent results’ by Peter Tankov

inverse_conditional_distribution(eps: array, x: array) array[source]
x_first_derivative(u: array) float[source]

Derivative of the Lévy copula with regard to \(u_i, u_j,\dots\) times the product \(u_i*u_j*\dots\)

Param

\(u\) -> variables \(u_i, u_j,\dots\)

class IndependentComponentsCopula[source]

Bases: LevyCopula

In this case, the margins are independent, see formula (4.2) in ‘Characterization of dependence of multidimensional Lévy processes using Lévy copulas’ by Kallsen and Tankov

class DependentComponentsCopula[source]

Bases: LevyCopula

In this case, the margins are completely dependent, see formula (4.3) in ‘Characterization of dependence of multidimensional Lévy processes using Lévy copulas’ by Kallsen and Tankov

conditional_distribution(eps: float, x: array) array[source]

The conditional distribution \(F_{\mathcal{E}}(x)\) as defined in ‘Lévy copulas: review of recent results’ by Peter Tankov

inverse_conditional_distribution(eps: array, x: array) array[source]
class FrankLevyCopula(eta: float)[source]

Bases: LevyCopula

The Frank-Lévy copula is parametrised by eta, see the formula (32) (2d case) in ‘A Structural Jump Threshold Framework for Credit Risk’ by Garreau and Kercheval

__init__(eta: float)[source]
property eta

pairing

Definition of pairing functions and their inverse

A pairing function is a bijection between integers and \(N^k\), see https://en.wikipedia.org/wiki/Pairing_function for more details and also the paper “The Rosenberg-Strong Pairing Function” by Matthew P. Szudzik (https://arxiv.org/abs/1706.04129)

Here we define extend the pairing functions to Z

class Pairing[source]

Bases: object

Pairing function

pairing(x: tuple[int, ...]) int[source]
projection(z: int, dim=2) tuple[int, ...][source]
static pairing2d(x: int, y: int) int[source]
static projection2d(z: int) tuple[int, int][source]
class Cantor[source]

Bases: Pairing

The famous Cantor pairing

projection(z: int, dim=2) tuple[int, ...][source]
static pairing2d(x: int, y: int) int[source]
static projection2d(z: int) tuple[int, int][source]
class RosenbergStrong[source]

Bases: Pairing

pairing(x: tuple[int, ...]) int[source]
projection(z: int, dim=2) tuple[int, ...][source]
static pairing2d(x: int, y: int) int[source]
static projection2d(z: int) tuple[int, int][source]
class Szudzik[source]

Bases: Pairing

static pairing2d(x: int, y: int) int[source]
static projection2d(z: int) tuple[int, int][source]
class HyperbolicPairing[source]

Bases: Pairing

From ‘Managing storage for extendible arrays’ by Rosenberg

static pairing2d(x: int, y: int) int[source]
static projection2d(z: int) tuple[int, int][source]
class PepisKalmar[source]

Bases: Pairing

static pairing2d(x: int, y: int) int[source]
static projection2d(z: int) tuple[int, int][source]
mapping_to_z(n: int) int[source]

mapping 0, 1, -1, 2, -2, 3, -3,… to 0, 1, 2, 3, 4, 5, 6,…

projection_to_z(z: int) int[source]

mapping 0, 1, 2, 3, 4, 5, 6,… to 0, 1, -1, 2, -2, 3, -3,…

class PairingToZd(pairing: Pairing, dimension: int = 2, omit_zero: bool = True)[source]

Bases: object

Pairing \(\mathbb{N}\) with \(\mathbb{Z}^d\)

__init__(pairing: Pairing, dimension: int = 2, omit_zero: bool = True)[source]
project(x: int)[source]
pair(x: tuple[int, ...]) int[source]
pairing(x: tuple[int, ...]) int[source]
projection(n) tuple[int, ...][source]
class PairingToZ1d(interval: tuple[int, int], omit_zero: bool = True)[source]

Bases: object

Mapping 0, 1, 2, 3,… to the states in an interval \([-L, R], L>0, R>0, L\neq R\)

__init__(interval: tuple[int, int], omit_zero: bool = True)[source]
project(x: int)[source]
pair(x: int) int[source]
class Boundary[source]

Bases: object

Boundary for a domain, the default is that there is no boundary

class RectangleBoundary(truncations: list[tuple[int, int]])[source]

Bases: Boundary

__init__(truncations: list[tuple[int, int]])[source]
class SimplexBoundary(truncations: list[tuple[int, int]])[source]

Bases: Boundary

__init__(truncations: list[tuple[int, int]])[source]
class MyBoundary(truncations: list[tuple[int, int]], threshold: float)[source]

Bases: Boundary

__init__(truncations: list[tuple[int, int]], threshold: float)[source]
static b_fun(x: float, r1, r2, c)[source]
class Domain(boundary: Boundary, grid: CTMCGrid, pairing: PairingToZd)[source]

Bases: object

A domain D is a “regular” volume which meets the following assumptions:
  • it contains the origin

  • there is point \(z = (z_1, z_2, ...., z_n)\) in D such that \(|z_i| > |x_i|\) where \(x_i\) is the i-th coordinate in \((0,0,..., 0, x_i, 0, ..., 0)\) which is the boundary on the i-th axis of D

  • all hyperplanes are convex

__init__(boundary: Boundary, grid: CTMCGrid, pairing: PairingToZd)[source]
outside(x: Coordinates) bool[source]
compute_total_number_of_states_and_frontier() deque[int][source]
class StatesManager(pairing: PairingToZd, domain: Domain, grid: CTMCGrid)[source]

Bases: object

__init__(pairing: PairingToZd, domain: Domain, grid: CTMCGrid)[source]
Parameters
  • pairing – pairing object

  • domain – domain of the admissible states

  • grid – discretisation grid

is_outside(state_increment)[source]
project_index_to_state_increment(x: int, max_logged: int = -1) tuple[tuple[int, ...], bool][source]

Return the state increment and a boolean which is True if we have exhausted all the states in the domain

Parameters
  • x – current index to be mapped to a state increment

  • max_logged – max logged index

Returns

the state increment and a break condition

sampling

Generic sampling class for continuous or discrete probability distributions

class SamplingMethod(value)[source]

Bases: Enum

Sampling method type

ALIAS = 1
TABLE = 2
BINARYSEARCHTREE = 3
HUFFMANNTREE = 4
INVERSION = 5
BINARYSEARCHTREEADAPTED = 6
BINARYSEARCHTREEADAPTED1D = 7
class Sampling[source]

Bases: object

Base class for sampling method

__init__()[source]
cost() int[source]
Returns

the computing cost of the algorithm for generating the random variable the cost will usually correspond to the number of generated uniform random variables

reset_sampling_cost()[source]

reset the simulation cost to 0

abstract sample(size: int = 1) array[source]

sample a random variable corresponding the distribution in scope

Parameters

size – size of the sampling vector

Returns

the array of simulated variables

samplingfactory

Simple factory function to create a sampling method

compute_intensity_of_jumps(model: Union[LevyModel, LevyCopulaModel], grid: CTMCGrid)[source]
create_q_vector(levy_measure: LevyMeasure, grid: CTMCGrid) array[source]
create_vec_jump_matrix(q_vector: array, init_state, intensity_of_jumps: float)[source]
create_matrix_jump_matrix(q_matrix: array, init_state) array[source]
create_sampling_method(model, levy_measure, method: SamplingMethod, grid: CTMCGrid, is_levy_copula: bool, intensity_of_jumps: float)[source]
create_sampling_inversion_method(grid, model, intensity_of_jumps, is_levy_copula)[source]