API reference guide

Contents

API reference guide#

This page documents the GEMAct API exposed by the main modelling modules. The class entries below intentionally avoid properties and private implementation classes so that the rendered API focuses on constructors, parameters, and documented methods.

LossModel#

Risk costing#

GEMAct costing model is based on the collective risk theory. The aggregate loss \(X\), also referred to as aggregate claim cost, is

(1)#\[X = \sum_{i=1}^{N} Z_i,\]

where the following assumptions hold:

  • \(N\) is a random variable taking values in \(\mathbb{N}_0\) representing the claim frequency.

  • \(\left\{ Z_i\right\}_{i \in \mathbb{N}}\) is a sequence of i.i.d. non-negative random variables independent of \(N\); \(Z\) is the random variable representing the individual claim loss.

Equation (1) is often referred to as the frequency-severity loss model representation. This can encompass common coverage modifiers present in (re)insurance contracts. More specifically, we consider:

  • For \(a \in [0, 1]\), the function \(Q_a\) apportioning the aggregate loss amount:

    \[Q_a (X)= a X.\]
  • For \(c,d \geq 0\), the function \(L_{c, d}\) applied to the individual claim loss:

    (2)#\[L_{c, d} (Z_i) = \min \left\{\max \left\{0, Z_i-d\right\}, c\right\}.\]

    Herein, for each and every loss, the excess to a deductible \(d\), sometimes referred to as priority, is considered up to a cover or limit \(c\). Similarly to the individual loss \(Z_i\), Formula (2) can be applied to the aggregate loss \(X\).

The expected value of the aggregate loss constitutes the building block of an insurance tariff. Listed below are some examples of basic reinsurance contracts whose pure premium can be computed with GEMAct.

  • The Quota Share (QS), where a share \(a\) of the aggregate loss is ceded to the reinsurer together with the respective premium, and the remaining part is retained:

    \[\text{P}^{QS} = \mathbb{E}\left[ Q_a \left( X \right)\right].\]
  • The Excess-of-loss (XL), where the insurer cedes to the reinsurer each and every loss exceeding a deductible \(d\), up to an agreed limit or cover \(c\), with \(c,d \geq 0\):

    \[\text{P}^{XL} = \mathbb{E}\left[ \sum_{i=1}^{N} L_{c,d} (Z_i) \right].\]
  • The Stop Loss (SL), where the reinsurer covers the aggregate loss exceedance of an aggregate deductible \(v\), up to an aggregate limit or cover \(u\), with \(u,v \geq 0\):

    \[\text{P}^{SL} = \mathbb{E}\left[ L_{u, v} (X) \right].\]
  • The Excess-of-loss with reinstatements (RS) (Sundt [Sun91]). Assuming the aggregate cover \(u\) is equal to \((K + 1)c\), with \(K \in \mathbb{Z}^+\):

    (3)#\[\text{P}^{RS} = \frac{\mathbb{E}\left[ L_{u, v} (X) \right]}{1+\frac{1}{c} \sum_{k=1}^K l_k \mathbb{E}\left[ L_{c, (k-1)c+v}(X) \right]}.\]

    Where \(K\) is the number of reinstatement layers and \(l_k \in [0, 1]\) is the reinstatement premium percentage, with \(k=1, \ldots, K\). When \(l_k = 0\), the \(k\)-th reinstatement is said to be free.

The following table gives the correspondence between the LossModel class attributes and the costing model above.

Costing model notation

Parametrization in LossModel

\(d\)

deductible

\(c\)

cover

\(v\)

aggr_deductible

\(u\)

aggr_cover

\(K\)

n_reinst

\(l_k\)

reinst_percentage

\(\alpha\)

share

For additional information the reader can refer to Klugman and Panjer [KP19], Sundt [Sun91]. Further details on the computational methods to approximate the aggregate loss distribution can be found in Klugman and Panjer [KP19] and Embrechts and Frei [EF08].

Example#

Below is an example of costing an XL contract with reinstatements:

from gemact.lossmodel import Frequency, Severity, PolicyStructure, Layer, LossModel

lossmodel_RS = LossModel(
    frequency=Frequency(
        dist='poisson',
        par={'mu': 1.5}
    ),
    severity=Severity(
        par={'loc': 0, 'scale': 83.34, 'c': 0.834},
        dist='genpareto'
    ),
    policystructure=PolicyStructure(
        layers=Layer(
            cover=100,
            deductible=0,
            aggr_deductible=100,
            reinst_percentage=0.5,
            n_reinst=2
        )
    ),
    aggr_loss_dist_method='fft',
    sev_discr_method='massdispersal',
    n_aggr_dist_nodes=int(100000)
)
lossmodel_RS.print_costing_specs()

Severity discretization#

When passing from a continuous distribution to an arithmetic distribution, it is important to preserve the distribution properties, either locally or globally. Given a bandwidth, or discretization step, \(h\) and a number of nodes \(M\), in Klugman and Panjer [KP19] the method of mass dispersal and the method of local moments matching work as follows.

Method of mass dispersal

(4)#\[f_{0}=\operatorname{Pr}\left(Y<\frac{h}{2}\right)=F_{Y}\left(\frac{h}{2}-0\right)\]
(5)#\[f_{j}=F_{Y}\left(j h+\frac{h}{2}-0\right)-F_{Y}\left(j h-\frac{h}{2}-0\right), \quad j=1,2, \ldots, M-1\]
(6)#\[f_{M}=1-F_{X}[(M-0.5) h-0]\]

Method of local moments matching

The following approach is applied to preserve the global mean of the distribution.

(7)#\[f_0 = m^0_0\]
(8)#\[f_j = m^{j}_0+ m^{j-1}_1, \quad j=0,1, \ldots, M\]
(9)#\[\sum_{j=0}^{1}\left(x_{k}+j h\right)^{r} m_{j}^{k}=\int_{x_{k}-0}^{x_{k}+ h-0} x^{r} d F_{X}(x), \quad r=0,1\]
(10)#\[m_{j}^{k}=\int_{x_{k}-0}^{x_{k}+p h-0} \prod_{i \neq j} \frac{x-x_{k}-i h}{(j-i) h} d F_{X}(x), \quad j=0,1\]

In addition to these two methods, GEMAct also provides upper and lower discretizations.

Example#

An example of code to implement severity discretization is given below:

from gemact.lossmodel import Severity
import numpy as np

severity = Severity(
    par={'loc': 0, 'scale': 83.34, 'c': 0.834},
    dist='genpareto'
)

massdispersal = severity.discretize(
    discr_method='massdispersal',
    n_discr_nodes=50000,
    discr_step=.01,
    deductible=0
)

localmoments = severity.discretize(
    discr_method='localmoments',
    n_discr_nodes=50000,
    discr_step=.01,
    deductible=0
)

meanMD = np.sum(massdispersal['sev_nodes'] * massdispersal['fj'])
meanLM = np.sum(localmoments['sev_nodes'] * localmoments['fj'])

print('Original mean: ', severity.model.mean())
print('Mean (mass dispersal): ', meanMD)
print('Mean (local moments): ', meanLM)

Classes#

PolicyStructure#

class PolicyStructure(layers=None)[source]#

Bases: object

Policy structure component of a loss model.

Parameters:

layers (Layer, LayerTower, list) – Non-proportional layer (default is infinity-xs-0 layer).

PolicyStructure.index_to_layer_name(idx)[source]#

Return name of a layer given its index.

PolicyStructure.layer_name_to_index(name)[source]#

Return index of a layer given its name.

Layer#

class Layer(cover=inf, deductible=0, aggr_cover=inf, aggr_deductible=0, n_reinst=None, reinst_percentage=0, maintenance_limit=0, share=1, basis='regular', retention=True)[source]#

Bases: object

Policy structure non-proportional layer.

Parameters:
  • deductible (int or float) – each-and-every-loss (non-ranking) deductible, also referred to as retention or priority (default value is 0).

  • cover (int or float) – each-and-every-loss cover, also referred to as limit (default value is infinity). Cover plus deductible is the upper priority or severity ‘exit point’.

  • aggr_deductible (int or float) – aggregate deductible (default value is 0).

  • aggr_cover (int or float) – aggregate cover, also referred to as aggregate limit (default is infinity).

  • n_reinst (int) – Number of reinstatements. When reinstatements are free (percentage = 0), an alternative parametrization is aggregate cover = (number of reinstatement + 1) * cover. E.g. When the number of reinstatements = 0, the aggregate cover is equal to the cover, when number of reinstatements is infinity there is no aggregate cover (the aggregate cover is infinity).

  • reinst_percentage (int or float or np.array) – percentage of reinstatements layers, a value in [0, 1]. Default value is 0, i.e. the reinstatement layer is free.

  • maintenance_limit (int or float) – maintenance limit, sometimes referred to as residual maintenance deductible or residual each-and-every-loss deductible (default is 0). Non-zero maintenance deductible applies to first layer only.

  • share (float) – Partecipation share of the layer (default is 1).

  • basis (str) – layer basis (default is ‘regular’). One of ‘regular’, ‘drop-down’, ‘stretch-down’.

  • retention (bool) – True if the layer represents a retention layer, i.e. it receives losses below the (lowest) deductible and above the overall limit. Relevant only if the Layer is in a LayerTower.

static Layer.specs()[source]#

Method (static) returning layer specifications names.

Returns:

layer specifications names.

Return type:

set

LayerTower#

class LayerTower(*args)[source]#

Bases: list

Policy structure tower of non-proportional layers.

Parameters:

**args – See below

Keyword Arguments:
  • args (Layers) – Layer tower elements.

LayerTower.append(item)[source]#

Append object to the end of the list.

LayerTower.insert(index, item)[source]#

Insert Layer at a given index.

Parameters:
  • index (int) – the index where the Layer needs to be inserted.

  • item (Layer) – the Layer to be inserted in the list.

LayerTower.extend(*args)[source]#

Extend by appending elements from the iterable.

LayerTower.sort()[source]#

Stable sort in place by layer deductible.

Frequency#

class Frequency(dist, par, threshold=0)[source]#

Bases: object

Frequency component of the loss models underlying the collective risk model.

Parameters:
  • dist (str) – name of the frequency distribution.

  • par (dict) – parameters of the frequency distribution.

  • threshold (int or float) – analysis threshold where the frequency model refers (optional). Default is 0, i.e. the ‘ground up’ or reporting threshold frequency. See pag. 323 in Parodi, P. (2014). Pricing in general insurance (first ed.).

Frequency.abp0g0(fj)[source]#

Parameters of the frequency distribution according to the (a, b, k) parametrization, the probability generating function computed in zero given the discrete severity probs, and the probability of the distribution in zero.

Parameters:

fj (numpy.ndarray) – discretized severity distribution probabilities.

Returns:

a, b, probability in zero and aggregate cost probability in zero.

Return type:

tuple

Severity#

class Severity(dist, par)[source]#

Bases: object

Severity component of the loss models underlying the collective risk model. Severity model is always considered to start at (the relative) 0, i.e. the reporting threshold.

Parameters:
  • dist (str) – name of the frequency distribution.

  • par (dict) – parameters of the frequency distribution.

Severity.excess_frequency(x, base_frequency=100)[source]#

Expected excess frequency function, i.e. expected frequency in excess of a given threshold.

Parameters:
  • x (float) – value where excess frequency is evaluated.

  • base_frequency (int, float) – frequency at origin (default is 100). Optional.

Returns:

excess frequency.

Return type:

numpy.float or float

Severity.return_period(x, base_frequency=100)[source]#

Expected return period, given a base frequency.

Parameters:
  • x (float) – value whose return period is evaluated.

  • base_frequency (int, float) – frequency at origin (default is 100). Optional.

Returns:

return period.

Return type:

numpy.float or float

Severity.censored_var(cover, deductible)[source]#

Variance of the transformed severity min(max(x - d, 0), c).

Parameters:
  • cover (int, float) – cover, also referred to as limit. cover plus deductible is the upper priority or severity ‘exit point’.

  • deductible (int, float) – deductible, also referred to as retention or priority.

Returns:

variance of the transformed severity.

Return type:

numpy.float

Severity.censored_std(cover, deductible)[source]#

Standard deviation of the transformed severity min(max(x - u, 0), v).

Parameters:
  • cover (int, float) – cover, also referred to as limit. cover plus deductible is the upper priority or severity ‘exit point’.

  • deductible (int, float) – deductible, also referred to as retention or priority.

Returns:

standard deviation of the transformed severity.

Return type:

numpy.float

Severity.censored_mean(cover, deductible)[source]#

Mean of the transformed severity min(max(x - u, 0), v). Also referred to as the stop-loss transformation function.

Parameters:
  • cover (int, float) – cover, also referred to as limit. cover plus deductible is the upper priority or severity ‘exit point’.

  • deductible (int, float) – deductible, also referred to as retention or priority.

Returns:

mean of the transformed severity.

Return type:

numpy.float

Severity.censored_skewness(cover, deductible)[source]#

Skewness of the transformed severity min(max(x - u, 0), v).

Parameters:
  • cover (int, float) – cover, also referred to as limit. cover plus deductible is the upper priority or severity ‘exit point’.

  • deductible (int, float) – deductible, also referred to as retention or priority.

Returns:

skewness of the transformed severity.

Return type:

numpy.float

Severity.censored_coeff_variation(cover, deductible)[source]#

Coefficient of variation (CoV) of the transformed severity min(max(x - u, 0), v).

Parameters:
  • cover (int, float) – cover, also referred to as limit. cover plus deductible is the upper priority or severity ‘exit point’.

  • deductible (int, float) – deductible, also referred to as retention or priority.

Returns:

CoV of the transformed severity.

Return type:

numpy.float

Severity.discretize(discr_method, n_discr_nodes, discr_step, deductible=0)[source]#

Severity discretization according to the discretization method selected by the user.

Parameters:
  • deductible (int or float) – deductible, also referred to as retention or priority.

  • discr_method (str) – severity discretization method. One of ‘massdispersal’, ‘localmoments’, ‘upperdiscretization’, ‘lowerdiscretization’.

  • discr_step (float) – severity discretization step.

  • n_discr_nodes (int) – number of nodes of the discretized severity. Optional, default is 0.

Returns:

discrete severity, nodes sequence and discrete probabilities.

Return type:

dict

Severity.plot_discr_sev_cdf(discr_method, n_discr_nodes, discr_step, deductible, log_x_scale=False, log_y_scale=False, **kwargs)[source]#

Plot the cumulative distribution function of the discretized severity distribution.

Parameters:
  • discr_method (str) – severity discretization method. One of ‘massdispersal’, ‘localmoments’, ‘upperdiscretization’, ‘lowerdiscretization’.

  • n_discr_nodes (int) – number of nodes of the discretized severity.

  • discr_step (float) – severity discretization step.

  • deductible (int or float) – deductible, also referred to as retention or priority.

  • log_x_scale (bool) – if True the x-axis scale is logarithmic (optional).

  • log_y_scale (bool) – if True the y-axis scale is logarithmic (optional).

  • **kwargs – Additional parameters as those for matplotlib.axes.Axes.step.

Returns:

plot of the cdf.

Return type:

matplotlib.figure.Figure

LossModel#

class LossModel(severity, frequency, policystructure=<gemact.lossmodel.PolicyStructure object>, aggr_loss_dist_method=None, n_sim=10000, tilt=False, tilt_value=0, random_state=None, qmc_sequence='sobol', n_aggr_dist_nodes=20000, sev_discr_method='localmoments', n_sev_discr_nodes=None, sev_discr_step=None)[source]#

Bases: object

Loss model for (re)insurance costing and risk modeling using a collective risk model framework.

Parameters:
  • severity (Severity) – severity model.

  • frequency (Frequency) – frequency model.

  • policystructure (PolicyStructure) – policy structure.

  • aggr_loss_dist_method (str) – computational method to approximate the aggregate loss distribution. One of Fast Fourier Transform (‘fft’), Panjer recursion (‘recursion’), Monte Carlo simulation (‘mc’) and quasi-Monte Carlo (‘qmc’).

  • n_sim (int) – number of simulations of Monte Carlo (‘mc’) and of quasi-Monte Carlo (‘qmc’) methods for the aggregate loss distribution approximation.

  • tilt (bool) – whether tilting of fft is present or not (default is 0).

  • tilt_value (float) – tilting parameter value of fft method for the aggregate loss distribution approximation.

  • random_state (int) – random state for the random number generator in mc and qmc.

  • qmc_sequence (str) – type of quasi-Monte Carlo low-discrepancy sequence. One of Halton - van der Corput (‘halton’), Latin hypercube (‘lhs’), and Sobol (‘sobol’). Optional (default is ‘sobol’).

  • n_aggr_dist_nodes (int) – number of nodes in the approximated aggregate loss distribution. It cannot be lower than 256.

  • sev_discr_method (str) – severity discretization method. One of ‘massdispersal’, ‘localmoments’, ‘upperdiscretization’, ‘lowerdiscretization’.

  • n_sev_discr_nodes (int) – number of nodes of the discretized severity (optional).

  • sev_discr_step (float) – severity discretization step.

LossModel.dist_calculate(aggr_loss_dist_method=None, n_aggr_dist_nodes=None, n_sim=None, random_state=None, qmc_sequence=None, sev_discr_method=None, sev_discr_step=None, n_sev_discr_nodes=None, tilt=None, tilt_value=None)[source]#

Approximate the aggregate loss distributions of each policystructure layer. Distributions can be accessed via the dist property, which is a list of distributions.PWC objects, each one representing a aggregate loss distribution.

Parameters:
  • aggr_loss_dist_method (str) – computational method to approximate the aggregate loss distribution. One of Fast Fourier Transform (‘fft’), Panjer recursion (‘recursion’), Monte Carlo simulation (‘mc’) and quasi-Monte Carlo (‘qmc’).

  • n_aggr_dist_nodes (int) – number of nodes in the approximated aggregate loss distribution. Remark: before application of eventual aggregate conditions.

  • n_sim (int) – number of simulations of Monte Carlo (‘mc’) and quasi-Monte Carlo (‘qmc’) methods for the aggregate loss distribution approximation.

  • random_state (int) – random state for the random number generator in Monte Carlo (‘mc’) and quasi-Monte Carlo (‘qmc’), optional.

  • qmc_sequence (str) – type of quasi-Monte Carlo low-discrepancy sequence. One of Halton - van der Corput (‘halton’), Latin hypercube (‘lhs’), and Sobol (‘sobol’). Optional (default is ‘sobol’).

  • sev_discr_method (str) – severity discretization method, optional (default is ‘localmoments’).

  • sev_discr_step (float) – severity discretization step.

  • n_sev_discr_nodes (int) – number of nodes of the discretized severity.

  • tilt (bool) – whether tilting of fft is present or not, optional (default is 0).

  • tilt_value (float) – tilting parameter value of fft method for the aggregate loss distribution approximation, optional.

Returns:

void

Return type:

None

LossModel.moment(central=False, n=1, idx=0)[source]#

Approximated aggregate loss distribution moment of order n. It is based on dist property.

Parameters:
  • central (bool) – True if the moment is central, False if the moment is raw.

  • n (int) – order of the moment, optional (default is 1).

  • idx (int) – list index corresponding to the layer loss distribution of interest (default is 0). See ‘index_to_layer_name’ and ‘layer_name_to_index’ PolicyStructure methods.

Returns:

moment of order n.

Return type:

numpy.float64

LossModel.ppf(q, idx=0)[source]#

Aggregate loss distribution percent point function, a.k.a. the quantile function, inverse of the cumulative distribution function.

Parameters:
  • q (float or numpy.ndarray) – probability.

  • idx (int) – list index corresponding to the layer loss distribution of interest (default is 0). See ‘index_to_layer_name’ and ‘layer_name_to_index’ PolicyStructure methods.

Returns:

quantile.

Return type:

numpy.float64 or numpy.ndarray

LossModel.cdf(x, idx=0)[source]#

Aggregate loss distribution cumulative distribution function.

Parameters:
  • x (float or int or numpy.ndarray) – quantiles where the cumulative distribution function is evaluated.

  • idx (int) – list index corresponding to the layer loss distribution of interest (default is 0). See ‘index_to_layer_name’ and ‘layer_name_to_index’ PolicyStructure methods.

Returns:

cumulative distribution function.

Return type:

numpy.float64 or numpy.ndarray

LossModel.sf(x, idx=0)[source]#

Aggregate loss distribution survival function.

Parameters:
  • x (float or int or numpy.ndarray) – quantiles where the survival functionis evaluated.

  • idx (int) – list index corresponding to the layer loss distribution of interest (default is 0). See ‘index_to_layer_name’ and ‘layer_name_to_index’ PolicyStructure methods.

Returns:

survival function.

Return type:

numpy.float64 or numpy.ndarray

LossModel.rvs(size=1, random_state=None, idx=0)[source]#

Random variates generator function.

Parameters:
  • size (int) – random variates sample size, optional (default is 1).

  • random_state (int) – random state for the random number generator, optional (no default).

  • idx (int) – list index corresponding to the layer loss distribution of interest (default is 0). See ‘index_to_layer_name’ and ‘layer_name_to_index’ PolicyStructure methods.

Returns:

random variates.

Return type:

numpy.int or numpy.ndarray

LossModel.mean(idx=0, use_dist=True)[source]#

Mean of the aggregate loss.

Parameters:
  • idx (int) – list index corresponding to the layer loss distribution of interest (default is 0). See ‘index_to_layer_name’ and ‘layer_name_to_index’ PolicyStructure methods.

  • use_dist (bool) – If True, the mean is calculated from the (approximated) aggregate loss distributon. If False, the mean is computed from the underlying frequency-severity loss model. The latter is possible only if there are no aggregate conditions in the layer of interest.

Returns:

mean of the aggregate loss.

Return type:

numpy.float64

LossModel.var(idx=0, use_dist=True)[source]#

Variance of the aggregate loss.

Parameters:
  • idx (int) – list index corresponding to the layer loss distribution of interest (default is 0). See ‘index_to_layer_name’ and ‘layer_name_to_index’ PolicyStructure methods.

  • use_dist (bool) – If True, the mean is calculated from the (approximated) aggregate loss distributon. If False, the mean is computed from the underlying frequency-severity loss model. The latter is possible only if there are no aggregate conditions in the layer of interest.

Returns:

variance of the aggregate loss.

Return type:

numpy.float64

LossModel.std(idx=0, use_dist=True)[source]#

Standard deviation of the aggregate loss.

Parameters:
  • idx (int) – list index corresponding to the layer loss distribution of interest (default is 0). See ‘index_to_layer_name’ and ‘layer_name_to_index’ PolicyStructure methods.

  • use_dist (bool) – If True, the mean is calculated from the (approximated) aggregate loss distributon. If False, the mean is computed from the underlying frequency-severity loss model. The latter is possible only if there are no aggregate conditions in the layer of interest.

Returns:

standard deviation of the aggregate loss.

Return type:

numpy.float64

LossModel.skewness(idx=0, use_dist=True)[source]#

Skewness of the aggregate loss.

Parameters:
  • idx (int) – list index corresponding to the layer loss distribution of interest (default is 0). See ‘index_to_layer_name’ and ‘layer_name_to_index’ PolicyStructure methods.

  • use_dist (bool) – If True, the skewness is calculated from the (approximated) aggregate loss distributon. If False, the skewness is computed from the underlying frequency-severity loss model. The latter is possible only if there are no aggregate conditions in the layer of interest.

Returns:

skewness of the aggregate loss.

Return type:

numpy.float64

LossModel.coeff_variation(idx=0, use_dist=True)[source]#

Coefficient of variation (CoV) of the aggregate loss.

Parameters:
  • idx (int) – list index corresponding to the layer loss distribution of interest (default is 0). See ‘index_to_layer_name’ and ‘layer_name_to_index’ PolicyStructure methods.

  • use_dist (bool) – If True, the CoV is calculated from the (approximated) aggregate loss distributon. If False, the CoV is computed from the underlying frequency-severity loss model. The latter is possible only if there are no aggregate conditions in the layer of interest.

Returns:

CoV of the aggregate loss.

Return type:

numpy.float64

LossModel.costing()[source]#

Actuarial costing (also referred to as risk costing) of (re)insurance covers, such as quota share, excess-of-loss (including reinstatements or aggregate conditions) and stop loss.

Returns:

Void

Return type:

None

LossModel.print_costing_specs(idx=0)[source]#

Print costing information of a given layer (specified via its index).

Parameters:

idx (int) – index corresponding to the policystructure layer of interest (default is 0). See ‘index_to_layer_name’ and ‘layer_name_to_index’ PolicyStructure methods.

Returns:

Void

Return type:

None

LossModel.print_aggr_loss_method_specs(idx=0)[source]#

Print information of the aggregate loss distribution approximation for a given layer (specified via its index).

Parameters:

idx (int) – index corresponding to the policystructure layer of interest (default is 0). See ‘index_to_layer_name’ and ‘layer_name_to_index’ PolicyStructure methods.

Returns:

Void

Return type:

None

LossModel.print_policy_layer_specs(idx=0)[source]#

Print policy structure information of a given layer (specified via its index).

Parameters:

idx (int) – index corresponding to the policystructure layer of interest (default is 0). See ‘index_to_layer_name’ and ‘layer_name_to_index’ PolicyStructure methods.

Returns:

Void

Return type:

None

LossModel.plot_dist_cdf(idx=0, log_x_scale=False, log_y_scale=False, **kwargs)[source]#

Plot the cumulative distribution function of the aggregate loss distribution.

Parameters:
  • idx (int) – index corresponding to the policystructure layer of interest (default is 0). See ‘index_to_layer_name’ and ‘layer_name_to_index’ PolicyStructure methods.

  • log_x_scale (bool) – if True the x-axis scale is logarithmic (optional).

  • log_y_scale (bool) – if True the y-axis scale is logarithmic (optional).

  • **kwargs – Additional parameters as those for matplotlib.axes.Axes.step.

Returns:

plot of the cdf.

Return type:

matplotlib.figure.Figure

LossReserve#

Claims reserving#

GEMAct provides a software implementation of average cost methods for claims reserving based on the collective risk model framework. The methods implemented are the Fisher-Lange method in Fisher et al. [FLB99] and the collective risk model for claims reserving in Ricotta and Clemente [RC16].

It allows for tail estimates and assumes the triangular inputs to be provided as a numpy.ndarray with two equal dimensions (I,J), where I=J. The aim of average cost methods is to model incremental payments as in equation (11).

(11)#\[P_{i,j}=n_{i,j} \cdot m_{i,j}\]

where \(n_{i,j}\) is the number of payments in the cell \(i,j\) and \(m_{i,j}\) is the average cost in the cell \(i,j\).

Example#

It is possible to use the module gemdata to test GEMAct average cost methods:

from gemact import gemdata

ip_ = gemdata.incremental_payments
in_ = gemdata.incurred_number
cp_ = gemdata.cased_payments
cn_ = gemdata.cased_number
reported_ = gemdata.reported_claims
claims_inflation = gemdata.claims_inflation

An example of Fisher-Lange implementation:

from gemact.lossreserve import AggregateData, ReservingModel, LossReserve
from gemact import gemdata

ad = AggregateData(
    incremental_payments=gemdata.incremental_payments,
    cased_payments=gemdata.cased_payments,
    payments_number=gemdata.payments_number,
    open_claims_number=gemdata.open_number,
    reported_claims=gemdata.reported_claims
)

rm = ReservingModel(
    tail=True,
    reserving_method="fisher_lange",
    claims_inflation=gemdata.claims_inflation
)

lr = LossReserve(data=ad, reservingmodel=rm)

Classes#

AggregateData#

class AggregateData(incremental_payments, cased_payments, payments_number, open_claims_number, reported_claims, cumulative_payments=None)[source]#

Bases: object

Triangular data sets.

Parameters:
  • cumulative_payments (numpy.ndarray) – cumulative payments triangle.

  • incremental_payments (numpy.ndarray) – incremental payments triangle.

  • cased_payments (numpy.ndarray) – cased payments triangle.

  • payments_number (numpy.ndarray) – number of paid claims.

  • open_claims_number (numpy.ndarray) – number of open claims.

  • reported_claims (numpy.ndarray) – number of reported claims by accident period. Data must be provided from old to recent.

ReservingModel#

class ReservingModel(tail=False, reserving_method='fisher_lange', claims_inflation=None, mixing_fq_par=None, mixing_sev_par=None, czj=None)[source]#

Bases: object

Reserving model assumptions.

Parameters:
  • tail (bool) – True when the tail estimate is required else false (optional). Default False.

  • reserving_method (str) – one of the reserving methods supported by the GemAct package.

  • claims_inflation (numpy.ndarray) – claims inflation. In case no tail is present and the triangular data IxJ matrices, claims_inflation must be J-1 dimensional. When a tail estimate is required, it must be J dimensional. In case no tail is present it must be J-1 dimensional.

  • czj (numpy.ndarray) – severity coefficient of variation by development period. It is set to None in case the crm is selected as reserving method. When a tail estimate is required, it must be J dimensional. In case no tail is present it must be J-1 dimensional.

  • mixing_fq_par (dict) – Mixing frequency parameters.

  • mixing_sev_par (dict) – Mixing severity parameters.

LossReserve#

class LossReserve(data, reservingmodel, custom_alphas=None, custom_ss=None, ntr_sim=1000, random_state=None)[source]#

Bases: object

Claims loss reserving. The available reserving models are the deterministic Fisher-Lange and the collective risk model. Input company data must be numpy.ndarray data on numbers and payments must be in triangular form: two-dimensional numpy.ndarray with shape (I, J) where I=J.

Parameters:
  • ntr_sim (int) – Number of simulated triangles in the c.r.m reserving method.

  • random_state (int) – Simulation seed to make the c.r.m reserving method results reproducible.

  • custom_alphas (numpy.ndarray) – optional, custom values for the alpha parameters.

  • custom_ss (numpy.ndarray) – optional, custom values for the settlement speed.

LossReserve.plot_ss_fl(start_=0)[source]#

Plot the settlement speed vector for each accident period.

Parameters:

start (int) – starting accident period from which to plot.

LossReserve.plot_alpha_fl()[source]#

Plot the Fisher-Lange alpha.

LossReserve.print_loss_reserve()[source]#

Table with claims reserve results. When the stochastic reserve according to the collective risk model is computed the results are compared with the Fisher-Lange.

LossReserve.mean(use_dist=False)[source]#

Mean of the loss reserve. Depending on the selected reserving method, it returns either the attribute crm_reserve or fl_reserve.

Parameters:

use_dist (bool) – parameter that sets whether or not the approximate distribution should be used. Default False.

Returns:

mean of the loss reserve.

Return type:

numpy.float64

LossReserve.std(use_dist=True)[source]#

Standard deviation of the loss reserve (not available for claims reserving with the fisher lange).

Parameters:

use_dist (bool) – parameter that sets whether or not the approximate distribution should be used. Default False.

Returns:

standard deviation of the loss reserve.

Return type:

numpy.float64

LossReserve.var(use_dist=True)[source]#

Variance of the loss reserve (not available for claims reserving with the fisher lange).

Parameters:

use_dist (bool) – parameter that sets whether or not the approximate distribution should be used. Default False.

Returns:

Variance of the loss reserve.

Return type:

numpy.float64

LossReserve.skewness(use_dist=True)[source]#

Skewness of the loss reserve (not available for claims reserving with the fisher lange).

Returns:

skewness of the loss reserve.

Return type:

numpy.float64

LossReserve.ppf(q)[source]#

Aggregate loss reserve percent point function, a.k.a. the quantile function. This is only available for stochastic methods.

Parameters:

q (float or numpy.ndarray) – probability.

Returns:

quantile.

Return type:

numpy.float64 or numpy.ndarray

LossReserve.cdf(x)[source]#

Aggregate loss reserve cumulative density function. This is only available for stochastic methods.

Parameters:

x (float or numpy.ndarray) – quantile.

Returns:

probability.

Return type:

numpy.float64 or numpy.ndarray

LossReserve.sf(x)[source]#

Survival function, 1 - cumulative distribution function.

Parameters:

x (int or float) – quantile where the survival function is evaluated.

Returns:

survival function

Return type:

numpy.float64 or numpy.ndarray

LossAggregation#

Loss aggregation#

(12)#\[P\left[ X_1 +\ldots +X_d \right] \approx P_n(s)\]

The probability in equation (12) can be approximated iteratively via the AEP algorithm, which is implemented in GEMAct under the following assumptions:

  • \(X=(X_1, \ldots, X_d)\) is a vector of strictly positive random components.

  • The joint c.d.f. \(H(x_1,\ldots,x_d)=P\left[ X_1 +\ldots +X_d \right]\) is known or it can be computed numerically.

Refer to Arbenz et al. [AEP11] for an extensive explanation of the AEP algorithm. It is possible to use Monte Carlo simulation for comparison.

Example#

Example code under a Frank copula assumption:

from gemact.lossaggregation import LossAggregation, Copula, Margins

lossaggregation = LossAggregation(
    margins=Margins(
        dist=['genpareto', 'lognormal'],
        par=[
            {'loc': 0, 'scale': 1/.9, 'c': 1/.9},
            {'loc': 0, 'scale': 10, 'shape': 1.5}
        ],
    ),
    copula=Copula(
        dist='frank',
        par={'par': 1.2, 'dim': 2}
    ),
    n_sim=500000,
    random_state=10,
    n_iter=8
)

s = 300
p_aep = lossaggregation.cdf(x=s, method='aep')
p_mc = lossaggregation.cdf(x=s, method='mc')

Classes#

Margins#

class Margins(dist, par)[source]#

Bases: object

Marginal components of Loss Aggregation.

Parameters:
  • dist (list) – list of the marginal distributions.

  • par (list) – list of the marginal distributions parameters. It must be a list of dictionaries.

Margins.ppf(q)[source]#

Margin percent point function, a.k.a. the quantile function, inverse of the cumulative distribution function.

Parameters:

q (numpy.ndarray) – probabilities. Shape must be (dim, size) where size is the number of points to be evaluated.

Returns:

quantile.

Return type:

numpy.ndarray

Margins.cdf(x)[source]#

Margin cumulative distribution function.

Parameters:

x (numpy.ndarray) – quantiles where the cumulative distribution function is evaluated. Shape must be (dim, size) where size is the number of points to be evaluated.

Returns:

cumulative distribution function.

Return type:

numpy.ndarray

Copula#

class Copula(dist, par)[source]#

Bases: object

Copula component of Loss Aggregation.

Parameters:
  • dist (str) – name of the copula distribution.

  • par (dict) – parameters of the copula distribution.

Copula.rvs(size, random_state)[source]#

Random variates generator function.

Parameters:
  • size (int) – random variates sample size.

  • random_state (int) – random state for the random number generator.

Returns:

random variates.

Return type:

numpy.ndarray

Copula.cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (numpy.ndarray) – quantiles where the cumulative distribution function is evaluated. Shape must be (dim, size) where size is the number of points to be evaluated.

Returns:

cumulative distribution function.

Return type:

numpy.ndarray

LossAggregation#

class LossAggregation(copula, margins, n_sim=None, random_state=None, n_iter=7, tol=0.0001)[source]#

Bases: object

Class representing the sum of positive random variables. Dependence structure is specified by a copula.

Parameters:
  • copula (Copula) – name of the copula that describes the dependence structure.

  • margins (Margins) – list of the marginal distributions.

  • n_sim (int) – number of Monte Carlo simulations (optional). If None the simulation is skipped.

  • random_state (int) – random state for the random number generator (optional).

  • n_iter (int) – number of AEP algorithm iterations (optional).

  • tol (float) – tolerance threshold for AEP ppf, maximum allowed absolute difference between cumulative probability values (optional).

LossAggregation.dist_calculate(n_sim=None, random_state=None)[source]#

Approximate the distribution of the sum of random variable with a given dependence structure by executing a Monte Carlo simulation. The resulting distribution can be accessed via the dist property, which is a distributions.PWC object.

Parameters:
  • n_sim (int) – number of simulations of Monte Carlo simulation (optional).

  • random_state (int) – random state for the random number generator (optional).

Returns:

Void.

Return type:

None

LossAggregation.cdf(x, method='mc', n_iter=None)[source]#

Cumulative distribution function of the random variable sum. If method is Monte Carlo (‘mc’) the function relies on the approximated distribution calculated via dist_calculate method when the object is initiated (accessed via the dist property). If method is AEP (‘aep’) the function is evaluated pointwise, on-the-fly, regardless of the dist property.

Parameters:
  • x (float) – quantiles where the cumulative distribution function are evaluated.

  • method (string) – method to approximate the cdf of the sum of the random variables. One of AEP (‘aep’) and Monte Carlo simulation (‘mc’).

  • n_iter (int) – number of AEP algorithm iterations (optional).

Returns:

cumulative distribution function.

Return type:

numpy.float64 or numpy.ndarray

LossAggregation.sf(x, method='mc', n_iter=None)[source]#

Survival function of the random variable sum. If method is Monte Carlo (‘mc’) the function relies on the approximated distribution calculated via dist_calculate method when the object is initiated (accessed via the dist property). If method is AEP (‘aep’) the function is evaluated pointwise, on-the-fly, regardless of the dist property.

Parameters:
  • x (float) – quantiles where the survival function are evaluated.

  • method (string) – method to approximate the survival function of the sum of the random variables. One of AEP (‘aep’) and Monte Carlo simulation (‘mc’).

  • n_iter (int) – number of AEP algorithm iterations (optional).

Returns:

survival function.

Return type:

numpy.float64 or numpy.ndarray

LossAggregation.ppf(q, method='mc', n_iter=None, tol=0.0001)[source]#

Percent point function, a.k.a. the quantile function, of the random variable sum. Inverse of cumulative distribution function. If method is Monte Carlo (‘mc’) the function relies on the approximated distribution calculated via dist_calculate method when the object is initiated (accessed via the dist property). If method is AEP (‘aep’) the function is evaluated pointwise, on-the-fly, regardless of the dist property. It adopts the scipy.optimize.brentq optimizer.

Parameters:
  • q (float, numpy.ndarray, numpy.floating) – probabilities where point function is evaluated.

  • method (string) – method to approximate the ppf of the sum of the random variables. One of AEP (‘aep’) and Monte Carlo simulation (‘mc’).

  • n_iter (int) – number of AEP algorithm iterations (optional).

  • tol (float) – tolerance threshold, maximum allowed absolute difference between cumulative probability values (optional).

Returns:

percent point function.

Return type:

numpy.float64 or numpy.int or numpy.ndarray

LossAggregation.rvs(size=1, random_state=None, method='mc', n_iter=None, tol=None)[source]#

Random variates generator function. If method is Monte Carlo (‘mc’) the function use inverse transform sampling via copula, margins and then apply the sum. If method is AEP (‘aep’) the function use the inverse transform sampling via ‘aep’ ppf. The latter option is time demanding.

Parameters:
  • size (int) – random variates sample size (default is 1).

  • random_state (int) – random state for the random number generator.

  • method (string) – method to execute the generator of random variates. One of AEP (‘aep’) and Monte Carlo simulation (‘mc’).

  • n_iter (int) – number of AEP algorithm iterations (optional).

  • tol (float) – tolerance threshold, maximum allowed absolute difference between cumulative probability values (optional).

Returns:

Random variates.

Return type:

numpy.float64 or numpy.ndarray

LossAggregation.moment(central=False, n=1)[source]#

Moment of order n of the random variable sum. It is based on Monte Carlo simulation results, i.e. dist property.

Parameters:
  • central (bool) – True if the moment is central, False if the moment is raw.

  • n (int) – order of the moment, optional (default is 1).

Returns:

moment of order n.

Return type:

numpy.float64

LossAggregation.mean()[source]#

Mean of the random variable sum. It is based on Monte Carlo simulation results, i.e. dist property.

Returns:

mean.

Return type:

numpy.float64

LossAggregation.skewness()[source]#

Skewness of the random variable sum. It is based on Monte Carlo simulation results, i.e. dist property.

Returns:

skewness.

Return type:

numpy.float64

LossAggregation.var()[source]#

Variance of the random variable sum. It is based on Monte Carlo simulation results, i.e. dist property.

Returns:

variance.

Return type:

numpy.float64

LossAggregation.std()[source]#

Standard deviation of the random variable sum. It is based on Monte Carlo simulation results, i.e. dist property.

Returns:

standard deviation.

Return type:

numpy.float64

LossAggregation.lev(v)[source]#

Limited expected value, i.e. expected value of the function min(x, v).

Parameters:

v (int, float, numpy.float or numpy.ndarray) – values with respect to the minimum.

Returns:

expected value of the minimum function.

Return type:

numpy.float or numpy.ndarray

LossAggregation.censored_moment(n, u, v)[source]#

Non-central moment of order n of the transformed random variable min(max(x - u, 0), v). When n = 1 it is the so-called stop loss transformation function.

Parameters:
  • u (int, float, numpy.float or numpy.ndarray) – lower censoring point.

  • v (int, float, numpy.float or numpy.ndarray) – difference between the upper and the lower censoring points, i.e. v + u is the upper censoring point.

  • n (int) – moment order.

Returns:

censored raw moment of order n.

Return type:

numpy.float or numpy.ndarray

LossAggregation.plot_cdf(log_x_scale=False, log_y_scale=False, **kwargs)[source]#

Plot the cumulative distribution function of the random variable sum. It is based on Monte Carlo simulation results, i.e. dist property.

Parameters:
  • log_x_scale (bool) – if True the x-axis scale is logarithmic (optional).

  • log_y_scale (bool) – if True the y-axis scale is logarithmic (optional).

  • **kwargs – Additional parameters as those for matplotlib.axes.Axes.step.

Returns:

plot of the cdf.

Return type:

matplotlib.figure.Figure

distributions module#

The distribution classes below are documented at class level and through explicitly documented methods. Inherited private base classes are intentionally not expanded here to avoid repeated private-class documentation.

Frequency distributions#

Poisson#

class Poisson(loc=0, **kwargs)[source]#

Bases: _DiscreteDistribution

Poisson distribution. Wrapper to scipy poisson distribution (scipy.stats._discrete_distns.poisson_gen) Refer to :py:class:’~_DiscreteDistribution’ for additional details.

Parameters:
  • loc (int, optional) – location parameter (default=0), to shift the support of the distribution.

  • **kwargs – See below

Keyword Arguments:
  • mu (numpy.float64) – Poisson distribution parameter mu (rate).

Poisson.pgf(f)[source]#

Probability generating function. It computes the probability generating function of the random variable given the (a, b, k) parametrization.

Parameters:

f (numpy array) – point where the function is evaluated.

Returns:

probability generated in f.

Return type:

numpy.ndarray

Poisson.par_deductible_adjuster(nu)[source]#

Parameter correction in case of deductible.

Parameters:

nu (float) – severity model survival function at the deductible.

Returns:

Void

Return type:

None

Poisson.par_deductible_reverter(nu)[source]#

Undo parameter correction in case of deductible.

Parameters:

nu (float) – severity model survival function at the deductible.

Returns:

Void

Return type:

None

Poisson.abk()[source]#

Function returning (a, b, k) parametrization.

Returns:

a, b, probability in zero

Return type:

numpy.array

Poisson.skewness()[source]#

Skewness (third standardized moment).

Returns:

skewness.

Return type:

float

Poisson.kurtosis()[source]#

Excess kurtosis.

Returns:

Excess kurtosis.

Return type:

float

Binom#

class Binom(loc=0, **kwargs)[source]#

Bases: _DiscreteDistribution

Binomial distribution. Wrapper to scipy binomial distribution (scipy.stats._discrete_distns.binom_gen). Refer to :py:class:’~_DiscreteDistribution’ for additional details.

Parameters:
  • loc (int, optional) – location parameter (default=0), to shift the support of the distribution.

  • **kwargs – See below

Keyword Arguments:
  • n (int) – Number of trials.

  • p (float) – Probability of a success, parameter of the binomial distribution.

Binom.pgf(f)[source]#

Probability generating function. It computes the probability generating function of the random variable given the (a, b, k) parametrization.

Parameters:

f (numpy array) – point where the function is evaluated

Returns:

probability generated in f.

Return type:

numpy.ndarray

Binom.par_deductible_adjuster(nu)[source]#

Parameter correction in case of deductible.

Parameters:

nu (float) – severity model survival function at the deductible.

Returns:

Void

Return type:

None

Binom.par_deductible_reverter(nu)[source]#

Undo parameter correction in case of deductible.

Parameters:

nu (float) – severity model survival function at the deductible.

Returns:

Void

Return type:

None

Binom.abk()[source]#

Function returning (a, b, k) parametrization.

Returns:

a, b, probability in zero

Return type:

numpy.array

Binom.skewness()[source]#

Skewness (third standardized moment).

Returns:

skewness.

Return type:

float

Binom.kurtosis()[source]#

Excess kurtosis.

Returns:

Excess kurtosis.

Return type:

float

Geom#

class Geom(loc=0, **kwargs)[source]#

Bases: _DiscreteDistribution

Geometric distribution. Wrapper to scipy geometric distribution (scipy.stats._discrete_distns.geom_gen). Refer to :py:class:’~_DiscreteDistribution’ for additional details.

Parameters:
  • loc (int, optional) – location parameter (default=0), to shift the support of the distribution.

  • **kwargs – See below

Keyword Arguments:
  • p (float) – Probability parameter of the geometric distribution.

Geom.pgf(f)[source]#

Probability generating function. It computes the probability generating function of the random variable given the (a, b, k) parametrization.

Parameters:

f (numpy array) – point where the function is evaluated

Returns:

probability generated in f.

Return type:

numpy.ndarray

Geom.par_deductible_adjuster(nu)[source]#

Parameter correction in case of deductible.

Parameters:

nu (float) – severity model survival function at the deductible.

Returns:

Void

Return type:

None

Geom.par_deductible_reverter(nu)[source]#

Undo parameter correction in case of deductible.

Parameters:

nu (float) – severity model survival function at the deductible.

Returns:

Void

Return type:

None

Geom.abk()[source]#

Function returning (a, b, k) parametrization.

Returns:

a, b, probability in zero

Return type:

numpy.array

Geom.skewness()[source]#

Skewness (third standardized moment).

Returns:

skewness.

Return type:

float

Geom.kurtosis()[source]#

Excess kurtosis.

Returns:

Excess kurtosis.

Return type:

float

NegBinom#

class NegBinom(loc=0, **kwargs)[source]#

Bases: _DiscreteDistribution

Negative Binomial distribution. Wrapper to scipy negative binomial distribution (scipy.stats._discrete_distns.nbinom_gen). Refer to :py:class:’~_DiscreteDistribution’ for additional details.

Parameters:
  • loc (int, optional) – location parameter (default=0), to shift the support of the distribution.

  • **kwargs – See below

Keyword Arguments:
  • n (int) – Size parameter of the negative binomial distribution.

  • p (float) – Probability parameter of the negative binomial distribution.

NegBinom.pgf(f)[source]#

Probability generating function. It computes the probability generating function of the random variable given the (a, b, k) parametrization.

Parameters:

f (numpy array) – point where the function is evaluated.

Returns:

probability generated in f.

Return type:

numpy.ndarray

NegBinom.par_deductible_adjuster(nu)[source]#

Parameter correction in case of deductible.

Parameters:

nu (float) – severity model survival function at the deductible.

Returns:

Void

Return type:

None

NegBinom.par_deductible_reverter(nu)[source]#

Undo parameter correction in case of deductible.

Parameters:

nu (float) – severity model survival function at the deductible.

Returns:

Void

Return type:

None

NegBinom.abk()[source]#

Function returning (a, b, k) parametrization.

Returns:

a, b, probability in zero

Return type:

numpy.array

NegBinom.skewness()[source]#

Skewness (third standardized moment).

Returns:

skewness.

Return type:

float

NegBinom.kurtosis()[source]#

Excess kurtosis.

Returns:

Excess kurtosis.

Return type:

float

Logser#

class Logser(loc=0, **kwargs)[source]#

Bases: _DiscreteDistribution

Logarithmic (Log-Series, Series) discrete distribution. Wrapper to scipy logser distribution (scipy.stats._discrete_distns.logser_gen) Refer to :py:class:’~_DiscreteDistribution’ for additional details.

Parameters:
  • loc (int, optional) – location parameter (default=0), to shift the support of the distribution.

  • **kwargs – See below

Keyword Arguments:
  • p (float) – Probability parameter of the logser distribution.

Logser.pgf(f)[source]#

Probability generating function. It computes the probability generating function of the random variable given the (a, b, k) parametrization.

Parameters:

f (numpy array) – point where the function is evaluated.

Returns:

probability generated in f.

Return type:

numpy.ndarray

Logser.abk()[source]#

Function returning (a, b, k) parametrization.

Returns:

a, b, probability in zero

Return type:

numpy.array

Logser.par_deductible_adjuster(nu)[source]#

Parameter correction in case of deductible.

Parameters:

nu (float) – severity model survival function at the deductible.

Returns:

Void

Return type:

None

Logser.par_deductible_reverter(nu)[source]#

Undo parameter correction in case of deductible.

Parameters:

nu (float) – severity model survival function at the deductible.

Returns:

Void

Return type:

None

ZTPoisson#

class ZTPoisson(loc=0, **kwargs)[source]#

Bases: object

Zero-truncated Poisson distribution. Poisson distribution with no mass (truncated) in 0. scipy reference non-zero-truncated distribution: scipy.stats._discrete_distns.poisson_gen

Parameters:
  • loc (int, optional) – location parameter (default=0), to shift the support of the distribution.

  • **kwargs – See below

Keyword Arguments:
  • mu (numpy.float64) – Zero-truncated Poisson distribution parameter mu (rate).

ZTPoisson.pmf(x)[source]#

Probability mass function.

Parameters:

x (int) – quantile where probability mass function is evaluated.

Returns:

probability mass function.

Return type:

numpy.float64 or numpy.ndarray

ZTPoisson.logpmf(x)[source]#

Natural logarithm of the probability mass function.

Parameters:

x (int) – quantile where the (natural) probability mass function logarithm is evaluated.

Returns:

natural logarithm of the probability mass function

Return type:

numpy.float64 or numpy.ndarray

ZTPoisson.cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (float) – quantile where the cumulative distribution function is evaluated.

Returns:

cumulative distribution function.

Return type:

numpy.float64 or numpy.ndarray

ZTPoisson.logcdf(x)[source]#

Natural logarithm of the cumulative distribution function.

Parameters:

x (int) – quantile where log of the cumulative distribution function is evaluated.

Returns:

natural logarithm of the cumulative distribution function.

Return type:

numpy.float64 or numpy.ndarray

ZTPoisson.rvs(size=1, random_state=None)[source]#

Random variates generator function.

Parameters:
  • size (int, optional) – random variates sample size (default is 1).

  • random_state (int, optional) – random state for the random number generator.

Returns:

random variates.

Return type:

numpy.int or numpy.ndarray

ZTPoisson.ppf(q)[source]#

Percent point function, a.k.a. the quantile function, inverse of cumulative distribution function.

Parameters:

q (float) – level at which the percent point function is evaluated.

Returns:

percent point function.

Return type:

numpy.int or numpy.ndarray

ZTPoisson.mean()[source]#

Mean of the distribution.

Returns:

mean.

Return type:

numpy.float64

ZTPoisson.var()[source]#

Variance of the distribution.

Returns:

variance.

Return type:

numpy.float64

ZTPoisson.pgf(f)[source]#

Probability generating function. It computes the probability generating function of the random variable given the (a, b, k) parametrization.

Parameters:

f (numpy array) – point where the function is evaluated

Returns:

probability generated in f.

Return type:

numpy.ndarray

ZTPoisson.abk()[source]#

Function returning (a, b, k) parametrization.

Returns:

a, b, probability in zero

Return type:

numpy.array

ZTPoisson.par_deductible_adjuster(nu)[source]#

Parameter correction in case of deductible.

Parameters:

nu (float) – severity model survival function at the deductible.

Returns:

Void

Return type:

None

ZTPoisson.par_deductible_reverter(nu)[source]#

Undo parameter correction in case of deductible.

Parameters:

nu (float) – severity model survival function at the deductible.

Returns:

Void

Return type:

None

ZMPoisson#

class ZMPoisson(loc=0, maxdiff=0.95, **kwargs)[source]#

Bases: object

Zero-modified Poisson distribution. Discrete mixture between a degenerate distribution at zero and a non-modified Poisson distribution. scipy reference non-zero-modified distribution: scipy.stats._discrete_distns.poisson_gen

Parameters:
  • loc (int, optional) – location parameter (default=0).

  • maxdiff (float, optional) – threshold to determine which method to generate random variates (default=0.95).

  • **kwargs – See below

Keyword Arguments:
  • mu (numpy.float64) – Zero-modified Poisson distribution rate parameter.

  • p0m (numpy.float64) – Zero-modified Poisson mixing parameter. Resulting probability mass in zero.

ZMPoisson.pmf(x)[source]#

Probability mass function.

Parameters:

x (int) – quantile where probability mass function is evaluated.

Returns:

probability mass function.

Return type:

numpy.float64 or numpy.ndarray

ZMPoisson.logpmf(x)[source]#

Natural logarithm of the probability mass function.

Parameters:

x (int) – quantile where the (natural) probability mass function logarithm is evaluated.

Returns:

natural logarithm of the probability mass function

Return type:

numpy.float64 or numpy.ndarray

ZMPoisson.cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (int) – quantile where the cumulative distribution function is evaluated.

Returns:

cumulative distribution function.

Return type:

numpy.float64 or numpy.ndarray

ZMPoisson.logcdf(x)[source]#

Natural logarithm of the cumulative distribution function.

Parameters:

x (int) – quantile where log of the cumulative distribution function is evaluated.

Returns:

natural logarithm of the cumulative distribution function.

Return type:

numpy.float64 or numpy.ndarray

ZMPoisson.rvs(size=1, random_state=None)[source]#

Random variates generator function.

Parameters:
  • size (int, optional) – random variates sample size (default is 1).

  • random_state (int, optional) – random state for the random number generator.

Returns:

random variates.

Return type:

numpy.int or numpy.ndarray

ZMPoisson.ppf(q)[source]#

Percent point function, a.k.a. the quantile function, inverse of cumultaive distribution function.

Parameters:

q (float) – level at which the percent point function is evaluated.

Returns:

percent point function.

Return type:

numpy.int or numpy.ndarray

ZMPoisson.pgf(f)[source]#

Probability generating function. It computes the probability generating function of the random variable given the (a, b, k) parametrization.

Parameters:

f (numpy array) – point where the function is evaluated

Returns:

probability generated in f.

Return type:

numpy.ndarray

ZMPoisson.abk()[source]#

Function returning (a, b, k) parametrization.

Returns:

a, b, probability in zero

Return type:

numpy.array

ZMPoisson.par_deductible_adjuster(nu)[source]#

Parameter correction in case of deductible.

Parameters:

nu (float) – severity model survival function at the deductible.

Returns:

Void

Return type:

None

ZMPoisson.par_deductible_reverter(nu)[source]#

Undo parameter correction in case of deductible.

Parameters:

nu (float) – severity model survival function at the deductible.

Returns:

Void

Return type:

None

ZTBinom#

class ZTBinom(**kwargs)[source]#

Bases: object

Zero-truncated binomial distribution. Binomial distribution with no mass (truncated) in 0. scipy reference non-zero-truncated distribution: scipy.stats._discrete_distns.binom_gen .

Parameters:

**kwargs – See below

Keyword Arguments:
  • n (int) – Zero-truncated binomial distribution size parameter n.

  • p (float) – Zero-truncated binomial distribution probability parameter p.

ZTBinom.pmf(x)[source]#

Probability mass function.

Parameters:

x (int) – quantile where probability mass function is evaluated.

Returns:

probability mass function.

Return type:

numpy.float64 or numpy.ndarray

ZTBinom.logpmf(x)[source]#

Natural logarithm of the probability mass function.

Parameters:

x (int) – quantile where the (natural) probability mass function logarithm is evaluated.

Returns:

natural logarithm of the probability mass function

Return type:

numpy.float64 or numpy.ndarray

ZTBinom.cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (int) – quantile where the cumulative distribution function is evaluated.

Returns:

cumulative distribution function.

Return type:

numpy.float64 or numpy.ndarray

ZTBinom.logcdf(x)[source]#

Natural logarithm of the cumulative distribution function.

Parameters:

x (int) – quantile where log of the cumulative distribution function is evaluated.

Returns:

natural logarithm of the cumulative distribution function.

Return type:

numpy.float64 or numpy.ndarray

ZTBinom.rvs(size=1, random_state=None)[source]#

Random variates generator function.

Parameters:
  • size (int, optional) – random variates sample size (default is 1).

  • random_state (int, optional) – random state for the random number generator.

Returns:

random variates.

Return type:

numpy.int or numpy.ndarray

ZTBinom.ppf(q)[source]#

Percent point function, a.k.a. the quantile function, inverse of cumulative distribution function.

Parameters:

q (float) – level at which the percent point function is evaluated.

Returns:

percent point function.

Return type:

numpy.int or numpy.ndarray

ZTBinom.mean()[source]#

Mean of the distribution.

Returns:

mean.

Return type:

numpy.float64

ZTBinom.var()[source]#

Variance of the distribution.

Returns:

variance.

Return type:

numpy.float64

ZTBinom.pgf(f)[source]#

Probability generating function. It computes the probability generating function of the random variable given the (a, b, k) parametrization.

Parameters:

f (numpy array) – point where the function is evaluated

Returns:

probability generated in f.

Return type:

numpy.ndarray

ZTBinom.abk()[source]#

Function returning (a, b, k) parametrization.

Returns:

a, b, probability in zero

Return type:

numpy.array

ZTBinom.par_deductible_adjuster(nu)[source]#

Parameter correction in case of deductible.

Parameters:

nu (float) – severity model survival function at the deductible.

Returns:

Void

Return type:

None

ZTBinom.par_deductible_reverter(nu)[source]#

Undo parameter correction in case of deductible.

Parameters:

nu (float) – severity model survival function at the deductible.

Returns:

Void

Return type:

None

ZMBinom#

class ZMBinom(**kwargs)[source]#

Bases: object

Zero-modified binomial distribution. Discrete mixture between a degenerate distribution at zero and a non-modified binomial distribution. scipy reference non-zero-modified distribution: scipy.stats._discrete_distns.binom_gen.

Parameters:

**kwargs – See below

Keyword Arguments:
  • n (numpy.float64) – Zero-modified binomial distribution size parameter n.

  • p (numpy.float64) – Zero-modified binomial distribution probability parameter p.

  • p0m (numpy.float64) – Zero-modified binomial mixing parameter.

ZMBinom.pmf(x)[source]#

Probability mass function.

Parameters:

x (int) – quantile where probability mass function is evaluated.

Returns:

probability mass function.

Return type:

numpy.float64 or numpy.ndarray

ZMBinom.logpmf(x)[source]#

Natural logarithm of the probability mass function.

Parameters:

x (int) – quantile where the (natural) probability mass function logarithm is evaluated.

Returns:

natural logarithm of the probability mass function

Return type:

numpy.float64 or numpy.ndarray

ZMBinom.cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (int) – quantile where the cumulative distribution function is evaluated.

Returns:

cumulative distribution function.

Return type:

numpy.float64 or numpy.ndarray

ZMBinom.logcdf(x)[source]#

Natural lograithm of the cumulative distribution function.

Parameters:

x (int) – quantile where log of the cumulative distribution function is evaluated.

Returns:

natural logarithm of the cumulative distribution function.

Return type:

numpy.float64 or numpy.ndarray

ZMBinom.rvs(size=1, random_state=None)[source]#

Random variates generator function.

Parameters:
  • size (int, optional) – random variates sample size (default is 1).

  • random_state (int, optional) – random state for the random number generator.

Returns:

random variates.

Return type:

numpy.int or numpy.ndarray

ZMBinom.ppf(q)[source]#

Percent point function, a.k.a. the quantile function, inverse of cumulative distribution function.

Parameters:

q (float) – level at which the percent point function is evaluated.

Returns:

percent point function.

Return type:

numpy.int or numpy.ndarray

ZMBinom.pgf(f)[source]#

Probability generating function. It computes the probability generating function of the random variable given the (a, b, k) parametrization.

Parameters:

f (numpy array) – point where the function is evaluated

Returns:

probability generated in f.

Return type:

numpy.ndarray

ZMBinom.abk()[source]#

Function returning (a, b, k) parametrization.

Returns:

a, b, probability in zero

Return type:

numpy.array

ZMBinom.par_deductible_adjuster(nu)[source]#

Parameter correction in case of deductible.

Parameters:

nu (float) – severity model survival function at the deductible.

Returns:

Void

Return type:

None

ZMBinom.par_deductible_reverter(nu)[source]#

Undo parameter correction in case of deductible.

Parameters:

nu (float) – severity model survival function at the deductible.

Returns:

Void

Return type:

None

ZTGeom#

class ZTGeom(**kwargs)[source]#

Bases: object

Zero-truncated geometric distribution. Geometric distribution with no mass (truncated) in 0. scipy reference non-zero-truncated distribution: scipy.stats._discrete_distns.geom_gen

Parameters:

**kwargs – See below

Keyword Arguments:
  • p (numpy.float64) – Zero-truncated geometric distribution probability parameter p.

ZTGeom.pmf(x)[source]#

Probability mass function.

Parameters:

x (int) – quantile where probability mass function is evaluated.

Returns:

probability mass function.

Return type:

numpy.float64 or numpy.ndarray

ZTGeom.logpmf(x)[source]#

Natural logarithm of the probability mass function.

Parameters:

x (int) – quantile where the (natural) probability mass function logarithm is evaluated.

Returns:

natural logarithm of the probability mass function

Return type:

numpy.float64 or numpy.ndarray

ZTGeom.cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (int) – quantile where the cumulative distribution function is evaluated.

Returns:

cumulative distribution function.

Return type:

numpy.float64 or numpy.ndarray

ZTGeom.logcdf(x)[source]#

Natural logarithm of the cumulative distribution function.

Parameters:

x (int) – quantile where log of the cumulative distribution function is evaluated.

Returns:

natural logarithm of the cumulative distribution function.

Return type:

numpy.float64 or numpy.ndarray

ZTGeom.rvs(size=1, random_state=None)[source]#

Random variates generator function.

Parameters:
  • size (int, optional) – random variates sample size (default is 1).

  • random_state (int, optional) – random state for the random number generator.

Returns:

random variates.

Return type:

numpy.int or numpy.ndarray

ZTGeom.ppf(q)[source]#

Percent point function, a.k.a. the quantile function, inverse of cumulative distribution function.

Parameters:

q (float) – level at which the percent point function is evaluated.

Returns:

percent point function.

Return type:

numpy.int or numpy.ndarray

ZTGeom.mean()[source]#

Mean of the distribution.

Returns:

mean.

Return type:

numpy.float64

ZTGeom.var()[source]#

Variance of the distribution.

Returns:

variance.

Return type:

numpy.float64

ZTGeom.pgf(f)[source]#

Probability generating function. It computes the probability generating function of the random variable given the (a, b, k) parametrization.

Parameters:

f (numpy array) – point where the function is evaluated

Returns:

probability generated in f.

Return type:

numpy.ndarray

ZTGeom.abk()[source]#

Function returning (a, b, k) parametrization.

Returns:

a, b, probability in zero

Return type:

numpy.array

ZTGeom.par_deductible_adjuster(nu)[source]#

Parameter correction in case of deductible.

Parameters:

nu (float) – severity model survival function at the deductible.

Returns:

Void

Return type:

None

ZTGeom.par_deductible_reverter(nu)[source]#

Undo parameter correction in case of deductible.

Parameters:

nu (float) – severity model survival function at the deductible.

Returns:

Void

Return type:

None

ZMGeom#

class ZMGeom(**kwargs)[source]#

Bases: object

Zero-modified geometric distribution. Discrete mixture between a degenerate distribution at zero and a non-modified geometric distribution. scipy reference non-zero-modified distribution: scipy.stats._discrete_distns.geom_gen`

Parameters:

**kwargs – See below

Keyword Arguments:
  • p (numpy.float64) – Zero-modified geometric distribution probability parameter p.

  • p0m (numpy.float64) – Zero-modified geometric mixing parameter.

ZMGeom.pmf(x)[source]#

Probability mass function.

Parameters:

x (int) – quantile where probability mass function is evaluated.

Returns:

probability mass function.

Return type:

numpy.float64 or numpy.ndarray

ZMGeom.logpmf(x)[source]#

Natural logarithm of the probability mass function.

Parameters:

x (int) – quantile where the (natural) probability mass function logarithm is evaluated.

Returns:

natural logarithm of the probability mass function

Return type:

numpy.float64 or numpy.ndarray

ZMGeom.cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (int) – quantile where the cumulative distribution function is evaluated.

Returns:

cumulative distribution function.

Return type:

numpy.float64 or numpy.ndarray

ZMGeom.logcdf(x)[source]#

Natural logarithm of the cumulative distribution function.

Parameters:

x (int) – quantile where log of the cumulative distribution function is evaluated.

Returns:

natural logarithm of the cumulative distribution function.

Return type:

numpy.float64 or numpy.ndarray

ZMGeom.rvs(size=1, random_state=None)[source]#

Random variates generator function.

Parameters:
  • size (int, optional) – random variates sample size (default is 1).

  • random_state (int, optional) – random state for the random number generator.

Returns:

random variates.

Return type:

numpy.int or numpy.ndarray

ZMGeom.ppf(q)[source]#

Percent point function, a.k.a. the quantile function, inverse of cumulative distribution function.

Parameters:

q (float) – level at which the percent point function is evaluated.

Returns:

percent point function.

Return type:

numpy.int or numpy.ndarray

ZMGeom.pgf(f)[source]#

Probability generating function. It computes the probability generating function of the random variable given the (a, b, k) parametrization.

Parameters:

f (numpy array) – point where the function is evaluated

Returns:

probability generated in f.

Return type:

numpy.ndarray

ZMGeom.abk()[source]#

Function returning (a, b, k) parametrization.

Returns:

a, b, probability in zero

Return type:

numpy.array

ZMGeom.par_deductible_adjuster(nu)[source]#

Parameter correction in case of deductible.

Parameters:

nu (float) – severity model survival function at the deductible.

Returns:

Void

Return type:

None

ZMGeom.par_deductible_reverter(nu)[source]#

Undo parameter correction in case of deductible.

Parameters:

nu (float) – severity model survival function at the deductible.

Returns:

Void

Return type:

None

ZTNegBinom#

class ZTNegBinom(**kwargs)[source]#

Bases: object

Zero-truncated negative binomial distribution. Negative binomial distribution with no mass (truncated) in 0. scipy reference non-zero-truncated distribution: scipy.stats._discrete_distns.nbinom_gen.

Parameters:

**kwargs – See below

Keyword Arguments:
  • n (int) – Zero-truncated negative binomial distribution size parameter n.

  • p (numpy.float64) – Zero-truncated negative binomial distribution probability parameter p.

ZTNegBinom.pmf(x)[source]#

Probability mass function.

Parameters:

x (int) – quantile where probability mass function is evaluated.

Returns:

probability mass function.

Return type:

numpy.float64 or numpy.ndarray

ZTNegBinom.logpmf(x)[source]#

Natural logarithm of the probability mass function.

Parameters:

x (int) – quantile where the (natural) probability mass function logarithm is evaluated.

Returns:

natural logarithm of the probability mass function

Return type:

numpy.float64 or numpy.ndarray

ZTNegBinom.cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (int) – quantile where the cumulative distribution function is evaluated.

Returns:

cumulative distribution function.

Return type:

numpy.float64 or numpy.ndarray

ZTNegBinom.logcdf(x)[source]#

Natural logarithm of the cumulative distribution function.

Parameters:

x (int) – quantile where log of the cumulative distribution function is evaluated.

Returns:

natural logarithm of the cumulative distribution function.

Return type:

numpy.float64 or numpy.ndarray

ZTNegBinom.rvs(size=1, random_state=None)[source]#

Random variates generator function.

Parameters:
  • size (int, optional) – random variates sample size (default is 1).

  • random_state (int, optional) – random state for the random number generator.

Returns:

random variates.

Return type:

numpy.int or numpy.ndarray

ZTNegBinom.ppf(q)[source]#

Percent point function, a.k.a. the quantile function, inverse of cumulative distribution function.

Parameters:

q (float) – level at which the percent point function is evaluated.

Returns:

percent point function.

Return type:

numpy.int or numpy.ndarray

ZTNegBinom.mean()[source]#

Mean of the distribution.

Returns:

mean.

Return type:

numpy.float64

ZTNegBinom.var()[source]#

Variance of the distribution.

Returns:

variance.

Return type:

numpy.float64

ZTNegBinom.pgf(f)[source]#

Probability generating function. It computes the probability generating function of the random variable given the (a, b, k) parametrization.

Parameters:

f (numpy array) – point where the function is evaluated

Returns:

probability generated in f.

Return type:

numpy.ndarray

ZTNegBinom.abk()[source]#

Function returning (a, b, k) parametrization.

Returns:

a, b, probability in zero

Return type:

numpy.array

ZTNegBinom.par_deductible_adjuster(nu)[source]#

Parameter correction in case of deductible.

Parameters:

nu (float) – severity model survival function at the deductible.

Returns:

Void

Return type:

None

ZTNegBinom.par_deductible_reverter(nu)[source]#

Undo parameter correction in case of deductible.

Parameters:

nu (float) – severity model survival function at the deductible.

Returns:

Void

Return type:

None

ZMNegBinom#

class ZMNegBinom(**kwargs)[source]#

Bases: object

Zero-modified negative binomial distribution. Discrete mixture between a degenerate distribution at zero and a non-modified negative binomial distribution. scipy reference non-zero-modified distribution: scipy.stats._discrete_distns.nbinom_gen.

Parameters:

**kwargs – See below

Keyword Arguments:
  • n (int) – Zero-modified negative binomial distribution size parameter n.

  • p (numpy.float64) – Zero-modified negative binomial distribution probability parameter p.

  • p0m (numpy.float64) – Zero-modified negative binomial mixing parameter.

ZMNegBinom.pmf(x)[source]#

Probability mass function.

Parameters:

x (int) – quantile where probability mass function is evaluated.

Returns:

probability mass function.

Return type:

numpy.float64 or numpy.ndarray

ZMNegBinom.logpmf(x)[source]#

Natural logarithm of the cumulative distribution function.

Parameters:

x (int) – quantile where log of the cumulative distribution function is evaluated.

Returns:

natural logarithm of the cumulative distribution function.

Return type:

numpy.float64 or numpy.ndarray

ZMNegBinom.cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (int) – quantile where the cumulative distribution function is evaluated.

Returns:

cumulative distribution function.

Return type:

numpy.float64 or numpy.ndarray

ZMNegBinom.logcdf(x)[source]#

Natural logarithm of the cumulative distribution function.

Parameters:

x (int) – quantile where log of the cumulative distribution function is evaluated.

Returns:

natural logarithm of the cumulative distribution function.

Return type:

numpy.float64 or numpy.ndarray

ZMNegBinom.rvs(size=1, random_state=None)[source]#

Random variates generator function.

Parameters:
  • size (int, optional) – random variates sample size (default is 1).

  • random_state (int, optional) – random state for the random number generator.

Returns:

random variates.

Return type:

numpy.int or numpy.ndarray

ZMNegBinom.ppf(q)[source]#

Percent point function, a.k.a. the quantile function, inverse of cumulative distribution function.

Parameters:

q (float) – level at which the percent point function is evaluated.

Returns:

percent point function.

Return type:

numpy.int or numpy.ndarray

ZMNegBinom.pgf(f)[source]#

Probability generating function. It computes the probability generating function of the random variable given the (a, b, k) parametrization.

Parameters:

f (numpy array) – point where the function is evaluated

Returns:

probability generated in f.

Return type:

numpy.ndarray

ZMNegBinom.abk()[source]#

Function returning (a, b, k) parametrization.

Returns:

a, b, probability in zero

Return type:

numpy.array

ZMNegBinom.par_deductible_adjuster(nu)[source]#

Parameter correction in case of deductible.

Parameters:

nu (float) – severity model survival function at the deductible.

Returns:

Void

Return type:

None

ZMNegBinom.par_deductible_reverter(nu)[source]#

Undo parameter correction in case of deductible.

Parameters:

nu (float) – severity model survival function at the deductible.

Returns:

Void

Return type:

None

ZMLogser#

class ZMLogser(**kwargs)[source]#

Bases: object

Zero-modified (discrete) logarithmic (log-series) distribution. Discrete mixture between a degenerate distribution at zero and a non-modified logarithmic distribution. scipy reference non-zero-modified distribution: scipy.stats._discrete_distns.logser_gen

Parameters:

**kwargs – See below

Keyword Arguments:
  • p (numpy.float64) – ZM discrete logarithmic distribution probability parameter p.

  • p0m (numpy.float64) – ZM discrete logarithmic mixing parameter.

ZMLogser.pmf(x)[source]#

Probability mass function.

Parameters:

x (int) – quantile where probability mass function is evaluated.

Returns:

probability mass function.

Return type:

numpy.float64 or numpy.ndarray

ZMLogser.logpmf(x)[source]#

Natural logarithm of the probability mass function.

Parameters:

x (int) – quantile where the (natural) probability mass function logarithm is evaluated.

Returns:

natural logarithm of the probability mass function

Return type:

numpy.float64 or numpy.ndarray

ZMLogser.cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (int) – quantile where the cumulative distribution function is evaluated.

Returns:

cumulative distribution function.

Return type:

numpy.float64 or numpy.ndarray

ZMLogser.logcdf(x)[source]#

Natural logarithm of the cumulative distribution function.

Parameters:

x (int) – quantile where log of the cumulative distribution function is evaluated.

Returns:

natural logarithm of the cumulative distribution function.

Return type:

numpy.float64 or numpy.ndarray

ZMLogser.rvs(size=1, random_state=None)[source]#

Random variates generator function.

Parameters:
  • size (int, optional) – random variates sample size (default is 1).

  • random_state (int, optional) – random state for the random number generator.

Returns:

random variates.

Return type:

numpy.int or numpy.ndarray

ZMLogser.ppf(q)[source]#

Percent point function, a.k.a. the quantile function, inverse of cumulative distribution function.

Parameters:

q (float) – level at which the percent point function is evaluated.

Returns:

percent point function.

Return type:

numpy.int or numpy.ndarray

ZMLogser.abk()[source]#

Function returning (a, b, k) parametrization.

Returns:

a, b, probability in zero

Return type:

numpy.array

ZMLogser.par_deductible_adjuster(nu)[source]#

Parameter correction in case of deductible.

Parameters:

nu (float) – severity model survival function at the deductible.

Returns:

Void

Return type:

None

ZMLogser.par_deductible_reverter(nu)[source]#

Undo parameter correction in case of deductible.

Parameters:

nu (float) – severity model survival function at the deductible.

Returns:

Void

Return type:

None

Severity distributions#

Beta#

class Beta(loc=0, scale=1, **kwargs)[source]#

Bases: _ContinuousDistribution

Wrapper to scipy beta distribution. scipy.stats._continuous_distns.beta_gen

Parameters:
  • scale (float) – beta scale parameter.

  • loc (float) – beta location parameter.

  • **kwargs – See below

Keyword Arguments:
  • a (int or float) – shape parameter a.

  • b (int or float) – shape parameter b.

Beta.lev(v)[source]#

Limited expected value, i.e. expected value of the function min(x, v).

Parameters:

v (numpy.float or numpy.ndarray) – values with respect to the minimum.

Returns:

expected value of the minimum function.

Return type:

numpy.float or numpy.ndarray

Exponential#

class Exponential(loc=0, theta=1)[source]#

Bases: _ContinuousDistribution

Expontential distribution. scipy reference distribution: scipy.stats._continuous_distns.expon_gen

Parameters:
  • theta (float) – exponential distribution theta parameter.

  • loc (float) – location parameter

Exponential.pdf(x)[source]#

Probability density function.

Parameters:

x (numpy.ndarray, list, float, int) – quantile where probability density function is evaluated.

Returns:

probability density function

Return type:

numpy.float64 or numpy.ndarray

Exponential.logpdf(x)[source]#

Natural logarithm of the probability density function.

Parameters:

x (numpy.ndarray) – the log of the probability function will be computed in x.

Returns:

logpdf

Return type:

numpy.float64 or numpy.ndarray

Exponential.cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (numpy.ndarray) – the cumulative distribution function will be computed in x.

Returns:

cumulative distribution function

Return type:

numpy.float64 or numpy.ndarray

Exponential.logcdf(x)[source]#

Natural logarithm of the cumulative distribution function.

Parameters:

x (int) – point where the natural logarithm of the cumulative distribution function is evaluated.

Returns:

natural logarithm of the cumulative distribution function

Return type:

numpy.float64 or numpy.ndarray

Exponential.sf(x)[source]#

Survival function, 1 - cumulative distribution function.

Parameters:

x (int) – point where the survival is evaluated.

Returns:

survival function

Return type:

numpy.float64 or numpy.ndarray

Exponential.logsf(x)[source]#

Natural logarithm of the survival function.

Parameters:

x (int) – point where the natural logarithm of the survival function is evaluated.

Returns:

natural logarithm of the survival function

Return type:

numpy.float64 or numpy.ndarray

Exponential.isf(x)[source]#

Inverse survival function (inverse of sf).

Parameters:

x (numpy.ndarray) – point where the inverse of the survival function is evaluated.

Returns:

inverse of the survival function

Return type:

numpy.float64 or numpy.ndarray

Exponential.rvs(size=1, random_state=None)[source]#

Random variates.

Parameters:
  • size (int) – random variates sample size (default is 1).

  • random_state (int) – random state for the random number generator.

Returns:

Random variates.

Return type:

numpy.float64 or numpy.ndarray

Exponential.entropy()[source]#

(Differential) entropy of the RV.

Returns:

(differential) entropy.

Return type:

numpy.float64

Exponential.mean()[source]#

Mean of the distribution.

Returns:

mean.

Return type:

numpy.float64

Exponential.var()[source]#

Variance of the distribution.

Returns:

variance.

Return type:

numpy.float64

Exponential.std()[source]#

Standard deviation of the distribution.

Returns:

standard deviation.

Return type:

numpy.float64

Exponential.ppf(q)[source]#

Percent point function, a.k.a. the quantile function, inverse of the cumulative distribution function.

Parameters:

q (float) – level at which the percent point function is evaluated.

Returns:

percent point function.

Return type:

numpy.float64 or numpy.int or numpy.ndarray

Exponential.lev(v)[source]#

Limited expected value, i.e. expected value of the function min(x, v).

Parameters:

v (numpy.float or numpy.ndarray) – values with respect to the minimum.

Returns:

expected value of the minimum function.

Return type:

numpy.float or numpy.ndarray

Exponential.partial_moment(n, low, up)[source]#

Partial moment of order n.

Parameters:
  • n (int) – moment order.

  • low (int, float) – lower limit of the partial moment.

  • up (int, float) – upper limit of the partial moment.

Returns:

raw partial moment of order n.

Return type:

float

Gamma#

class Gamma(loc=0, scale=1.0, **kwargs)[source]#

Bases: _ContinuousDistribution

Gamma distribution. When a is an integer it reduces to an Erlang distribution. When a=1 it reduces to an Exponential distribution. Wrapper to scipy gamma distribution ( scipy.stats._continuous_distns.gamma_gen ).

Parameters:
  • scale (float) – scale parameter (inverse of the rate parameter).

  • loc (float) – location parameter.

  • **kwargs – See below

Keyword Arguments:
  • a (int or float) – shape parameter a.

Gamma.lev(v)[source]#

Limited expected value, i.e. expected value of the function min(x, v).

Parameters:

v (numpy.float or numpy.ndarray) – values with respect to the minimum.

Returns:

expected value of the minimum function.

Return type:

numpy.float or numpy.ndarray

Gamma.partial_moment(n, low, up)[source]#

Partial moment of order n.

Parameters:
  • n (int) – moment order.

  • low (int, float) – lower limit of the partial moment.

  • up (int, float) – upper limit of the partial moment.

Returns:

raw partial moment of order n.

Return type:

float

InvGamma#

class InvGamma(loc=0, scale=1, **kwargs)[source]#

Bases: _ContinuousDistribution

Wrapper to scipy inverse gamma distribution. scipy.stats._continuous_distns.invgamma_gen object

Parameters:
  • scale (float) – scale parameter.

  • loc (float) – location parameter.

  • **kwargs – See below

Keyword Arguments:
  • a (int or float) – shape parameter a.

InvGamma.lev(v)[source]#

Limited expected value, i.e. expected value of the function min(x, v).

Parameters:

v (numpy.float or numpy.ndarray) – values with respect to the minimum.

Returns:

expected value of the minimum function.

Return type:

numpy.float or numpy.ndarray

GenPareto#

class GenPareto(loc=0, scale=1.0, **kwargs)[source]#

Bases: _ContinuousDistribution

Wrapper to scipy genpareto distribution. When c (i.e. shape) = 0, it reduces to an Exponential distribution. When c (i.e. shape) = -1, it reduces to a uniform distribution. When the correct parametrization is adopted, it is possible to fit all the Pareto types. scipy reference distribution: scipy.stats._continuous_distns.genpareto_gen .

Parameters:
  • scale (float) – scale parameter.

  • loc (float) – location parameter.

  • **kwargs – See below

Keyword Arguments:
  • c (int or float) – shape parameter.

GenPareto.lev(v)[source]#

Limited expected value, i.e. expected value of the function min(x, v).

Parameters:

v (numpy.float or numpy.ndarray) – values with respect to the minimum.

Returns:

expected value of the minimum function.

Return type:

numpy.float or numpy.ndarray

Pareto2#

class Pareto2(min=0, scale=1, **kwargs)[source]#

Bases: GenPareto

Pareto TypeII distribution. This is a Genpareto distribution with parameter loc = min; scale = scale/shape and c = 1/shape. See scipy.stats._continuous_distns.genpareto.

Parameters:
  • min (float) – location parameter.

  • scale (float) – scale parameter.

  • **kwargs – See below

Keyword Arguments:
  • shape (int or float) –

    shape parameter.

Pareto1#

class Pareto1(min=0, **kwargs)[source]#

Bases: Pareto2

Single-parameter Pareto distribution. This is a Pareto II distribution with parameter scale = min. scipy.stats._continuous_distns.genpareto

Parameters:
  • min (float) – pareto 1 location parameter.

  • **kwargs – See below

Keyword Arguments:
  • shape (int or float) –

    shape parameter.

Lognormal#

class Lognormal(scale=1.0, **kwargs)[source]#

Bases: _ContinuousDistribution

Lognormal distribution. The more common parametrization lognormal(mu, sigma), where mu and sigma are the parameter of the underlying Normal distribution, is equivalent to lognormal(log(scale), shape). scipy reference distribution: scipy.stats._continuous_distns.lognorm_gen

Parameters:
  • scale (float) – lognormal scale parameter. The natural logarithm of scale is the mean of the underlying Normal distribution.

  • **kwargs – See below

Keyword Arguments:
  • shape (int or float) – shape parameter. It corresponds to the standard deviation of the underlying Normal distribution.

Lognormal.lev(v)[source]#

Limited expected value, i.e. expected value of the function min(x, v).

Parameters:

v (numpy.float or numpy.ndarray) – values with respect to the minimum.

Returns:

expected value of the minimum function.

Return type:

numpy.float or numpy.ndarray

Lognormal.partial_moment(n, low, up)[source]#

Partial moment of order n.

Parameters:
  • n (int) – moment order.

  • low (int, float) – lower limit of the partial moment.

  • up (int, float) – upper limit of the partial moment.

Returns:

raw partial moment of order n.

Return type:

float

GenBeta#

class GenBeta(shape1, shape2, shape3, scale=1.0)[source]#

Bases: object

Generalized Beta (GB) distribution, also refer to as Generalized Beta of the second kind, or the Generalized Beta Prime distribution. If X is a GB distributed r.v., its cumulative distribution function can be expressed as:

Pr[X <= x] = Pr[Y <= (x/scale)^shape3], 0 < x < scale,

where Y has a Beta distribution, with parameters shape1 and shape2. Refer to Appendix A of Klugman, Panjer & Willmot, Loss Models, Wiley.

GenBeta.rvs(size=1, random_state=None)[source]#

Random variates.

Parameters:
  • size (int) – random variates sample size (default is 1).

  • random_state (int) – random state for the random number generator.

Returns:

Random variates.

Return type:

numpy.float64 or numpy.ndarray

GenBeta.pdf(x)[source]#

Probability density function.

Parameters:

x (numpy.ndarray, list, float, int) – quantile where probability density function is evaluated.

Returns:

probability density function in x.

Return type:

numpy.float64 or numpy.ndarray

GenBeta.cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (float) – cumulative distribution function will be computed in x.

Returns:

cumulative distribution function in x.

Return type:

numpy.float64 or numpy.ndarray

GenBeta.logpdf(x)[source]#

Natural logarithm of the probability distribution function.

Parameters:

x (float) – natural logarithm of the probability distribution function computed in x.

Returns:

natural logarithm of the probability distribution function computed in x.

Return type:

numpy.float64 or numpy.ndarray

GenBeta.logcdf(x)[source]#

Natural logarithm of the cumulative distribution function.

Parameters:

x (float) – natural logarithm of the cumulative distribution function computed in x.

Returns:

natural logarithm of the cumulative distribution function in x.

Return type:

numpy.float64 or numpy.ndarray

GenBeta.sf(x)[source]#

Survival function, 1 - cumulative distribution function.

Parameters:

x (float) – survival function will be computed in x.

Returns:

survival function in x

Return type:

numpy.float64 or numpy.ndarray

GenBeta.logsf(x)[source]#

Natural logarithm of the survival function.

Parameters:

x (float) – natural logarithm of the survival function computed in x.

Returns:

natural logarithm of the survival function in x

Return type:

numpy.float64 or numpy.ndarray

GenBeta.ppf(q)[source]#

Percent point function, a.k.a. the quantile function, inverse of cumulative distribution function.

Parameters:

q (float) – level at which the percent point function is evaluated.

Returns:

percent point function.

Return type:

numpy.float64 or numpy.int or numpy.ndarray

GenBeta.isf(q)[source]#

Inverse survival function (inverse of sf).

Parameters:

q – Inverse survival function computed in q.

Returns:

inverse sf

Return type:

numpy.float64 or numpy.ndarray

GenBeta.moment(n)[source]#

Non-central moment of order n.

Parameters:

n (int) – moment order.

Returns:

raw moment of order n.

Return type:

float

GenBeta.stats(moments='mv')[source]#

Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’).

Parameters:

moments – moments to be returned.

Returns:

moments.

Return type:

tuple

GenBeta.median()[source]#

Median of the distribution.

Returns:

median

Return type:

numpy.float64

GenBeta.mean()[source]#

Mean of the distribution.

Returns:

mean.

Return type:

numpy.float64

GenBeta.var()[source]#

Variance of the distribution.

Returns:

variance.

Return type:

numpy.float64

GenBeta.std()[source]#

Standard deviation of the distribution.

Returns:

standard deviation.

Return type:

numpy.float64

GenBeta.skewness()[source]#

Skewness (third standardized moment).

Returns:

skewness.

Return type:

float

GenBeta.kurtosis()[source]#

Excess kurtosis.

Returns:

Excess kurtosis.

Return type:

float

GenBeta.lev(v)[source]#

Limited expected value, i.e. expected value of the function min(x, v).

Parameters:

v (numpy.float or numpy.ndarray) – values with respect to the minimum.

Returns:

expected value of the minimum function.

Return type:

numpy.float or numpy.ndarray

GenBeta.censored_moment(n, d, c)[source]#

Non-central moment of order n of the transformed random variable min(max(x - d, 0), c). When n = 1 it is the so-called stop loss transformation function.

Parameters:
  • d (int, float) – deductible, or attachment point.

  • c (int, float) – cover, deductible + cover is the detachment point.

  • n (int) – moment order.

Returns:

raw moment of order n.

Return type:

float

GenBeta.partial_moment(n, low, up)[source]#

Non-central partial moment of order n.

Parameters:
  • n (int) – moment order.

  • low (int, float) – lower limit of the partial moment.

  • up (int, float) – upper limit of the partial moment.

Returns:

raw partial moment of order n.

Return type:

float

GenBeta.truncated_moment(n, low, up)[source]#

Non-central truncated moment of order n.

Parameters:
  • n (int) – moment order.

  • low (int, float) – lower truncation point.

  • up (int, float) – upper truncation point.

Returns:

raw truncated moment of order n.

Return type:

float

Burr12#

class Burr12(loc=0, scale=1, **kwargs)[source]#

Bases: _ContinuousDistribution

Burr distribution, also referred to as the Burr Type XII, Singh–Maddala distribution. When d=1, this is a Fisk distribution. When c=d, this is a Paralogistic distribution. scipy reference distribution: scipy.stats._continuous_distns.burr_gen object

Parameters:
  • scale (float) – burr scale parameter.

  • loc (float) – burr location parameter.

  • **kwargs – See below

Keyword Arguments:
  • c (int or float) – shape parameter c.

  • d (int or float) – shape parameter d.

Burr12.lev(v)[source]#

Limited expected value, i.e. expected value of the function min(x, v).

Parameters:

v (numpy.float or numpy.ndarray) – values with respect to the minimum.

Returns:

expected value of the minimum function.

Return type:

numpy.float or numpy.ndarray

Paralogistic#

class Paralogistic(loc=0, scale=1, **kwargs)[source]#

Bases: Burr12

Paralogistic distribution. This is a Burr12 distribution with same parameters. scipy.stats._continuous_distns.burr12

Parameters:
  • scale (float) – paralogistic scale parameter.

  • loc (float) – paralogistic location parameter.

  • **kwargs – See below

Keyword Arguments:
  • a (int or float) – distribution parameter a.

Dagum#

class Dagum(loc=0, scale=1, **kwargs)[source]#

Bases: _ContinuousDistribution

Wrapper to scipy mielke distribution. It is referred to the Inverse Burr, Mielke Beta-Kappa. When d=s, this is an inverse paralogistic. scipy.stats._continuous_distns.mielke

Parameters:
  • scale (float) – dagum scale parameter.

  • loc (float) – dagum location parameter.

  • **kwargs – See below

Keyword Arguments:
  • d (int or float) – shape parameter d.

  • s (int or float) – shape parameter s.

Dagum.lev(v)[source]#

Limited expected value, i.e. expected value of the function min(x, v).

Parameters:

v (numpy.float or numpy.ndarray) – values with respect to the minimum.

Returns:

expected value of the minimum function.

Return type:

numpy.float or numpy.ndarray

InvParalogistic#

class InvParalogistic(loc=0, scale=1, **kwargs)[source]#

Bases: Dagum

Inverse paralogistic distribution. This is a Dagum distribution with same parameters. scipy.stats._continuous_distns.mielke

Parameters:
  • scale (float) – inverse paralogistic scale parameter.

  • loc (float) – inverse paralogistic location parameter.

  • **kwargs – See below

Keyword Arguments:
  • b (int or float) –

    distribution parameter b.

Weibull#

class Weibull(loc=0, scale=1, **kwargs)[source]#

Bases: _ContinuousDistribution

Wrapper to scipy Weibull (Weibull_min) distribution. scipy.stats._continuous_distns.weibull_min_gen object

Parameters:
  • scale (float) – scale parameter.

  • loc (float) – location parameter.

  • **kwargs – See below

Keyword Arguments:
  • c (int or float) – shape parameter c.

Weibull.lev(v)[source]#

Limited expected value, i.e. expected value of the function min(x, v).

Parameters:

v (numpy.float or numpy.ndarray) – values with respect to the minimum.

Returns:

expected value of the minimum function.

Return type:

numpy.float or numpy.ndarray

InvWeibull#

class InvWeibull(loc=0, scale=1, **kwargs)[source]#

Bases: _ContinuousDistribution

Wrapper to scipy inverse Weibull distribution. scipy.stats._continuous_distns.invweibull_gen object

Parameters:
  • scale (float) – scale parameter.

  • loc (float) – location parameter.

  • **kwargs – See below

Keyword Arguments:
  • c (int or float) – shape parameter c.

InvWeibull.lev(v)[source]#

Limited expected value, i.e. expected value of the function min(x, v).

Parameters:

v (numpy.float or numpy.ndarray) – values with respect to the minimum.

Returns:

expected value of the minimum function.

Return type:

numpy.float or numpy.ndarray

InvGauss#

class InvGauss(loc=0.0, scale=1.0, **kwargs)[source]#

Bases: _ContinuousDistribution

Wrapper to scipy inverse gaussian distribution. scipy.stats._continuous_distns.invgauss_gen object

Parameters:
  • scale (float) – scale parameter.

  • loc (float) – location parameter.

  • **kwargs – See below

Keyword Arguments:
  • mu (int or float) – shape parameter mu.

InvGauss.lev(v)[source]#

Limited expected value, i.e. expected value of the function min(x, v).

Parameters:

v (numpy.float or numpy.ndarray) – values with respect to the minimum.

Returns:

expected value of the minimum function.

Return type:

numpy.float or numpy.ndarray

Fisk#

class Fisk(loc=0.0, scale=1.0, **kwargs)[source]#

Bases: _ContinuousDistribution

Wrapper to scipy Fisk distribution. scipy.stats._continuous_distns.fisk_gen object

Parameters:
  • scale (float) – scale parameter.

  • loc (float) – location parameter.

  • **kwargs – See below

Keyword Arguments:
  • c (int or float) – shape parameter c.

Fisk.lev(v)[source]#

Limited expected value, i.e. expected value of the function min(x, v).

Parameters:

v (numpy.float or numpy.ndarray) – values with respect to the minimum.

Returns:

expected value of the minimum function.

Return type:

numpy.float or numpy.ndarray

LogGamma#

class LogGamma(scale=1.0, **kwargs)[source]#

Bases: object

Log Gamma distribution. Random variable whose logarithm transformation is Gamma distributed. Parameters (a and scale) refer to the underlying log-transformed random variable. Remark: distribution form and parametrization differ from <scipy.stats._continuous_distns.loggamma_gen object>

Parameters:
  • scale (float) – scale parameter (inverse of the rate parameter).

  • **kwargs – See below

Keyword Arguments:
  • a (int or float) – shape parameter a.

LogGamma.pdf(x)[source]#

Probability density function.

Parameters:

x (numpy.ndarray, list, float, int) – quantile where probability density function is evaluated.

Returns:

probability mass function.

Return type:

numpy.float64 or numpy.ndarray

LogGamma.cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (int or float) – quantile where the cumulative distribution function is evaluated.

Returns:

cumulative distribution function.

Return type:

numpy.float64 or numpy.ndarray

LogGamma.sf(x)[source]#

Survival function, 1 - cumulative distribution function.

Parameters:

x (int or float) – quantile where the survival function is evaluated.

Returns:

survival function

Return type:

numpy.float64 or numpy.ndarray

LogGamma.ppf(q)[source]#

Percent point function, a.k.a. the quantile function, inverse of the cumulative distribution function.

Parameters:

q (float) – level at which the percent point function is evaluated.

Returns:

percent point function.

Return type:

numpy.float64 or numpy.int or numpy.ndarray

LogGamma.rvs(size=1, random_state=None)[source]#

Random variates.

Parameters:
  • size (int) – random variates sample size (default is 1).

  • random_state (int) – random state for the random number generator.

Returns:

Random variates.

Return type:

numpy.float64 or numpy.ndarray

LogGamma.moment(n)[source]#

Non-central moment of order n.

Parameters:

n (int) – moment order.

Returns:

raw moment of order n.

Return type:

float

LogGamma.mean()[source]#

Mean of the distribution.

Returns:

mean.

Return type:

float

LogGamma.var()[source]#

Variance of the distribution.

Returns:

variance.

Return type:

float

LogGamma.std()[source]#

Standard deviation of the distribution.

Returns:

standard deviation.

Return type:

float

LogGamma.logpdf(x)[source]#

Natural logarithm of the probability distribution function.

Parameters:

x (float) – natural logarithm of the probability distribution function computed in x.

Returns:

natural logarithm of the probability distribution function computed in x.

Return type:

numpy.float64 or numpy.ndarray

LogGamma.logcdf(x)[source]#

Natural logarithm of the cumulative distribution function.

Parameters:

x (float) – natural logarithm of the cumulative distribution function computed in x.

Returns:

natural logarithm of the cumulative distribution function in x.

Return type:

numpy.float64 or numpy.ndarray

LogGamma.logsf(x)[source]#

Natural logarithm of the survival function.

Parameters:

x (float) – natural logarithm of the survival function computed in x.

Returns:

natural logarithm of the survival function in x

Return type:

numpy.float64 or numpy.ndarray

LogGamma.isf(q)[source]#

Inverse survival function (inverse of sf).

Parameters:

q – Inverse survival function computed in q.

Returns:

inverse sf

Return type:

numpy.float64 or numpy.ndarray

LogGamma.stats(moments='mv')[source]#

Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’).

Parameters:

moments – moments to be returned.

Returns:

moments.

Return type:

tuple

LogGamma.median()[source]#

Median of the distribution.

Returns:

median

Return type:

numpy.float64

LogGamma.skewness()[source]#

Skewness (third standardized moment).

Returns:

skewness.

Return type:

float

LogGamma.kurtosis()[source]#

Excess kurtosis.

Returns:

Excess kurtosis.

Return type:

float

LogGamma.lev(v)[source]#

Limited expected value, i.e. expected value of the function min(x, v).

Parameters:

v (numpy.float or numpy.ndarray) – values with respect to the minimum.

Returns:

expected value of the minimum function.

Return type:

numpy.float or numpy.ndarray

LogGamma.censored_moment(n, d, c)[source]#

Non-central moment of order n of the transformed random variable min(max(x - d, 0), c). When n = 1 it is the so-called stop loss transformation function.

Parameters:
  • d (int, float) – deductible, or attachment point.

  • c (int, float) – cover, deductible + cover is the detachment point.

  • n (int) – moment order.

Returns:

raw moment of order n.

Return type:

float

LogGamma.partial_moment(n, low, up)[source]#

Non-central partial moment of order n.

Parameters:
  • n (int) – moment order.

  • low (int, float) – lower limit of the partial moment.

  • up (int, float) – upper limit of the partial moment.

Returns:

raw partial moment of order n.

Return type:

float

LogGamma.truncated_moment(n, low, up)[source]#

Non-central truncated moment of order n.

Parameters:
  • n (int) – moment order.

  • low (int, float) – lower truncation point.

  • up (int, float) – upper truncation point.

Returns:

raw truncated moment of order n.

Return type:

float

Uniform#

class Uniform(a=0, b=1)[source]#

Bases: Beta

Uniform continuous distribution over interval [a, b].

Parameters:
  • a (float or int) – lower bound.

  • b (float or int) – upper bound.

Empirical and piecewise distributions#

PWL#

class PWL(points, cumprobs)[source]#

Bases: object

Piecewise-linear distribution (a.k.a. mixture of continguous uniform distribution). Distribution specified by a set of points which are delimiting the intervals and a set of cumulative probabilities (associated to the intervals). Between two consecutive points, the random variable is uniformly distributed. Points must be non negatives.

Parameters:
  • points (list or np.ndarray of int or float) – limit points of the bins of the distribution. At least the two points where cumulative probabilities are 0 and 1 needs to be provided. Its length must match cumprobs one.

  • cumprobs (list or np.ndarray of int or float) – cumulative probabilities associated to the points. At least cumulative probabilities of 0 and 1 needs to be provided. Its length must match points one.

PWL.cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (int or float) – quantile where the cumulative distribution function is evaluated.

Returns:

cumulative distribution function.

Return type:

numpy.float64 or numpy.ndarray

PWL.pdf(x)[source]#

Probability density function.

Parameters:

x (numpy.ndarray, list, float, int) – quantile where probability density function is evaluated.

Returns:

probability mass function.

Return type:

numpy.float64 or numpy.ndarray

PWL.ppf(q)[source]#

Percent point function, a.k.a. the quantile function, inverse of the cumulative distribution function.

Parameters:

q (float) – level at which the percent point function is evaluated.

Returns:

percent point function.

Return type:

numpy.float64 or numpy.int or numpy.ndarray

PWL.rvs(size=1, random_state=None)[source]#

Random variates generator function.

Parameters:
  • size (int, optional) – random variates sample size (default is 1).

  • random_state (int, optional) – random state for the random number generator (default=None).

Returns:

random variates.

Return type:

numpy.int or numpy.ndarray

PWL.sf(x)[source]#

Survival function, 1 - cumulative distribution function.

Parameters:

x (int or float) – quantile where the survival function is evaluated.

Returns:

survival function

Return type:

numpy.float64 or numpy.ndarray

PWL.moment(n=1, central=False)[source]#

Moment of order n.

Parameters:
  • central (bool) – True if the moment is central, False if the moment is raw.

  • n (int) – moment order.

Returns:

moment of order n.

Return type:

float

PWL.mean()[source]#

Mean of the distribution.

Returns:

mean.

Return type:

float

PWL.var()[source]#

Standard deviation of the distribution.

Returns:

standard deviation.

Return type:

float

PWL.std()[source]#

Standard deviation of the distribution.

Returns:

standard deviation.

Return type:

float

PWL.skewness()[source]#

Skewness.

Returns:

skewness.

Return type:

numpy.float64

PWL.kurtosis(excess=False)[source]#

Kurtosis. If excess is True, the excess of kurtosis (Fisher’s definition) is calculated, i.e. 3.0 is subtracted from the raw result to give 0.0 for a normal distribution.

Parameters:

excess (bool) – True if excess of kurtosis, False otherwise.

Returns:

kurtosis.

Return type:

numpy.float64

PWL.censored_moment(n, d, c)[source]#

Non-central moment of order n of the transformed random variable min(max(x - u, 0), v). When n = 1 it is the so-called stop loss transformation function.

Parameters:
  • d (int, float) – deductible, or attachment point.

  • c (int, float) – cover, deductible + cover is the detachment point.

  • n (int) – moment order.

Returns:

raw moment of order n.

Return type:

float

PWL.lev(v)[source]#

Limited expected value, i.e. expected value of the function min(x, v).

Parameters:

v (numpy.float or numpy.ndarray) – values with respect to the minimum.

Returns:

expected value of the minimum function.

Return type:

numpy.float or numpy.ndarray

PWC#

class PWC(nodes, cumprobs, legit=True)[source]#

Bases: object

Piecewise-constant distribution (a.k.a. empirical cumulative distribution). Distribution specified by a set of nodes and a set of cumulative probabilities (associated to the nodes). Nodes must be non negatives.

Parameters:
  • nodes (list or np.ndarray of int or float) – nodes of the distribution. Its length must match cumprobs one.

  • cumprobs (list or np.ndarray of int or float) – cumulative probabilities associated to the nodes. Its length must match nodes one.

  • legit (bool) – boolean. If True (default) the distribution must be a legitimate probability, i.e. last cumprobs value equal to 1.

PWC.cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (int or float) – quantile where the cumulative distribution function is evaluated.

Returns:

cumulative distribution function.

Return type:

numpy.float64 or numpy.ndarray

PWC.ppf(q)[source]#

Percent point function, a.k.a. the quantile function, inverse of the cumulative distribution function.

Parameters:

q (float) – level at which the percent point function is evaluated.

Returns:

percent point function.

Return type:

numpy.float64 or numpy.int or numpy.ndarray

PWC.rvs(size=1, random_state=None)[source]#

Random variates generator function.

Parameters:
  • size (int, optional) – random variates sample size (default is 1).

  • random_state (int, optional) – random state for the random number generator (default=None).

Returns:

random variates.

Return type:

numpy.int or numpy.ndarray

PWC.sf(x)[source]#

Survival function, 1 - cumulative distribution function.

Parameters:

x (int or float) – quantile where the survival function is evaluated.

Returns:

survival function

Return type:

numpy.float64 or numpy.ndarray

PWC.moment(central=False, n=1)[source]#

Moment of order n.

Parameters:
  • central (bool) – True if the moment is central, False if the moment is raw.

  • n (int) – moment order.

Returns:

moment of order n.

Return type:

float

PWC.mean()[source]#

Mean of the distribution.

Returns:

mean.

Return type:

float

PWC.var()[source]#

Standard deviation of the distribution.

Returns:

standard deviation.

Return type:

float

PWC.std()[source]#

Standard deviation of the distribution.

Returns:

standard deviation.

Return type:

float

PWC.skewness()[source]#

Skewness.

Returns:

skewness.

Return type:

numpy.float64

PWC.kurtosis(excess=False)[source]#

Kurtosis. If excess is True, the excess of kurtosis (Fisher’s definition) is calculated, i.e. 3.0 is subtracted from the raw result to give 0.0 for a normal distribution.

Parameters:

excess (bool) – True if excess of kurtosis, False otherwise.

Returns:

kurtosis.

Return type:

numpy.float64

PWC.censored_moment(n, d, c)[source]#

Non-central moment of order n of the transformed random variable min(max(x - u, 0), v). When n = 1 it is the so-called stop loss transformation function.

Parameters:
  • d (int, float) – deductible, or attachment point.

  • c (int, float) – cover, deductible + cover is the detachment point.

  • n (int) – moment order.

Returns:

raw moment of order n.

Return type:

float

PWC.lev(v)[source]#

Limited expected value, i.e. expected value of the function min(x, v).

Parameters:

v (numpy.float or numpy.ndarray) – values with respect to the minimum.

Returns:

expected value of the minimum function.

Return type:

numpy.float or numpy.ndarray

Multivariate distributions#

Multinomial#

class Multinomial(loc=0, seed=None, **kwargs)[source]#

Bases: _MultDiscreteDistribution

Multinomial distribution. Wrapper to scipy multinomial distribution (scipy.stats._multivariate.multinomial). Refer to :py:class:’~__MultDiscreteDistribution’ for additional details.

Parameters:
  • loc (int, optional) – location parameter (default=0), to shift the support of the distribution.

  • seed (int) – Used to set a specific seed (default=np.random.RandomState).

  • **kwargs – See below

Keyword Arguments:
  • n (int) – Number of trials.

  • p (float) – Probability of a success, parameter of each marginal distribution.

Multinomial.cov()[source]#

Covariance Matrix of a Multinomial Distribution. :return: Covariance Matrix. :rtype: float

Multinomial.var()[source]#

Variances of a Multinomial Distribution.

Returns:

Array of Variances.

Return type:

numpy.ndarray

Multinomial.entropy()[source]#

(Differential) entropy of the Multinomial distribution

Returns:

entropy

Return type:

numpy.ndarray

Multinomial.pmf(x)[source]#

Probability mass function of the Multinomial distribution

Parameters:

x (int) – quantile where probability mass function is evaluated.

Returns:

probability mass function.

Return type:

numpy.float64 or numpy.ndarray

Multinomial.logpmf(x)[source]#

Natural logarithm of the probability mass function of the Multinomial distribution

Parameters:

x (int) – quantile where the (natural) probability mass function logarithm is evaluated.

Returns:

natural logarithm of the probability mass function

Return type:

numpy.float64 or numpy.ndarray

Dirichlet_Multinomial#

class Dirichlet_Multinomial(seed=None, **kwargs)[source]#

Bases: _MultDiscreteDistribution

Dirichlet Multinomial distribution. Wrapper to scipy dirichlet multinomial distribution (scipy.stats.dirichlet_multinomial). Refer to :py:class:’~__MultDiscreteDistribution’ for additional details.

Parameters:
  • seed (int) – Used to set a specific seed (default=np.random.RandomState).

  • **kwargs – See below

Keyword Arguments:
  • alpha ( int or numpy.ndarray) – Concentration parameters.

  • n (int) – Number of trials.

Dirichlet_Multinomial.cov()[source]#

Covariance Matrix of a Dirichlet Multinomial Distribution.

Returns:

Covariance Matrix.

Return type:

float

Dirichlet_Multinomial.var()[source]#

Variances of a Dirichlet Multinomial Distribution.

Returns:

Array of Variances.

Return type:

numpy.ndarray

Dirichlet_Multinomial.pmf(x)[source]#

Probability mass function of the Dirichlet Multinomial Distribution.

Parameters:

x (int) – quantile where probability mass function is evaluated.

Returns:

probability mass function.

Return type:

numpy.float64 or numpy.ndarray

Dirichlet_Multinomial.logpmf(x)[source]#

Natural logarithm of the probability mass function of the Dirichlet Multinomial Distribution.

Parameters:

x (int) – quantile where the (natural) probability mass function logarithm is evaluated.

Returns:

natural logarithm of the probability mass function

Return type:

numpy.float64 or numpy.ndarray

Dirichlet_Multinomial.mean()[source]#

Mean of the Dirichlet Multinomial Distribution.

Parameters:

x (int) – quantile where the (natural) probability mass function logarithm is evaluated.

Returns:

natural logarithm of the probability mass function

Return type:

numpy.float64 or numpy.ndarray

Dirichlet_Multinomial.rvs(size=1, random_state=None)[source]#

Random variates generator function.

Parameters:
  • size (int, optional) – random variates sample size (default is 1).

  • random_state (int, optional) – random state for the random number generator.

Returns:

random variates.

Return type:

numpy.int or numpy.ndarray

NegMultinom#

class NegMultinom(x0, p, loc=0)[source]#

Bases: _MultDiscreteDistribution

Negative Multinomial distribution.

Parameters:
  • loc (int, optional) – Location parameter to shift the support (default=0).

  • **kwargs – See below

Keyword Arguments:
  • x0 (int) – Size parameter of the negative multinomial distribution.

  • p (float) – Probability parameter of the negative multinomial distribution.

NegMultinom.pmf(x)[source]#

Probability mass function.

PMF formula from reference: Γ(∑x_i) * p0^x0 / Γ(x0) * ∏(p_i^x_i / x_i!)

Parameters:

x (numpy.ndarray) – Quantile where PMF is evaluated.

Returns:

Probability mass function evaluated at x.

Return type:

numpy.float64

NegMultinom.logpmf(x)[source]#

Natural logarithm of the probability mass function.

Parameters:

x (numpy.ndarray) – Quantile where log-PMF is evaluated.

Returns:

Log of probability mass function evaluated at x.

Return type:

numpy.float64

NegMultinom.mean()[source]#

Mean vector of the distribution.

Returns:

Mean vector.

Return type:

numpy.ndarray

NegMultinom.var()[source]#

Variances of a Negative Multinomial Distribution.

Returns:

Array of Variances.

Return type:

numpy.ndarray

NegMultinom.cov()[source]#

Covariance matrix of a Negative Multinomial Distribution.

Returns:

Covariance matrix.

Return type:

numpy.ndarray

NegMultinom.rvs(size=1, random_state=None)[source]#

Random variates generator function.

Parameters:
  • size (int) – Number of random variates to generate (default=1).

  • random_state (int, optional) – Random state for reproducibility.

Returns:

Random variates.

Return type:

numpy.ndarray

NegMultinom.mgf(t)[source]#

Moment generating function.

Parameters:

t (numpy.ndarray) – Vector where MGF is evaluated.

Returns:

Moment generating function evaluated at t.

Return type:

numpy.float64

MultivariateBinomial#

class MultivariateBinomial(**kwargs)[source]#

Bases: object

Multivariate Binomial distribution. Implementation from “Multivariate Binomial and Poisson Distribution”, A.S. Krishnamoorthy, 2013

Parameters:

**kwargs – See below

Keyword Arguments:
  • n (int) – Number of trials.

  • p_joint (numpy.ndarray) – Joint probability matrix where p_joint[i,j] = P(Xi=1,Xj=1)

MultivariateBinomial.pmf(x)[source]#

Probability mass function.

Uses G-polynomial expansion for dependence correction.

Parameters:

x (numpy.ndarray) – Quantile where PMF is evaluated.

Returns:

Probability mass function evaluated at x.

Return type:

numpy.float64

MultivariateBinomial.mean()[source]#

Mean vector of the distribution.

Returns:

Mean vector.

Return type:

numpy.ndarray

MultivariateBinomial.cov()[source]#

Covariance matrix of the distribution.

Returns:

Covariance matrix.

Return type:

numpy.ndarray

MultivariateBinomial.var()[source]#

Variance.

Returns:

Variance array.

Return type:

numpy.ndarray

MultivariateBinomial.correlation()[source]#

Correlation matrix of the distribution.

Returns:

Correlation matrix.

Return type:

numpy.ndarray

MultivariateBinomial.rvs(size=1, random_state=None)[source]#

Random variates generator function.

Parameters:
  • size (int) – Number of random variates to generate (default=1).

  • random_state (int, optional) – Random state for reproducibility.

Returns:

Array of random variates.

Return type:

numpy.ndarray

MultivariatePoisson#

class MultivariatePoisson(**kwargs)[source]#

Bases: object

Multivariate Poisson distribution. Implementation from “Multivariate Binomial and Poisson Distribution”, A.S. Krishnamoorthy, 2013

Parameters:

**kwargs – See below

Keyword Arguments:
  • mu (numpy.ndarray) – Array (k,) of marginal means.

  • mu_joint (numpy.ndarray) – Matrix (k,k) of Cov(Xi,Xj).

MultivariatePoisson.pmf(x)[source]#

Probability mass function using Charlier polynomials expansion.

Parameters:

x (numpy.ndarray) – Quantile where PMF is evaluated.

Returns:

Probability mass function evaluated at x.

Return type:

numpy.float64

MultivariatePoisson.mean()[source]#

Mean vector of the distribution.

Returns:

Mean vector.

Return type:

numpy.ndarray

MultivariatePoisson.cov()[source]#

Covariance matrix of the distribution.

Returns:

Covariance matrix.

Return type:

numpy.ndarray

MultivariatePoisson.var()[source]#

Variance.

Returns:

Variance array.

Return type:

numpy.ndarray

MultivariatePoisson.correlation()[source]#

Correlation matrix of the distribution.

Returns:

Correlation matrix.

Return type:

numpy.ndarray

MultivariatePoisson.rvs(size=1, random_state=None)[source]#

Random variates generator function.

Parameters:
  • size (int) – Number of random variates to generate (default=1).

  • random_state (int, optional) – Random state for reproducibility.

Returns:

Array of random variates.

Return type:

numpy.ndarray

copulas module#

class ClaytonCopula(par, dim)[source]#

Bases: object

Clayton copula.

Parameters:
  • par (float) – copula parameter.

  • dim (int) – copula dimension.

ClaytonCopula.cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (numpy.ndarray) – Array with shape (N, d) where N is the number of points and d the dimension.

Returns:

Cumulative distribution function in x.

Return type:

numpy.ndarray

ClaytonCopula.rvs(size=1, random_state=None)[source]#

Random variates.

Parameters:
  • size (int) – random variates sample size (default is 1).

  • random_state (int) – random state for the random number generator.

Returns:

Random variates.

Return type:

numpy.float64 or numpy.ndarray

class FrankCopula(par, dim)[source]#

Bases: object

Frank copula.

Parameters:
  • par (float) – copula parameter.

  • dim (int) – copula dimension.

FrankCopula.cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (numpy.ndarray) – Array with shape (N, d) where N is the number of points and d the dimension.

Returns:

Cumulative distribution function in x.

Return type:

numpy.ndarray

FrankCopula.rvs(size=1, random_state=None)[source]#

Random variates.

Parameters:
  • size (int) – random variates sample size (default is 1).

  • random_state (int) – random state for the random number generator.

Returns:

Random variates.

Return type:

numpy.float64 or numpy.ndarray

class GumbelCopula(par, dim)[source]#

Bases: object

Gumbel copula.

Parameters:
  • par (float) – copula parameter.

  • dim (int) – copula dimension.

GumbelCopula.cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (numpy.ndarray) – Array with shape (N, d) where N is the number of points and d the dimension.

Returns:

Cumulative distribution function in x.

Return type:

numpy.ndarray

GumbelCopula.rvs(size=1, random_state=None)[source]#

Random variates.

Parameters:
  • size (int) – random variates sample size (default is 1).

  • random_state (int) – random state for the random number generator.

Returns:

Random variates.

Return type:

numpy.float64 or numpy.ndarray

class GaussCopula(corr)[source]#

Bases: object

Gaussian copula.

Parameters:

corr (numpy.ndarray) – Correlation matrix.

GaussCopula.cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (numpy.ndarray) – Array with shape (N, d) where N is the number of points and d the dimension.

Returns:

Cumulative distribution function in x.

Return type:

numpy.ndarray

GaussCopula.rvs(size=1, random_state=None)[source]#

Random variates.

Parameters:
  • size (int) – random variates sample size (default is 1).

  • random_state (int) – random state for the random number generator.

Returns:

Random variates.

Return type:

numpy.float64 or numpy.ndarray

class TCopula(corr, df)[source]#

Bases: object

Student t copula.

Parameters:
  • corr (numpy.ndarray) – Correlation matrix.

  • df (int) – Degree of freedom.

TCopula.cdf(x, tolerance=0.0001, n_iterations=30)[source]#

Cumulative distribution function.

Parameters:
  • x (numpy.ndarray) – quantile where the cumulative distribution function is evaluated. Array with shape (n, d) where n is the number of data points and d the dimension.

  • tolerance (float, optional) – tolerance threshold of approximation (default is 1e-4).

  • n_iterations (int, optional) – number of iteration (default is 30).

Returns:

Cumulative distribution function in x.

Return type:

numpy.ndarray

TCopula.rvs(size=1, random_state=None)[source]#

Random variates.

Parameters:
  • size (int, optional) – random variates sample size (default is 1).

  • random_state (int, optional) – random state for the random number generator.

Returns:

Random variates.

Return type:

numpy.float64 or numpy.ndarray

class IndependenceCopula(dim)[source]#

Bases: object

The product (independence) copula.

Parameters:

dim (int) – copula dimension.

IndependenceCopula.cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (numpy.ndarray) – Array with shape (N, d) where N is the number of points and d the dimension.

Returns:

Cumulative distribution function in x.

Return type:

numpy.ndarray

IndependenceCopula.rvs(size=1, random_state=None)[source]#

Random variates.

Parameters:
  • size (int) – random variates sample size (default is 1).

  • random_state (int) – random state for the random number generator.

Returns:

Random variates.

Return type:

numpy.float64 or numpy.ndarray

class FHLowerCopula[source]#

Bases: object

Fréchet–Hoeffding lower bound bidimensional copula.

FHLowerCopula.cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (numpy.ndarray) – Array with shape (N, 2) where N is the number of points.

Returns:

Cumulative distribution function in x.

Return type:

numpy.ndarray

FHLowerCopula.rvs(size=1, random_state=None)[source]#

Random variates.

Parameters:
  • size (int) – random variates sample size (default is 1).

  • random_state (int) – random state for the random number generator.

Returns:

Random variates.

Return type:

numpy.float64 or numpy.ndarray

class FHUpperCopula(dim)[source]#

Bases: object

Fréchet–Hoeffding upper bound copula.

FHUpperCopula.cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (numpy.ndarray) – Array with shape (N, d) where N is the number of points and d the dimension.

Returns:

Cumulative distribution function in x.

Return type:

numpy.ndarray

FHUpperCopula.rvs(size=1, random_state=None)[source]#

Random variates.

Parameters:
  • size (int) – random variates sample size (default is 1).

  • random_state (int) – random state for the random number generator.

Returns:

Random variates.

Return type:

numpy.float64 or numpy.ndarray

class JoeCopula(par, dim)[source]#

Bases: object

Joe copula.

Parameters:
  • par (float) – copula parameter.

  • dim (int) – copula dimension.

JoeCopula.cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (numpy.ndarray) – Array with shape (N, d) where N is the number of points and d the dimension.

Returns:

Cumulative distribution function in x.

Return type:

numpy.ndarray

JoeCopula.rvs(size=1, random_state=None)[source]#

Random variates.

Parameters:
  • size (int) – random variates sample size (default is 1).

  • random_state (int) – random state for the random number generator.

Returns:

Random variates.

Return type:

numpy.float64 or numpy.ndarray

class AliMikhailHaqCopula(par, dim)[source]#

Bases: object

Ali-Mikhail-Haq copula.

Parameters:
  • par (float) – copula parameter.

  • dim (int) – copula dimension.

AliMikhailHaqCopula.cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (numpy.ndarray) – Array with shape (N, d) where N is the number of points and d the dimension.

Returns:

Cumulative distribution function in x.

Return type:

numpy.ndarray

AliMikhailHaqCopula.rvs(size=1, random_state=None)[source]#

Random variates.

Parameters:
  • size (int) – random variates sample size (default is 1).

  • random_state (int) – random state for the random number generator.

Returns:

Random variates.

Return type:

numpy.float64 or numpy.ndarray

helperfunctions module#

The following helper functions have docstrings. They are listed explicitly and private helpers are not included.

arg_type_handler(x)[source]#

Checks that arguments in distributions.py methods are managed correctly.

Parameters:

x (any) – method input

Returns:

x

Return type:

numpy.ndarray

ecdf(x)[source]#

Empirical cumulative distribution function.

Parameters:

x (numpy.ndarray) – sequence of nodes basis of the ecdf.

Returns:

empirical cumulative distribution function.

Return type:

function

normalizernans(x)[source]#

Normalize a vector with nan values ignoring the nan values during the computation. Used in the lossreserve.py script.

Parameters:

x (numpy.ndarray) – sequence to be normalized.

Returns:

normalized sequence.

Return type:

numpy.ndarray

lrcrm_f1(x, dist)[source]#

Simulate a random number from a distribution a poisson distribution with parameter mu. Used in the lossreserve.py script.

Parameters:
  • x (float) – distribution parameter.

  • dist (scipy.stats._discrete_distns.poisson_gen) – poisson distribution.

:return:simulated random number. :rtype: numpy.ndarray

lrcrm_f2(x, dist)[source]#

Simulates random values from a gamma. Used in the lossreserve.py script.

Parameters:
  • x (numpy.ndarray) – it contains the gamma parameters and the number of random values to be simulated.

  • dist (scipy.stats._discrete_distns.gamma_gen) – gamma distribution.

Returns:

sum of the simulated numbers.

Return type:

numpy.ndarray

lrcrm_f3(x, dist, dist2)[source]#

Simulates random values from a gamma. Used in the lossreserve.py script.

Parameters:
  • x (numpy.ndarray) – it contains the gamma parameters and the number of random values to be simulated.

  • dist (scipy.stats._discrete_distns.gamma_gen) – gamma distribution.

Returns:

sum of the simulated numbers.

Return type:

numpy.ndarray

cartesian_product(*arrays)[source]#

Generate the matrix points where copula is computed. Used in the lossaggregation.py script.

Returns:

matrix of points.

:rtype:numpy.ndarray

cov_to_corr(cov)[source]#

Covariance matrix to correlation matrix converter. Equivalent to R ‘cov2corr’ function.

Used in the copulas.py script.

Parameters:

cov (numpy.ndarray) – matrix of covariates

Returns:

matrix of correlations.

Return type:

numpy.ndarray

multivariate_t_cdf(x, corr, df, tol, iterations)[source]#

Estimate the cdf of a multivariate t distribution using quasi-Monte Carlo algorithm. Used in the copulas.py script.

See: - Genz, A. and F. Bretz (1999) “Numerical Computation of Multivariate t Probabilities with Application to Power Calculation of Multiple Contrasts”, J.Statist.Comput.Simul., 63:361-378. - Genz, A. and F. Bretz (2002) “Comparison of Methods for the Computation of Multivariate t Probabilities”, J.Comp.Graph.Stat., 11(4):950-971.

Parameters:
  • x (numpy.ndarray) – quantile where the cumulative distribution function is evaluated.

  • corr (numpy.ndarray) – correlation matrix of the distribution,must be symmetric and positive definite, with all elements of the diagonal being 1.

  • df (float) – degrees-of-freedom of the distribution, must be a positive real number.

  • tol (float) – tolerance for quasi-Monte Carlo algorithm.

  • iterations (int) – number of iterations of quasi-Monte Carlo algorithm.

Returns:

cumulative density function value and error estimate of the numerical approximation.

Return type:

tuple

assert_member(value, choice, logger, link=None)[source]#

Assert that a value is cointained in a reference set the value must belong to.

Parameters:
  • value (str) – value whose membership of set is to be checked.

  • choice (set) – admissible values.

  • logger (logger) – error log.

  • link (str) – link where additional information about set memebers can be found (optional).

Returns:

Void.

Return type:

None

assert_type_value(value, name, logger, type=(<class 'int'>, <class 'float'>), upper_bound=None, lower_bound=None, lower_close=True, upper_close=True)[source]#

Assert that a value match a given type and optional value criteria.

Parameters:
  • value (object) – value whose type and criteria is to be checked.

  • name (str) – name associated to the value object.

  • logger (logger) – error log.

  • type (tuple or type) – reference type to be matched.

  • upper_bound (float) – upper bound of value. Not None if value is a float or int.

  • lower_bound (float) – lower bound of value. Not None if value is a float or int.

  • upper_close (bool) – if upper_bound value is included in the admissible range or not. Not None iff value is a float or int.

  • lower_close (bool) – if lower_bound value is included in the admissible range or not. Not None iff value is a float or int.

Returns:

Void.

Return type:

None

ndarray_try_convert(value, name, logger, type=None)[source]#

Convert a given input value to a numpy array.

Parameters:
  • value (float, np.floating`) – value to be converted into a numpy array.

  • name (str) – name associated to the value object.

  • logger (logger) – error log.

  • type (np.dtype) – dtype of the numpy array to be returned.

Returns:

numpy array.

Return type:

np.ndarray

check_condition(value, check, name, logger, type='==')[source]#

Check that a condition holds between two values.

Parameters:
  • value (float, int) – value to assert equality.

  • check (float, int) – reference to match value to assert equality.

  • name (str) – name associated to the value object.

  • logger (logger) – error log.

  • type (str) – condition type to check, one of ‘==’, ‘!=’, ‘<=’, ‘<’, ‘>=’, ‘>’.

Returns:

Void.

Return type:

None

handle_random_state(value, logger)[source]#

Assert and if missing set up a random state to use in a pseudo random simulation.

Parameters:
  • value (int or None) – value of the random state provided by the user (a.k.a set random seed).

  • logger (logger) – error log.

Returns:

value of the random state.

Return type:

int

assert_not_none(value, name, logger)[source]#

Assert if value is not none.

Parameters:
  • value (Python object) – value to be tested not None.

  • name (str) – name assigned to the value.

  • logger (logger) – error log.

Returns:

Raise error if value is None.

Return type:

None or ValueError

check_none(value, logger, action, message)[source]#

Check if value is not none and perform a specified action.

Parameters:
  • value (Python object) – list of value to be tested not None.

  • logger (logger) – error log.

  • action (str) – action to perform if value is None. One of ‘error’, ‘warning’, ‘pass’.

  • message (str) – message to return.

Returns:

True of False depending whether the value is None or raise error.

Return type:

bool or ValueError

layerFunc(nodes, cover, deductible)[source]#

layer transformation, i.e. min-max function. Vectorized version with respect to cover and deductible.

Parameters:
  • nodes (np.ndarray, np.floating) – distribution nodes to which apply the layer transformation.

  • deductible (np.ndarray, np.floating) – deductible.

  • cover (np.ndarray, np.floating) – cover.

Returns:

layer transformed array.

Return type:

np.ndarray, np.floating

triangle_dimension(incremental_payments, cased_payments, incurred_number, cased_number)[source]#

Function to check that the provided dimension of the triangles is consistent and return the triangle dimension.

Parameters:
  • incremental_payments (np.ndarray) – distribution nodes to which apply the layer transformation.

  • cased_payments (np.ndarray) – distribution nodes to which apply the layer transformation.

  • incurred_number (np.ndarray) – deductible.

  • cased_number (np.ndarray) – cover.

Returns:

triangle dimension.

Return type:

np.floating, np.integer

compute_block2_crm_msep(average_payments, predicted_i_numbers, data, czj)[source]#

Function to compute the second block of the variance for the Collective Risk Model for Reserving in Ricotta et al. (2016)

Parameters:
  • data (gemact.AggregateData) – preprocessed company AggregateData information.

  • czj (np.ndarray) – coefficients of variation.

lrcrm_skewness_f4(x, dist)[source]#

Computes the severity third central moment. Used in the lossreserve.py script.

Parameters:
  • x (numpy.ndarray) – it contains the gamma parameters and the number of random values to be simulated.

  • dist (scipy.stats._discrete_distns.gamma_gen) – gamma distribution.

Returns:

sum of the simulated numbers.

Return type:

numpy.ndarray

compute_block2_crm_skewness(gamma1, gamma2, average_payments, predicted_i_numbers, data, czj, fl_reserve)[source]#

Internal function to compute the second block of the skewness in closed form.

Parameters:
  • gamma1 (scipy.stats._discrete_distns.gamma_gen) – frequency structure variable.

  • gamma2 (scipy.stats._discrete_distns.gamma_gen) – severity structure variable.

  • average_payments (numpy.ndarray) – Triangle of average payments.

  • predicted_i_numbers (numpy.ndarray) – Triangle of predicted payment numbers.

  • data (ReservingData) – ReservingData object.

  • czj (float64) – Vector of coefficients of variation per development period.

  • czj – Vector of coefficients of variation per development period.

  • fl_reserve – Fisher-Lange reserve.

Returns:

Block two of skewness closed formula.

Return type:

numpy.ndarray

compute_block3_crm_skewness(gamma1, gamma2, gamma3, average_payments, predicted_i_numbers, data, czj, fl_reserve)[source]#

Internal function to compute the third block of the skewness in closed form.

Parameters:
  • gamma1 (scipy.stats._discrete_distns.gamma_gen) – frequency structure variable.

  • gamma2 (scipy.stats._discrete_distns.gamma_gen) – severity structure variable.

  • average_payments (numpy.ndarray) – triangle of average payments.

  • predicted_i_numbers (numpy.ndarray) – triangle of predicted payment numbers.

  • data (ReservingData) – ReservingData object.

  • czj (float64) – Vector of coefficients of variation per development period.

  • czj – Vector of coefficients of variation per development period.

  • fl_reserve – Fisher-Lange reserve.

Returns:

Block three of skewness closed formula.

Return type:

numpy.ndarray

find_diagonal(mx, bigJ)[source]#

Function to find the diagonal of a reserving triangle.

Parameters:
  • mx (gemact.AggregateData) – preprocessed company AggregateData information.

  • bigJ (int) – triangle dimension.

Returns:

triangle diagonal

Return type:

np.ndarray

incrementals_2_cumulatives(mx)[source]#

Function to transform a triangle of incrementals into cumulatives.

Parameters:

mx (np.ndarray) – triangle of incrementals.

Returns:

triangle of cumulatives

Return type:

np.ndarray

make_pdf(par, func)[source]#

Return a pdf. MIT Probabilistic Computing Project. http://probcomp.csail.mit.edu/blog/programming-and-probability-sampling-from-a-discrete-distribution-over-an-infinite-set/

make_cdf(pdf)[source]#

Return cdf for pdf. MIT Probabilistic Computing Project. http://probcomp.csail.mit.edu/blog/programming-and-probability-sampling-from-a-discrete-distribution-over-an-infinite-set/

find_interval(u, cdf)[source]#

Find k such that u falls in I_k of given cdf. MIT Probabilistic Computing Project. http://probcomp.csail.mit.edu/blog/programming-and-probability-sampling-from-a-discrete-distribution-over-an-infinite-set/

simulate(cdf)[source]#

Simulate from pdf. MIT Probabilistic Computing Project. http://probcomp.csail.mit.edu/blog/programming-and-probability-sampling-from-a-discrete-distribution-over-an-infinite-set/

memoize(f)[source]#

helper function to speed up the simulation procedure using memoization. MIT Probabilistic Computing Project. http://probcomp.csail.mit.edu/blog/programming-and-probability-sampling-from-a-discrete-distribution-over-an-infinite-set/

partial_moment(n, low, up, dist)[source]#

Numerical approximation of the partial moment of order n of a dist distributed random variable.

Parameters:
  • n (int) – moment order.

  • low (int, float) – lower limit of the partial moment.

  • up (int, float) – upper limit of the partial moment.

  • dist (Severity) – distribution model.

Returns:

raw partial moment of order n.

Return type:

float

censored_moment(n, d, c, dist)[source]#

Non-central moment of order n of the transformed random variable min(max(x - d, 0), c). Where x is a dist distributed random variable.

Parameters:
  • n (int) – moment order.

  • d (int, float) – deductible, or attachment point.

  • c (int, float) – cover, deductible + cover is the detachment point.

  • dist (Severity) – distribution model.

Returns:

raw moment of order n.

Return type:

float

References#

[AEP11]

Philipp Arbenz, Paul Embrechts, and Giovanni Puccetti. The aep algorithm for the fast computation of the distribution of the sum of dependent random variables. Bernoulli, 17:562–591, 2011.

[EF08]

P. Embrechts and M. Frei. Panjer recursion versus fft for compound distributions. Mathematical Methods of Operations Research, 2008.

[FLB99]

Wayne H. Fisher, Jeffrey T. Lange, and John Balcarek. Loss reserve testing: a report year approach. 1999.

[KP19] (1,2,3)

P. Klugman and H.H. Panjer. Loss models from data to decisions. Wiley, SOA, 2019.

[RC16]

Alessandro Ricotta and Gian Paolo Clemente. An extension of collective risk model for stochastic claim reserving. 2016.

[SC14]

Nino Savelli and Gian Paolo Clemente. Lezioni di matematica attuariale delle assicurazioni danni. EDUCatt-Ente per il diritto allo studio universitario dell'Università Cattolica, 2014. ISBN 9788867807048. URL: http://hdl.handle.net/10807/67154.

[Sun91] (1,2)

B. Sundt. On excess of loss reinsurance with reinstatements. Insurance: Mathematics and Economics, 1991.