API

class QuadraticFormsMGHyp.QuadraticForm(a0, a, A, C, mu, gam, lam, chi, psi)

Quadratic form L = a0 + a'X + X'A X in a multivariate GH vector.

X = mu + W gam + sqrt(W) C Z, with Z standard normal and W ~ GIG(lam, chi, psi). gam is the skewness vector γ. a, mu, and gam have length d. A and C are d × d, either shaped (d, d) or flattened in row-major order.

The constructor diagonalizes the form. Repeat eval on one instance when several threshold grids share that reduction. The object releases the C state when it is closed, when a with block ends, or when it is collected.

Parameters:
  • a0 (float) – Constant term and the GIG parameters λ, χ, and ψ.

  • lam (float) – Constant term and the GIG parameters λ, χ, and ψ.

  • chi (float) – Constant term and the GIG parameters λ, χ, and ψ.

  • psi (float) – Constant term and the GIG parameters λ, χ, and ψ.

  • a (array_like) – Length-d vectors.

  • mu (array_like) – Length-d vectors.

  • gam (array_like) – Length-d vectors.

  • A (array_like) – d × d matrices.

  • C (array_like) – d × d matrices.

dimension

Length of a. None after from_spectral.

Type:

int or None

ne

Number of retained spectral terms. None until from_spectral.

Type:

int or None

classmethod from_spectral(omega, d, e, c, k, kk, lam, chi, psi)

Build from the spectral reduction used by the integral.

Parameters:
  • omega (array_like) – Eigenvalues and the two coefficient vectors, same length.

  • d (array_like) – Eigenvalues and the two coefficient vectors, same length.

  • e (array_like) – Eigenvalues and the two coefficient vectors, same length.

  • c (float) – The remaining scalar coefficients. kk is added back when the conditional expectation is formed.

  • k (float) – The remaining scalar coefficients. kk is added back when the conditional expectation is formed.

  • kk (float) – The remaining scalar coefficients. kk is added back when the conditional expectation is formed.

  • lam (float) – The remaining scalar coefficients. kk is added back when the conditional expectation is formed.

  • chi (float) – The remaining scalar coefficients. kk is added back when the conditional expectation is formed.

  • psi (float) – The remaining scalar coefficients. kk is added back when the conditional expectation is formed.

Return type:

QuadraticForm

eval(x, threads=0)

Integrate once and return the distribution and both moments.

Parameters:
  • x (array_like) – One-dimensional thresholds.

  • threads (int, optional) – Worker count on the scalar path. threads <= 0 uses one worker per logical CPU. NIG, ψ = 0, and the general-GH series evaluate the vector on the calling thread. More than 24 thresholds are reduced to a Chebyshev grid first.

Returns:

cdf, ccdf, pm, es – cdf[i] = P(L <= x[i]), ccdf[i] = P(L > x[i]), pm[i] = E[L 1_{L > x[i]}], and es[i] = E[L | L > x[i]]. The cdf and the partial moment are formed from the survival function and the expected shortfall of this same pass.

Return type:

ndarray

close()

Release the C object. A later eval raises RuntimeError.