statistic

statistic

Store the simulations of an estimator (underlying, payoff) and add tools to describe its statistics: moments, density, etc.

class NoStatistic[source]

Bases: object

NoStatistic object: statistics for this variable are not needed

__init__()[source]
add(simulation: int, variable: array) None[source]
extend(mc_path) None[source]
plot_density()[source]
class Density(label: str, process_representation: ProcessRepresentation)[source]

Bases: object

Define and plot the density function of a stochastic underlying modelled by a Lévy model

__init__(label: str, process_representation: ProcessRepresentation)[source]
Parameters
  • label – label of the density plot

  • process_representation – how the process is represented by the model (identity or log)

set_density(density)[source]
class Statistic(label: str, shape: tuple, mc_paths: int, process_representation: ProcessRepresentation)[source]

Bases: object

Statistics object to manage the simulated variables and handle requests such as plotting their density

__init__(label: str, shape: tuple, mc_paths: int, process_representation: ProcessRepresentation)[source]
Parameters
  • label – label of the simulated variables

  • shape – shape of the input data

  • mc_paths – number of simulations in the Monte-Carlo engine

plot_density()[source]
add(simulation: int, variable: array) None[source]
extend(mc_path) None[source]

Extend the data to support extra number of Monte-Carlo paths :param mc_path: extra number of paths

class MCStatistics(*, payoff_statistics: ~rpylib.montecarlo.statistic.statistic.Statistic, spot_underlying_statistics: ~rpylib.montecarlo.statistic.statistic.Statistic =, control_variates_statistics: ~rpylib.montecarlo.statistic.statistic.Statistic =)[source]

Bases: object

Statistics object when used with a standard Monte-Carlo engine

__init__(*, payoff_statistics: ~rpylib.montecarlo.statistic.statistic.Statistic, spot_underlying_statistics: ~rpylib.montecarlo.statistic.statistic.Statistic =, control_variates_statistics: ~rpylib.montecarlo.statistic.statistic.Statistic =)[source]
Parameters
  • payoff_statistics – statistics object handling the simulations of the payoff

  • spot_underlying_statistics – statistics object handling the simulations of the spot underlying

  • control_variates_statistics – statistics object handling the simulations of the control variates

add(simulation: int, path_manager: MCPath) None[source]
extend(mc_path) None[source]
plot_spot_density()[source]
plot_payoff_density()[source]
price(no_control_variates: bool = False) array[source]
mc_stddev(no_control_variates: bool = False) array[source]
get_mean(no_control_variates: bool = False) array[source]
get_variance(no_control_variates: bool = False) array[source]
class MLMCResults(Nl: array, sum_cost: array, all_pl_fine: list, all_pl_coarse: list)[source]

Bases: object

Handle the output of the Multilevel Monte-Carlo

__init__(Nl: array, sum_cost: array, all_pl_fine: list, all_pl_coarse: list)[source]
Parameters
  • Nl – number of Monte-Carlo paths for each level l

  • sum_cost – array of the cost for each level l

  • all_pl_fine – correction terms for the fine payoff for each level l

  • all_pl_coarse – correction terms for the coarse payoff for each level l

property mean_level_l
property var_level_l
property kurtosis
property ml

Mean of the correction terms \(|P_l - P_{l-1}|\) for the level l

property vl

Variance of the correction terms \(|P_l - P_{l-1}|\) for the level l

property cl

Algorithm cost associated to the level l

property cost

total cost of the Multilevel Monte-Carlo algorithm

property consistency_check
class PT(value)[source]

Bases: IntEnum

An enumeration.

FP = 0
CP = 1
class MLMCStatistics(mc_statistics: list[rpylib.montecarlo.statistic.statistic.MCStatistics], create_statistic)[source]

Bases: object

Statistics object when used with a Multilevel Monte-Carlo engine

__init__(mc_statistics: list[rpylib.montecarlo.statistic.statistic.MCStatistics], create_statistic)[source]
Parameters
  • mc_statistics – list of the statistics object for each level l

  • create_statistic – helper function to create individual statistics

add(simulation: int, level: int, path_manager: MCPath) None[source]
set_mlmc_results(Nl: array, sum_cost: array)[source]
add_mc_statistic()[source]
extend(mc_paths)[source]
plot_spot_density(level: Optional[int] = None)[source]
price(no_control_variates: bool = False) float[source]
mc_stddev(no_control_variates: bool = False) float[source]
simulation_payoff_with_fine_process(level, start: Optional[int] = None, end: Optional[int] = None, no_control_variates: bool = False) array[source]
simulation_payoff_with_coarse_process(level, start: Optional[int] = None, end: Optional[int] = None, no_control_variates: bool = False) array[source]
create_mc_statistics(mc_paths: int, underlying_density: [collections.abc.Callable[[float], float]], control_variates: ControlVariates, payoff_dimension: int, process_representation: ProcessRepresentation, activate_spot_statistics: bool, spot_dimension: int) MCStatistics[source]

Factory method which returns the MCStatistics object

Parameters
  • mc_paths – number of Monte-Carlo paths

  • underlying_density – theoretical underlying density

  • control_variates – control variates object

  • payoff_dimension – dimension of the payoff (that is the number of underlyings passed to the payoff function)

  • process_representation – process representation in the model

  • activate_spot_statistics – if True, compute and save the simulated values of the modelled underlying process

  • spot_dimension – dimension of the modelled underlying process

create_mlmc_statistics(mc_paths: int, underlying_density: [collections.abc.Callable[[float], float]], initial_level: int, control_variates: ControlVariates, payoff_dimension: int, process_representation: ProcessRepresentation) MLMCStatistics[source]

Factory method which returns the MLMCStatistics object

Parameters
  • mc_paths – number of Monte-Carlo paths

  • underlying_density – theoretical underlying density

  • initial_level – initial number of levels

  • control_variates – control variates object

  • payoff_dimension – dimension of the payoff (that is the number of underlyings passed to the payoff function)

  • process_representation – process representation in the model

tools

Useful tool for computing statistics

mean(simulations: array) array[source]
stddev(simulations: array) array[source]
mc_stddev(simulations: array) array[source]
skewness(simulations: array) array[source]
kurtosis(simulations: array) array[source]
class NonCenteredMoments(simulations: list[numpy.array])[source]

Bases: object

Computation of the moments E[X^k] of X

__init__(simulations: list[numpy.array])[source]
Parameters

simulations – list of ndarray, each element corresponds to the simulations of the level l of

the Multilevel Monte-Carlo (only one element for a standard Monte-Carlo engine)

property ncm_first
Returns

first non-centered moment, ie E[X]

property ncm_second
Returns

second non-centered moment, ie E[X^2]

property ncm_third
Returns

third non-centered moment, ie E[X^3]

property ncm_fourth
Returns

fourth non-centered moment, ie E[X^4]