Pro Feature. Requires a Pro or Ultra subscription. Get started at api.mathematicalcompany.com
Copula Dependence
Horizon implements four bivariate copula families for modeling dependence between prediction markets. Copulas separate the marginal distributions from the dependence structure, allowing you to capture tail dependence, asymmetric co-movement, and non-linear relationships that linear correlation misses. All computation runs in Rust via PyO3.4 Copula Families
Gaussian, Clayton, Gumbel, and Frank copulas covering symmetric, lower-tail, upper-tail, and no-tail dependence.
Automatic Selection
best_copula() fits all families and selects the one with highest log-likelihood.Sampling
Generate correlated uniform samples from any fitted copula for Monte Carlo simulation.
Pipeline Integration
hz.copula_dependence() monitors pairwise dependence in real time within hz.run().Why Copulas?
Linear correlation captures only one dimension of dependence. In prediction markets, outcomes often exhibit:- Tail dependence: two markets crash together more often than they rally together (Clayton copula)
- Upper tail dependence: markets resolve YES simultaneously (Gumbel copula)
- Symmetric dependence: markets move together uniformly across quantiles (Gaussian copula)
- No tail dependence: markets are linked but extreme co-movements are rare (Frank copula)
All copula functions operate on uniform marginals (values in [0, 1]). Use
hz.rank_transform() to convert raw price series to pseudo-uniform observations before fitting.API
CopulaFamily Enum
| Variant | Tail Dependence | Parameter Range | Best For |
|---|---|---|---|
Gaussian | None | rho in (-1, 1) | General symmetric dependence |
Clayton | Lower tail | theta > 0 | Crash co-movement |
Gumbel | Upper tail | theta >= 1 | Joint resolution events |
Frank | None | theta != 0 | Moderate symmetric dependence |
hz.rank_transform
Convert raw observation series to pseudo-uniform marginals using the empirical CDF (rank transform).| Parameter | Type | Description |
|---|---|---|
series_a | list[float] | First observation series |
series_b | list[float] | Second observation series (same length) |
(list[float], list[float]): pseudo-uniform marginals.
hz.fit_copula
Fit a specific copula family to bivariate uniform data using maximum likelihood estimation.| Parameter | Type | Description |
|---|---|---|
u | list[float] | First marginal (values in (0, 1)) |
v | list[float] | Second marginal (same length, values in (0, 1)) |
family | CopulaFamily | Copula family to fit |
CopulaFit.
hz.best_copula
Fit all four copula families and return the one with the lowest AIC (best fit).| Parameter | Type | Description |
|---|---|---|
u | list[float] | First marginal (values in (0, 1)) |
v | list[float] | Second marginal (same length, values in (0, 1)) |
CopulaFit for the best-fitting family.
CopulaFit Type
| Field | Type | Description |
|---|---|---|
family | CopulaFamily | The fitted copula family |
parameter | float | Estimated copula parameter (rho for Gaussian, theta for others) |
log_likelihood | float | Maximized log-likelihood |
aic | float | Akaike Information Criterion (lower is better) |
kendall_tau | float | Implied Kendall’s tau from the fitted parameter |
hz.copula_sample
Generate correlated samples from a fitted copula.| Parameter | Type | Description |
|---|---|---|
family | CopulaFamily | Copula family |
parameter | float | Copula parameter |
n | int | Number of samples to generate |
seed | int | Random seed for reproducibility (optional) |
list[(float, float)].
hz.copula_cdf
Evaluate the copula CDF at a given point (u, v).| Parameter | Type | Description |
|---|---|---|
u | float | First marginal value in [0, 1] |
v | float | Second marginal value in [0, 1] |
family | CopulaFamily | Copula family |
parameter | float | Copula parameter |
float: the copula CDF value C(u, v).
Pipeline Integration
hz.copula_dependence
Pipeline function that fits copulas between market pairs each cycle and injects results intoctx.params["copula"].
ctx.params["copula"] dict contains:
| Key | Type | Description |
|---|---|---|
family | str | Best-fit copula family name |
parameter | float | Fitted copula parameter |
kendall_tau | float | Implied Kendall’s tau |
aic | float | AIC of the best-fit model |
log_likelihood | float | Log-likelihood of the best fit |
Mathematical Background
Sklar's Theorem
Sklar's Theorem
Every joint distribution F(x, y) can be decomposed as F(x, y) = C(F_X(x), F_Y(y)) where C is a copula and F_X, F_Y are the marginal CDFs. The copula C captures all dependence information independent of the marginals. This separation allows modeling marginals and dependence separately.
Copula Families
Copula Families
Gaussian: C(u,v) is derived from the bivariate normal distribution with correlation rho. No tail dependence regardless of correlation strength.Clayton: C(u,v) = (u^(-theta) + v^(-theta) - 1)^(-1/theta). Lower tail dependence coefficient = 2^(-1/theta). Suitable for modeling crash co-movement.Gumbel: C(u,v) = exp(-((-log u)^theta + (-log v)^theta)^(1/theta)). Upper tail dependence coefficient = 2 - 2^(1/theta). Suitable for modeling joint resolution events.Frank: C(u,v) involves the debye function. No tail dependence (similar to Gaussian) but with different dependence structure in the body of the distribution.
Model Selection
Model Selection
best_copula() fits all four families by maximum likelihood and selects the one with the lowest AIC (Akaike Information Criterion). AIC = -2 * log_likelihood + 2 * k, where k is the number of parameters (always 1 for these bivariate copulas). Lower AIC indicates a better balance of fit and parsimony.Kendall's Tau
Kendall's Tau
Each copula family has a closed-form relationship between its parameter and Kendall’s tau:
- Gaussian: tau = (2/pi) * arcsin(rho)
- Clayton: tau = theta / (theta + 2)
- Gumbel: tau = 1 - 1/theta
- Frank: tau = 1 - 4/theta * (1 - D_1(theta)) where D_1 is the first Debye function