grid

grid

Definition of a grid object which will be need to define spatial grid as well as time grid.

class Coordinate1D(coordinate: int)[source]

Bases: object

Coordinate for an axis (one-dimensional grid)

__init__(coordinate: int)[source]
Parameters

coordinate – integer corresponding to the position on the axis

value
class CoordinateND(coordinates: Iterable[int])[source]

Bases: object

Coordinate for a n-dimensional grid

__init__(coordinates: Iterable[int])[source]
Parameters

coordinates – list of integers corresponding to the coordinates (positions) on each axis

value
class Coordinates(coordinates)[source]

Bases: object

General Coordinates object which handles both one-dimensional and n-dimensional cases

class Grid(axes: list[numpy.array])[source]

Bases: object

A grid is a set of axes, each of them being in the form of an interval [a_0,a_1,…,a_K], and i is the position of the i-th element a_i.

Example

For a 2d-grid specified by the axes [a_0,a_1,…,a_K] and [b_0,b_1,…,b_L], the point of coordinates (i,j) has value (a_i, b_j)

__init__(axes: list[numpy.array])[source]
number_of_points()[source]

Total number of points in the grid

class Uniform1DGrid(start: float, end: float, num: int)[source]

Bases: object

Build a one-dimensional uniform axis

Parameters
  • start – start element of the axes

  • end – end element of the axes (included)

  • num – (strictly positive) number of points between start and end

__init__(start: float, end: float, num: int)[source]
property num

spatial

Spatial Grid definitions.

In this module we define several types of spatial grids to be applied to the simulation of the CTMC scheme via Monte-Carlo.

class SpatialGrid(axes: list[numpy.array])[source]

Bases: Grid

Spatial Grid definition

Note

this object expects the axis to be arrays with increasing elements and this check is not carried out for performance reason.

__init__(axes: list[numpy.array])[source]
class CTMCGrid(h: float, origin_coordinate: int, axes: list[numpy.array])[source]

Bases: SpatialGrid

Grid object for the simulation of the CTMC (Continuous-Time Markov Chain) via Monte-Carlo

__init__(h: float, origin_coordinate: int, axes: list[numpy.array])[source]

Build the CTMC grid: :param h: the hyper-cube of size h centered in the origin of the grid is taken off the spatial grid :param origin_coordinate: coordinate of the grid origin :param axes: list of axes

outside(coordinate) bool[source]
outside(coordinate: Coordinate1D) bool
outside(coordinate: int) bool

Test if the coordinate is outside the limits of the grid

left_point(coordinate) float[source]
left_point(coordinate: Coordinate1D) float
left_point(coordinate: CoordinateND) tuple[float]
Returns

the point of the left side of x where x = axes[0][position] (single axis grid) if x is itself the first point of the axes, return x

right_point(coordinate) float[source]
right_point(coordinate: Coordinate1D) float
right_point(coordinate: CoordinateND) tuple[float]
Returns

the point of the right side of x where x = axes[0][position] (single axis grid) if x is itself the last point of the axes, return x

middle(xi: tuple[float], xip: tuple[float]) tuple[float][source]
middle(xi: float, xip: float) float
Returns

the middle-point of \([x_i, x_{i+1}]\) that is the point which coordinates are equal to the average of the coordinates of \(x_i\) and \(x_{i+1}\)

refine() None[source]

refine the axes, i.e. add all the ‘middle’ point for each interval \([x_i, x_{i+1}]\) of the axes

plot()[source]
class CTMCUniformGrid(h, model: Union[LevyModel, LevyCopulaModel], truncation_probability=0.99999)[source]

Bases: CTMCGrid

Uniform grid for the CTMC, each axis has uniform spatial step of size h.

__init__(h, model: Union[LevyModel, LevyCopulaModel], truncation_probability=0.99999)[source]

Building the uniform grid for the CTMC. Each axis is uniform with spatial step h. The bounds of the grid are calculated via the model and the truncation probability, namely each (left/right) axis bound is chosen such that the ratio of the remaining and the total mass is less than the truncation probability.

Parameters
  • h – uniform spatial step of the grid

  • model – Lévy model in scope

  • truncation_probability – used to define the bounds of the grid

classmethod create_from_fixed_nb_of_points(h: float, nb_of_points: int, dimension: int = 1)[source]

This constructor allows the user to define directly the number of points of the grid which also defines the boundaries of the grid.

Parameters
  • h – uniform spatial step h

  • nb_of_points – number of points for each axis

  • dimension – grid dimension

class CTMCGridProbabilityStep(h: float, model: LevyModel, minimum_probability_step: float = 0.05, dimension: int = 1)[source]

Bases: CTMCGrid

CTMC Grid where each spatial step is defined by its corresponding jump probability.

__init__(h: float, model: LevyModel, minimum_probability_step: float = 0.05, dimension: int = 1)[source]

Building the CTMC grid with probability steps :param h: spatial step h :param model: Lévy model in scope needed to compute the jump probability :param minimum_probability_step: :param dimension: grid dimension

middle(xi: float, xip: float) float[source]

In that case, the middle point is defined in terms of probability, that the middle point is such that there is equal probability to jump to the left/right point.

Parameters
  • xi – left point

  • xip – right point

class CTMCGridGeometric(h: float, model: Union[LevyModel, LevyCopulaModel, LevyDrivenSDEModel], nb_of_points_on_each_side: int = 2, truncation_probability: float = 0.99999)[source]

Bases: CTMCGrid

CTMC grid where the spatial step is geometric starting from the origin of the grid.

__init__(h: float, model: Union[LevyModel, LevyCopulaModel, LevyDrivenSDEModel], nb_of_points_on_each_side: int = 2, truncation_probability: float = 0.99999)[source]

Build the geometric grid for the CTMC. Considering only the right axis of a unidimensional grid, one gets: [0, h, alpha*h, alpha^2*h,…] where the last element is defined by the truncation probability and alpha is implied from this last quantity and the number of points.

Parameters
  • h – spatial step

  • model – Lévy model, needed along the truncation probability to compute the boundaries

  • nb_of_points_on_each_side – number of point for each left/right semi-axis

  • truncation_probability – truncation probability

classmethod create_with_bounds(h: float, truncations: tuple[float, float], dimension: int, nb_of_points_on_each_side: int = 2)[source]

This constructor allows the user to pass the truncations (boundaries of the grid) directly

Parameters
  • h – spatial step

  • truncations – truncation parameters

  • dimension – grid dimension

  • nb_of_points_on_each_side – number of points for each (left/right) semi-axis

class CTMCCredit(h: float, level_a: Union[float, list[float]], model: Union[LevyModel, LevyCopulaModel], symmetric_grid: bool = True)[source]

Bases: CTMCGrid

In the case of the Garreau-Kercheval Credit Model (see “A Structural Jump Threshold Framework for Credit Risk” by Garreau and Kercheval), one only require to know whether the underlying is above a threshold, hence the CTMC can be greatly simplified to only account for negative big jumps.

__init__(h: float, level_a: Union[float, list[float]], model: Union[LevyModel, LevyCopulaModel], symmetric_grid: bool = True)[source]

Build the CTMC grid: :param h: the hyper-cube of size h centered in the origin of the grid is taken off the spatial grid :param origin_coordinate: coordinate of the grid origin :param axes: list of axes

compute_truncation(model: Union[LevyModel, LevyCopulaModel, LevyDrivenSDEModel], h: float, truncation_probability: float = 0.99999)[source]

Compute truncations of the grid given the truncation probability and the model in scope.

Parameters
  • model – Lévy model

  • h – spatial step h

  • truncation_probability – truncation probability

compute_truncation_helper(levy_measure: LevyMeasure, h: float, probability: float) tuple[float, float][source]

Helper function: compute the truncations for a specific axis.

Parameters
  • levy_measure – levy measure of the model in scope

  • h – spatial step h

  • probability – truncation probability

compute_right_axis(h: float, levy_measure: LevyMeasure, minimum_probability_step: float)[source]
compute_left_axis(h: float, levy_measure: LevyMeasure, minimum_probability_step: float)[source]

time

Time grid definition, simply a one-dimensional grid, that is a simple axis, with increasing elements.

class TimeGrid(start: float, end: float, num: int = 2)[source]

Bases: Uniform1DGrid

Build a uniform time axis

__init__(start: float, end: float, num: int = 2)[source]
Parameters
  • start – start time

  • end – end time

  • num – number of discretisation points, 2 by default (the start and end points)