montecarlo

configuration

Configuration object for the Monte-Carlo engine.

Example
  • the number of paths

  • the seed for the random generator

  • the use of variance reduction

  • the number of processes to use in parallel (if using the multiprocessing implementation)

  • etc.

class VarianceReduction(value)[source]

Bases: Enum

Variance reduction methods

RICHARDSONEXTRAPOLATION = 1
ANTITHETIC = 2
class Engine(value)[source]

Bases: Enum

Monte-Carlo engine type

STANDARD = 1
MULTILEVEL = 2
class VarianceReductionMethod[source]

Bases: object

Class wrapper for the variance reduction methods

__init__()[source]
add(method: VarianceReduction)[source]

add variance method

has(method: VarianceReduction) bool[source]

check if method is present

class Configuration(variance_reduction: VarianceReductionMethod, seed: Optional[int] = None, control_variates: Optional[ControlVariates] = None, activate_spot_statistics: bool = False, nb_of_processes: Optional[int] = None)[source]

Bases: object

Monte-Carlo engine global configuration

__init__(variance_reduction: VarianceReductionMethod, seed: Optional[int] = None, control_variates: Optional[ControlVariates] = None, activate_spot_statistics: bool = False, nb_of_processes: Optional[int] = None)[source]
Parameters
  • variance_reduction – list of variance reduction methods to use

  • seed – seed for the random generator

  • control_variates – control variates

  • activate_spot_statistics – if true then compute the statistics of the modelled underlying spot

  • nb_of_processes

    number of processes used for the parallel processing implementation

    Note

    if using the multiprocessing implementation, the seed for each process will be chosen randomly as one can’t have the same seed for each proces.

initialisation_seed(multiprocessing: bool = False)[source]

Random seed initialisation

Note

if multiprocessing is used, the seed for each process is set randomly as otherwise all the processes would have the same seed

initialisation(product: Product) None[source]
class ConfigurationStandard(mc_paths: int = 1000, variance_reduction: Optional[VarianceReductionMethod] = None, seed: Optional[int] = None, control_variates: Optional[ControlVariates] = None, activate_spot_statistics: bool = False, nb_of_processes: Optional[int] = None)[source]

Bases: Configuration

Configuration for the standard Monte-Carlo engine

__init__(mc_paths: int = 1000, variance_reduction: Optional[VarianceReductionMethod] = None, seed: Optional[int] = None, control_variates: Optional[ControlVariates] = None, activate_spot_statistics: bool = False, nb_of_processes: Optional[int] = None)[source]
Parameters
  • mc_paths – number of Monte-Carlo paths

  • variance_reduction – variance reduction methods

  • seed – seed of the random generator

  • control_variates – control variates

  • activate_spot_statistics – if true, compute the modelled underlying spot

  • nb_of_processes – number of processes for parallel computing

class ConvergenceRates(alpha: Optional[float] = None, beta: Optional[float] = None, gamma: Optional[float] = None)[source]

Bases: object

Definition of the convergence rates (strong, weak and cost) in the MLMC case

__init__(alpha: Optional[float] = None, beta: Optional[float] = None, gamma: Optional[float] = None)[source]
Parameters
  • alpha – weak convergence rate

  • beta – strong convergence rate

  • gamma – cost convergence rate .. note:: the convergence rate are in base 2 in the level l, that is in 2**(alpha*l)

compute_convergence_rates(bg_index: float) ConvergenceRates[source]
Parameters

bg_index – Blumenthal-Getoor index

Returns

convergence rates alpha (weak convergence), beta (strong convergence) and gamma (cost)

class ConfigurationMultiLevel(variance_reduction: ~typing.Optional[~rpylib.montecarlo.configuration.VarianceReductionMethod] = None, convergence_rates: ~rpylib.montecarlo.configuration.ConvergenceRates = <rpylib.montecarlo.configuration.ConvergenceRates object>, convergence_criteria: ~typing.Optional[~rpylib.montecarlo.multilevel.criteria.ConvergenceCriteria] = None, initial_level: int = 2, maximum_level: int = 50, initial_mc_paths: int = 100, seed: ~typing.Optional[int] = None, control_variates: ~typing.Optional[~rpylib.product.product.ControlVariates] = None, activate_spot_statistics: bool = False, nb_of_processes: ~typing.Optional[int] = None)[source]

Bases: Configuration

Configuration for the Multilevel Monte-Carlo engine

__init__(variance_reduction: ~typing.Optional[~rpylib.montecarlo.configuration.VarianceReductionMethod] = None, convergence_rates: ~rpylib.montecarlo.configuration.ConvergenceRates = <rpylib.montecarlo.configuration.ConvergenceRates object>, convergence_criteria: ~typing.Optional[~rpylib.montecarlo.multilevel.criteria.ConvergenceCriteria] = None, initial_level: int = 2, maximum_level: int = 50, initial_mc_paths: int = 100, seed: ~typing.Optional[int] = None, control_variates: ~typing.Optional[~rpylib.product.product.ControlVariates] = None, activate_spot_statistics: bool = False, nb_of_processes: ~typing.Optional[int] = None)[source]
Parameters
  • variance_reduction – variance reduction methods

  • convergence_rates – convergence rates (weak, strong and cost)

  • convergence_criteria – convergence criteria of the MLMC algorithm

  • initial_level – initial level L0

  • maximum_level – maximum level L

  • initial_mc_paths – initial number of paths (for any level)

  • seed – seed of the random generator

  • control_variates – control variates

  • activate_spot_statistics – if true, compute the modelled spot underlying

  • nb_of_processes – number of processes for the multiprocessing implementation

path

Description of a simulated Monte-Carlo path

create_path(configuration: Configuration, deterministic_path: Callable[[array], ndarray[Any, dtype[ScalarType]]])[source]
Parameters
  • configuration – Monte-Carlo configuration

  • deterministic_path – values of the deterministic underlying

Returns

the path manager

class StochasticPath[source]

Bases: object

General Stochastic path

value() array[source]

Value of the path at each simulation time

times() array[source]

Simulation times

antithetic_value() array[source]

ANTITHETIC values of the path

class StochasticJumpPath(jump_times: array, diffusion_path: array, jump_path: array)[source]

Bases: StochasticPath

Stochastic path with a jump component

__init__(jump_times: array, diffusion_path: array, jump_path: array)[source]
Parameters
  • jump_times – jump times

  • diffusion_path – pure diffusive component

  • jump_path – pure jump component

jump_times
diffusion_path
jump_path
value() array[source]

Value of the path at each simulation time

value_jump() array[source]

Only the jump path

times() array[source]

Simulation times

antithetic_value() array[source]

ANTITHETIC values of the path

class StochasticSDEPath(drift: array, jump_times: array, diffusion_path: array, jump_path: array)[source]

Bases: StochasticJumpPath

Stochastic path for a process defined by a SDE

__init__(drift: array, jump_times: array, diffusion_path: array, jump_path: array)[source]
Parameters
  • drift – SDE drift values

  • jump_times – jump times

  • diffusion_path – pure diffusive component

  • jump_path – pure jump component

drift
value() array[source]

Value of the path at each simulation time

antithetic_value() array[source]

ANTITHETIC values of the path

class MCPath(deterministic_path: Callable[[array], array], activate_spot_underlying: bool)[source]

Bases: ABC

MCPath handles the different ways of storing a (possibly multidimensional) Monte-Carlo path, and it is also responsible for computing the underlying and the final payoff values.

__init__(deterministic_path: Callable[[array], array], activate_spot_underlying: bool)[source]
Parameters
  • deterministic_path – function that gives the deterministic value of the process

  • activate_spot_underlying – if True then compute the modelled underlying too

update(process_representation: ProcessRepresentation)[source]

Update the evaluation function with regard to the process representation

process_spot(path)[source]

Process the spot underlying if spot statistics are required

set_to_path(stochastic_path) None[source]

Set computed path

process(product: Product, control_variates: ControlVariates) None[source]

Compute the payoff value from the simulated path

discount(df: float)[source]

Discount the payoff with df :param df: discount

class MLMCPath(deterministic_path: Callable[[array], array], activate_spot_underlying: bool)[source]

Bases: MCPath

Handling of the path for the Multilevel Monte-Carlo

__init__(deterministic_path: Callable[[array], array], activate_spot_underlying: bool)[source]
Parameters
  • deterministic_path – function that gives the deterministic value of the process

  • activate_spot_underlying – if True then compute the modelled underlying too

process_spot_level_l(path_fine, path_coarse) None[source]

Processing the spot underlying for both the fine and coarse paths

Parameters
  • path_fine – path of the fine process

  • path_coarse – path of the coarse process

process(product: Product, control_variates: ControlVariates) None[source]

Processing the payoff for both the fine and coarse paths

Parameters
  • product – product to price

  • control_variates – control variates

process_l0(product: Product, control_variates: ControlVariates) None[source]

Processing the payoff for the first level (=0) that is when there is no coarse process

Parameters
  • product – product to price

  • control_variates – control variates