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:
EnumVariance reduction methods
- RICHARDSONEXTRAPOLATION = 1
- ANTITHETIC = 2
- class VarianceReductionMethod[source]
Bases:
objectClass wrapper for the variance reduction methods
- 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:
objectMonte-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.
- 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:
ConfigurationConfiguration 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:
objectDefinition of the convergence rates (strong, weak and cost) in the MLMC case
- 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:
ConfigurationConfiguration 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 StochasticJumpPath(jump_times: array, diffusion_path: array, jump_path: array)[source]
Bases:
StochasticPathStochastic 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
- class StochasticSDEPath(drift: array, jump_times: array, diffusion_path: array, jump_path: array)[source]
Bases:
StochasticJumpPathStochastic 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
- class MCPath(deterministic_path: Callable[[array], array], activate_spot_underlying: bool)[source]
Bases:
ABCMCPath 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(product: Product, control_variates: ControlVariates) None[source]
Compute the payoff value from the simulated path
- class MLMCPath(deterministic_path: Callable[[array], array], activate_spot_underlying: bool)[source]
Bases:
MCPathHandling 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