Skip to main content

risk.GaussianCopula

The Gaussian copula with correlation matrix correlation.

Usage

Source

risk.GaussianCopula()

Parameters

correlation: list of list of float
Symmetric, unit diagonal, positive definite.

Raises

ValueError
If the matrix is not a valid correlation matrix.

Examples

>>> from prospicio.risk import GaussianCopula
>>> c = GaussianCopula([[1.0, 0.5], [0.5, 1.0]])
>>> u = c.sample(3, seed=1)
>>> len(u), all(0.0 < x < 1.0 for row in u for x in row)

(3, True)

Attributes

Name Description
dim Number of dimensions.

dim

Number of dimensions.

dim: int

Methods

Name Description
cdf() The copula’s distribution function at the point u, each
cdf_estimate() The distribution function at u with its error estimate: exact
sample() n draws of uniforms; draw i uses stream i of seed.
sample_qmc() n draws on scrambled Sobol points (quasi-Monte Carlo): each

cdf()

The copula’s distribution function at the point u, each

Usage

Source

cdf(u)

coordinate in [0, 1].

Parameters
u: list of float
One value per dimension.
Returns
float
Raises
ValueError
If u has the wrong length or a value outside [0, 1], or the copula has no closed-form distribution function here.
Examples
>>> from prospicio.risk import GaussianCopula
>>> round(GaussianCopula([[1.0, 0.5], [0.5, 1.0]]).cdf([0.5, 0.5]), 12)

0.333333333333


cdf_estimate()

The distribution function at u with its error estimate: exact

Usage

Source

cdf_estimate(u, abs_tol=1e-05, max_points=..., seed=0)

in two dimensions, by Genz’s randomized quasi-Monte Carlo method in more (mvn_cdf). cdf is this at the defaults.

Parameters
u: list of float

One value per dimension, each in [0, 1].

abs_tol: float = 1e-5

Absolute error to reach, three standard errors.

max_points: int = 4194304

Most integrand evaluations.

seed: int = 0
Seed of the scrambles, so a call is reproducible.
Returns
MvnEstimate
Examples
>>> from prospicio.risk import GaussianCopula
>>> r = [[1.0, 0.5, 0.5], [0.5, 1.0, 0.5], [0.5, 0.5, 1.0]]
>>> p = GaussianCopula(r).cdf_estimate([0.5, 0.5, 0.5], abs_tol=1e-7)
>>> abs(p.value - 0.25) < 1e-6, p.error < 1e-7, p.converged

(True, True, True)


sample()

n draws of uniforms; draw i uses stream i of seed.

Usage

Source

sample(n, seed)
Parameters
n: int
seed: int
Returns
list of list of float

sample_qmc()

n draws on scrambled Sobol points (quasi-Monte Carlo): each

Usage

Source

sample_qmc(n, seed=0)

point w becomes Φ(L Φ⁻¹(w)). Over a power of two of points each margin is spread far more evenly than random draws, so a statistic converges faster; the rows are not independent, so a standard error needs several seeds. At most 1,111 dimensions.

Parameters
n: int

A power of two keeps the points balanced.

seed: int = 0
Returns
list of list of float
Examples
>>> from prospicio.risk import GaussianCopula
>>> u = GaussianCopula([[1.0, 0.6], [0.6, 1.0]]).sample_qmc(1024, seed=7)
>>> sorted(int(row[0] * 1024) for row in u) == list(range(1024))

True