Pro Feature. Requires a Pro or Ultra subscription. Get started at api.mathematicalcompany.com
Graph Analysis
Horizon provides Rust-native graph algorithms for analyzing the structure of prediction market networks. Build correlation graphs, extract minimum spanning trees, detect market communities, and measure contagion risk across interconnected markets.Correlation Graph
Build a weighted graph from pairwise market correlations. Filter by threshold to reveal significant relationships.
Minimum Spanning Tree
Extract the MST to find the most important connections with minimal redundancy.
Community Detection
Identify clusters of related markets using modularity-based community detection.
Contagion Risk
Measure how shocks in one market propagate through the network.
hz.build_correlation_graph
Build a weighted undirected graph from pairwise correlations between market return series. Edges are created between markets whose absolute correlation exceeds the threshold.MarketGraph Type
GraphNode Type
GraphEdge Type
hz.minimum_spanning_tree
Extract the minimum spanning tree (MST) from a market graph using Kruskal’s algorithm on correlation distances. The MST connects all markets with the minimum total distance, revealing the backbone structure of the correlation network.
Returns a
MarketGraph containing only the MST edges (N-1 edges for N nodes).
The MST uses correlation distance (smaller = more correlated) as edge weights. Highly correlated markets are connected first. The resulting tree reveals the hierarchical structure of market relationships without cycles.
hz.detect_communities
Detect communities (clusters) of related markets using the Louvain modularity optimization algorithm. Markets within a community are more correlated with each other than with markets in other communities.Community Type
hz.contagion_risk
Measure how a shock to one market propagates through the correlation network. Simulates the impact of a large move in a source market on all connected markets using the correlation structure.Contagion Result Type
Pipeline Integration
hz.market_network
Creates a pipeline function that builds and updates a market correlation graph from multiple feeds. Injects network statistics intoctx.params.
Injected Parameters
Example: Full Network Analysis
Mathematical Background
Correlation Distance
Correlation Distance
The correlation distance d(i,j) = sqrt(0.5 * (1 - corr(i,j))) maps correlations to a proper metric space. Perfectly correlated assets have distance 0; uncorrelated assets have distance sqrt(0.5) ~ 0.707; perfectly anti-correlated assets have distance 1. This metric satisfies the triangle inequality.
Louvain Community Detection
Louvain Community Detection
The Louvain algorithm optimizes modularity Q = sum over communities [e_c - (a_c)^2], where e_c is the fraction of edges within community c and a_c is the fraction of edge endpoints in c. The algorithm iteratively moves nodes between communities to maximize Q, then aggregates communities and repeats.
Contagion Propagation
Contagion Propagation
Contagion risk is modeled as a breadth-first propagation through the correlation graph. At each hop from the source, the shock is attenuated by the decay factor and scaled by the edge correlation. Markets reachable through multiple paths receive the maximum impact from any single path.