Skip to content

Copulas

quantflow.sp.copula.Copula pydantic-model

Bases: BaseModel, ABC

Bivariate copula probability distribution - Abstract class

Sklar's theorem states that any multivariate joint distribution can be written in terms of univariate marginal-distribution functions and a copula which describes the dependence structure between the variables.

tau abstractmethod

tau()

Kendall's tau - rank correlation parameter

Source code in quantflow/sp/copula.py
@abstractmethod
def tau(self) -> float:
    """Kendall's tau - rank correlation parameter"""

rho abstractmethod

rho()

Spearman's rho - rank correlation parameter

Source code in quantflow/sp/copula.py
@abstractmethod
def rho(self) -> float:
    """Spearman's rho - rank correlation parameter"""

jacobian

jacobian(u, v)

Jacobian with respected to u, v, and the internal parameters parameters of the copula. Optional to implement.

Source code in quantflow/sp/copula.py
def jacobian(self, u: FloatArrayLike, v: FloatArrayLike) -> FloatArray:
    """
    Jacobian with respected to u, v, and the internal parameters
    parameters of the copula.
    Optional to implement.
    """
    raise NotImplementedError

quantflow.sp.copula.IndependentCopula pydantic-model

Bases: Copula

No-op copula that keep the distributions independent.

\[\begin{equation} C(u,v) = uv \end{equation}\]

tau

tau()
Source code in quantflow/sp/copula.py
def tau(self) -> float:
    return 0.0

rho

rho()
Source code in quantflow/sp/copula.py
def rho(self) -> float:
    return 0.0

jacobian

jacobian(u, v)
Source code in quantflow/sp/copula.py
def jacobian(self, u: FloatArrayLike, v: FloatArrayLike) -> FloatArray:
    return np.array([v, u])

quantflow.sp.copula.FrankCopula pydantic-model

Bases: Copula

Frank Copula with parameter \(\kappa\)

\[\begin{equation} C(u, v) = -\frac{1}{\kappa}\log\left[1+\frac{\left(\exp\left(-\kappa u\right)-1\right)\left(\exp\left(-\kappa v\right)-1\right)}{\exp\left(-\kappa\right)-1}\right] \end{equation}\]

Fields:

kappa pydantic-field

kappa = 0.0

Frank copula parameter

tau

tau()

Kendall's tau

Source code in quantflow/sp/copula.py
def tau(self) -> float:
    """Kendall's tau"""
    k = self.kappa
    if isclose(k, 0.0):
        return 0
    return 1 + 4 * (debye(1, k) - 1) / k

rho

rho()

Spearman's rho

Source code in quantflow/sp/copula.py
def rho(self) -> float:
    """Spearman's rho"""
    k = self.kappa
    if isclose(k, 0.0):
        return 0
    return 1 - 12 * (debye(2, -k) - debye(1, -k)) / k

jacobian

jacobian(u, v)
Source code in quantflow/sp/copula.py
def jacobian(self, u: FloatArrayLike, v: FloatArrayLike) -> FloatArray:
    k = self.kappa
    if isclose(k, 0.0):
        return np.array([v, u, v * 0])
    eu = np.exp(-k * u)
    ev = np.exp(-k * v)
    e = np.exp(-k)
    x = (eu - 1) * (ev - 1) / (e - 1)
    c = -np.log(1 + x) / k
    xx = x / (1 + x)
    du = eu * (ev - 1) / (e - 1) / (1 + x)
    dv = ev * (eu - 1) / (e - 1) / (1 + x)
    dk = (u * du + v * dv - e * xx / (e - 1) - c) / k
    return np.array([du, dv, dk])