Pro Feature. Requires a Pro or Ultra subscription. Get started at api.mathematicalcompany.com
Lead-Lag Networks
Horizon provides Rust-native tools for detecting which prediction markets lead or lag others. These relationships are fundamental to cross-market arbitrage, informed order routing, and signal extraction from related markets.Hayashi-Yoshida
Asynchronous tick-by-tick correlation that handles irregular timestamps without synchronization bias.
Cross-Correlation
Multi-lag cross-correlation analysis to identify optimal lead/lag offsets.
Granger Causality
Statistical test for whether past values of one market predict another.
Lead-Lag Network
Build a directed network of lead-lag relationships across many markets.
hz.hayashi_yoshida
Compute the Hayashi-Yoshida estimator for asynchronous correlation between two tick streams. Unlike standard Pearson correlation, this does not require synchronized timestamps and avoids the Epps effect (correlation attenuation from data aggregation).| Parameter | Type | Description |
|---|---|---|
timestamps_x | list[float] | Tick timestamps for market X |
prices_x | list[float] | Tick prices for market X |
timestamps_y | list[float] | Tick timestamps for market Y |
prices_y | list[float] | Tick prices for market Y |
LeadLagResult Type
| Field | Type | Description |
|---|---|---|
correlation | float | Hayashi-Yoshida correlation estimate (-1 to 1) |
covariance | float | Hayashi-Yoshida covariance estimate |
n_overlaps | int | Number of overlapping return intervals used |
hz.cross_correlation_lags
Compute cross-correlation between two synchronized series at multiple lags to identify the optimal lead-lag offset.| Parameter | Type | Default | Description |
|---|---|---|---|
series_x | list[float] | required | First time series (returns or prices) |
series_y | list[float] | required | Second time series (same length as series_x) |
max_lag | int | 10 | Maximum lag to compute (both positive and negative) |
Cross-Correlation Result Type
| Field | Type | Description |
|---|---|---|
lags | list[int] | Lag values from -max_lag to +max_lag |
correlations | list[float] | Correlation at each lag |
best_lag | int | Lag with the highest absolute correlation |
best_correlation | float | Correlation value at the best lag |
A positive
best_lag means series_x leads series_y by that many observations. A negative best_lag means series_y leads series_x.hz.granger_causality
Test whether past values of series X help predict series Y beyond what series Y’s own past values provide. Uses an F-test on a bivariate VAR model.| Parameter | Type | Default | Description |
|---|---|---|---|
series_x | list[float] | required | Potential causal series |
series_y | list[float] | required | Potential effect series |
max_lag | int | 5 | Maximum lag order for the VAR model |
GrangerResult Type
| Field | Type | Description |
|---|---|---|
f_statistic | float | F-test statistic for the null hypothesis that X does not Granger-cause Y |
p_value | float | p-value of the F-test (lower = stronger evidence of causality) |
optimal_lag | int | Lag order selected by the test |
is_significant | bool | True if p_value < 0.05 |
hz.lead_lag_network
Build a directed network of lead-lag relationships across multiple markets. Computes pairwise Hayashi-Yoshida correlations at multiple lags and constructs a graph where edges point from leaders to followers.| Parameter | Type | Default | Description |
|---|---|---|---|
market_ids | list[str] | required | Market identifiers |
timestamps | list[list[float]] | required | Tick timestamps for each market |
prices | list[list[float]] | required | Tick prices for each market |
max_lag | int | 5 | Maximum lag to test in cross-correlation |
min_correlation | float | 0.3 | Minimum absolute correlation to create an edge |
LeadLagNetwork Type
| Field | Type | Description |
|---|---|---|
nodes | list[GraphNode] | Market nodes with degree statistics |
edges | list[GraphEdge] | Directed edges from leaders to followers |
adjacency | list[list[float]] | Weighted adjacency matrix (correlation values) |
GraphNode Type
| Field | Type | Description |
|---|---|---|
market_id | str | Market identifier |
out_degree | int | Number of markets this one leads |
in_degree | int | Number of markets that lead this one |
leadership_score | float | out_degree / (in_degree + out_degree) |
GraphEdge Type
| Field | Type | Description |
|---|---|---|
source | str | Leader market ID |
target | str | Follower market ID |
lag | int | Optimal lag (in ticks) from source to target |
correlation | float | Correlation strength at the optimal lag |
Pipeline Integration
hz.lead_lag_detector
Creates a pipeline function that tracks lead-lag relationships between feeds and injects leadership scores intoctx.params.
| Parameter | Type | Default | Description |
|---|---|---|---|
feed_x | str | required | Potential leader feed |
feed_y | str | required | Potential follower feed |
lookback | int | 500 | Number of observations to retain for correlation |
max_lag | int | 10 | Maximum lag to scan |
min_correlation | float | 0.3 | Minimum correlation to flag a lead-lag relationship |
param_name | str | "lead_lag" | Key in ctx.params |
Mathematical Background
Hayashi-Yoshida Estimator
Hayashi-Yoshida Estimator
The HY estimator computes the realized covariance between two asynchronously observed processes. For each pair of return intervals that overlap in time, it accumulates the product of the returns. This avoids synchronization (e.g., previous-tick interpolation) which attenuates correlation at high frequencies (the Epps effect).HY_cov = sum over overlapping intervals (delta_X_i * delta_Y_j)
Granger Causality
Granger Causality
X Granger-causes Y if past values of X improve the prediction of Y beyond what past values of Y alone provide. The test compares two VAR regressions:
- Restricted:
Y_t = c + sum(a_i * Y_{t-i}) - Unrestricted:
Y_t = c + sum(a_i * Y_{t-i}) + sum(b_i * X_{t-i})
Lead-Lag in Prediction Markets
Lead-Lag in Prediction Markets
In prediction markets, lead-lag relationships arise because:
- Correlated events: Related markets (e.g., presidency and Senate) share underlying information
- Liquidity differences: More liquid markets incorporate information faster
- Attention asymmetry: High-profile markets attract faster traders