markovchain

markovchain

One-dimensional CTMC implementation

vol_adjustment(model: LevyModel, h: float)[source]

For processes with infinite variation, the small jumps of size less than h are approximated by a Brownian motion. This function computes the corresponding coefficient.

Parameters
  • model – Lévy model

  • h – spatial step h

compute_mu_h(levy_measure, grid: CTMCGrid, axis: array, origin: int) float[source]

Computation of the drift mu_h of the CTMC

Parameters
  • levy_measure – Lévy measure of the process

  • grid – states grid

  • axis – axis

  • origin – origin coordinate

Returns

the drift mu_h

class MarkovChain(times: array, values: list[numpy.array], states_increments: list[numpy.array])[source]

Bases: object

Markov Chain object storing the simulation times, its values and state increments.

__init__(times: array, values: list[numpy.array], states_increments: list[numpy.array])[source]
Parameters
  • times – simulation times

  • values – Markov chain values

  • states_increments – Markov chain increments

times
values
states_increments
class MarkovChainProcess(model: LevyModel, method: SamplingMethod, grid: CTMCGrid)[source]

Bases: LevyProcess

Description of a Markov-Chain process approximating a Lévy model over spatial states axes

Parameters
  • model – Lévy model

  • grid – states grid

  • method – sampling method to simulate the discrete states

__init__(model: LevyModel, method: SamplingMethod, grid: CTMCGrid)[source]
process_drift() array[source]

Drift of the simulated process

intensity() float[source]

Intensity of the jump process

one_simulation_cost(product) float[source]
Parameters

product – product to price

Returns

the cost of simulating one Monte-Carlo path

reset_one_simulation_cost() None[source]

Set simulation cost to 0

initialisation(product: Product, max_step_epsilon: Optional[float] = None) None[source]

Initialisation of auxiliary objects

class MCSimulation[source]

Bases: object

Method to simulation the Markov Chain via Monte-Carlo

simulate_markov_chain() MarkovChain[source]
simulate_jumps()[source]
static helper_simulate_markov_chain(grid, sampling, all_nb_of_jumps) tuple[list[numpy.array], list[numpy.array]][source]

simulate one path of the non-deterministic part of the underlying

Parameters
  • grid – states grid

  • sampling – sampling method

  • all_nb_of_jumps – number of jumps for each time interval

class MCSimulationFixedTimes(process: MarkovChainProcess)[source]

Bases: MCSimulation, SimulationFixedTimes

Simulation of the Markov Chain at (pre-defined) fixed times

__init__(process: MarkovChainProcess)[source]
simulate_markov_chain() MarkovChain[source]

simulate one path of the non-deterministic part of the underlying

static project(values)[source]
simulate_jumps()[source]

Simulation of the jump component

simulate_diffusion(sqrt_dts)[source]

Simulation of the diffusive component

class MCSimulationWithJumpTimes(process: MarkovChainProcess)[source]

Bases: MCSimulation, SimulationWithJumpTimes

Simulation of the Markov Chain at stochastic jump times

__init__(process: MarkovChainProcess)[source]
simulate_markov_chain() MarkovChain[source]

simulate one path of the non-deterministic part of the underlying

simulate_jumps()[source]

Simulation of the jump component

simulate_diffusion(sqrt_dts)[source]

Simulation of the diffusive component

class MCSimulationMaximumStep(process: MarkovChainProcess, epsilon: float)[source]

Bases: MCSimulationWithJumpTimes, SimulationMaximumStep

Simulation of the Markov Chain at stochastic jump times with maximum time step of size epsilon

__init__(process: MarkovChainProcess, epsilon: float)[source]
simulate_jumps()[source]

Simulation of the jump component

markovchainlevycopula

Lévy copula simulated through a Markov Chain process

vol_adjustment_ij(i: int, j: int, h: float, levy_model: LevyCopulaModel)[source]

For processes with infinite variation, the small jumps of size less than h are approximated by a Brownian motion. This function computes the corresponding diffusion matrix.

Parameters
  • i – i-th coordinate

  • j – j-th coordinate

  • levy_model – Lévy copula model

  • h – spatial step h .. seealso:: function vol_adjustment()

class MarkovChainLevyCopula(levy_copula_model: LevyCopulaModel, grid: CTMCGrid, method: SamplingMethod)[source]

Bases: LevyProcess

Lévy copula simulated via a Markov Chain process

__init__(levy_copula_model: LevyCopulaModel, grid: CTMCGrid, method: SamplingMethod)[source]
Parameters
  • levy_copula_model – Lévy copula model

  • grid – states grid

  • method – sampling method

process_drift() array[source]

Drift of the simulated process

intensity() float[source]

Intensity of the jump process

one_simulation_cost(product) float[source]
Parameters

product – product to price

Returns

the cost of simulating one Monte-Carlo path

reset_one_simulation_cost() None[source]

Set simulation cost to 0

initialisation(product: Product, max_step_epsilon: Optional[float] = None) None[source]

Initialisation of auxiliary objects

class MCLevyCopulaSimulation(process: MarkovChainLevyCopula)[source]

Bases: object

Simulation method of Markov Chain process for Lévy copulas

__init__(process: MarkovChainLevyCopula)[source]
simulate_markov_chain() MarkovChain[source]
simulate_jumps()[source]
helper_simulate_levy_copula_markov_chain(all_nb_of_jumps) tuple[list[numpy.array], list[numpy.array]][source]

simulate one path of the non-deterministic part of the underlying

helper_simulate_diffusion_part(sqrt_time_increments, brownian_increments)[source]
class MCLevyCopulaSimulationFixedTimes(process: MarkovChainLevyCopula)[source]

Bases: MCLevyCopulaSimulation, SimulationFixedTimes

Simulation of a Markov Chain for Lévy copula at (pre-defined) fixed times

__init__(process: MarkovChainLevyCopula)[source]
simulate_one_path() StochasticPath[source]

Simulation of the path for deterministic payoff dates

simulate_markov_chain() MarkovChain[source]

simulate one path of the non-deterministic part of the underlying

static project(values, dim)[source]
simulate_jumps()[source]

Simulation of the jump component

simulate_diffusion_part()[source]
class MCLevyCopulaSimulationWithJumpTimes(process: MarkovChainLevyCopula)[source]

Bases: MCLevyCopulaSimulation, SimulationWithJumpTimes

Simulation of a Markov Chain for Lévy copula at the stochastic jump times

__init__(process: MarkovChainLevyCopula)[source]
simulate_one_path() StochasticPath[source]

Simulation of the path for stochastic payoff dates

simulate_markov_chain() MarkovChain[source]

simulate one path of the non-deterministic part of the underlying

simulate_jumps()[source]

Simulation of the jump component

simulate_diffusion_part(sqrt_time_increments)[source]
class MCLevyCopulaSimulationMaximumStep(process: MarkovChainLevyCopula, epsilon: float)[source]

Bases: MCLevyCopulaSimulationWithJumpTimes, SimulationMaximumStep

Simulation of a Markov Chain for Lévy copula at the stochastic jump times with maximum time increment of size epsilon

__init__(process: MarkovChainLevyCopula, epsilon: float)[source]
Parameters
  • process – Lévy process

  • epsilon – minimum time increment

simulate_jumps()[source]

Simulation of the jump component

markovchainsde

Lévy-driven SDE process

class MarkovChainSDE(model: LevyDrivenSDEModel, method: SamplingMethod, grid: CTMCGrid)[source]

Bases: Process

Markov Chain for a process defined by a Lévy-driven SDE

__init__(model: LevyDrivenSDEModel, method: SamplingMethod, grid: CTMCGrid)[source]
Parameters
  • model – Lévy-driven SDE model

  • method – sampling method of the Markov Chain

  • grid – states grid

initialisation(product: Product, _: Optional[float] = None) None[source]

Initialisation of the process from the characteristics of the product in scope

Parameters
  • product – financial product

  • max_step_epsilon – if epsilon != None then jump times with max step epsilon are used to build the time discretisation steps

one_simulation_cost(product) float[source]

Returns: the simulating cost corresponding to the numbers of uniform random variables simulated

reset_one_simulation_cost() None[source]

Reset the simulation cost

pre_computation(mc_paths: int, product: Product) None[source]

Pre-computation, for example simulate the random variables if possible :param mc_paths: number of Monte-Carlo paths :param product: financial product to price

process_drift() array[source]

Drift of the simulated process

sde_drift(t: float, x: array)[source]
deterministic_path(times: array) array[source]
Parameters

times – times of the path

Returns

the deterministic part of the path

simulate_one_path() StochasticPath[source]

Simulate (only) one path of the non-deterministic part of the underlying

class MarkovChainLevyLiborModel(model: LevyLiborModel, method: SamplingMethod, grid: CTMCGrid)[source]

Bases: MarkovChainSDE

Markov Chain for the Lévy Libor Model and the Forward Market Model

__init__(model: LevyLiborModel, method: SamplingMethod, grid: CTMCGrid)[source]
Parameters
  • model – Lévy-driven SDE model

  • method – sampling method of the Markov Chain

  • grid – states grid

initialisation(product: Product, _: Optional[float] = None) None[source]

Initialisation of the process from the characteristics of the product in scope

Parameters
  • product – financial product

  • max_step_epsilon – if epsilon != None then jump times with max step epsilon are used to build the time discretisation steps

sde_drift(t: float, x: array)[source]
compute_drift_term(t: float, omegas)[source]
Parameters
  • t – time

  • omegas\(\omega^i = L_t^i*\delta^i/(1 + L_t^i*\delta^i)\)

Returns

the drift term at order 1