Pro Feature. Requires a Pro or Ultra subscription. Get started at api.mathematicalcompany.com
Microstructure Invariance
Horizon implements the Kyle-Obizhaeva (2016) microstructure invariance framework. The invariance hypothesis states that the distribution of risk transferred per bet, measured in units of business time, is constant across markets and time periods. This provides a model-free approach to estimating natural bet sizes, market impact, and detecting informed trading. All computation runs in Rust via PyO3.Trading Activity
Estimate the rate of bet arrivals from volume, volatility, and price data.
Invariant Bet Size
Compute the natural bet size implied by the invariance hypothesis.
Market Impact
Kyle-Obizhaeva square-root impact model calibrated from trading activity.
Informed Trade Detection
Flag trades whose size exceeds the invariant bet size threshold.
Why Invariance?
Traditional market impact models require calibration to specific venues. The invariance hypothesis provides a universal scaling law: markets that differ in volume, volatility, and tick size all share the same distribution of bets when measured in the right units. This means you can estimate impact and detect informed trading without venue-specific calibration. The key scaling relationships are:- Trading activity:
gamma = volume * volatility / price(dollar-risk per unit time) - Invariant bet size:
V* = volume / (gamma^(2/3))(natural trade size) - Impact coefficient:
lambda ~ gamma^(1/3)(Kyle’s lambda from invariance)
Invariance is especially useful in prediction markets where historical calibration data is sparse. The framework transfers impact estimates from liquid markets to illiquid ones through the universal scaling law.
API
hz.trading_activity
Compute the Kyle-Obizhaeva trading activity measure (gamma) from market observables.
Returns
float: the trading activity measure gamma.
hz.invariant_bet_size
Compute the natural bet size implied by the invariance hypothesis.
Returns
float: the invariant bet size in contracts.
hz.kyle_obizhaeva_impact
Estimate price impact using the Kyle-Obizhaeva square-root model. Impact scales aslambda * sqrt(size / V*) where lambda is derived from trading activity.
Returns
float: estimated price impact in price units.
hz.is_informed_trade
Test whether a trade size exceeds a multiple of the invariant bet size, flagging potential informed trading.
Returns
bool.
hz.invariance_analysis
Run a complete invariance analysis, returning all derived quantities in a single call.InvarianceResult Type
Pipeline Integration
hz.invariance_monitor
Pipeline function that computes invariance metrics each cycle and injects them intoctx.params["invariance"].
ctx.params["invariance"] dict contains:
Mathematical Background
The Invariance Hypothesis
The Invariance Hypothesis
Kyle and Obizhaeva (2016) propose that the distribution of a “bet” — a portfolio decision by an informed trader — is invariant across markets and time when measured in business time. Business time is defined by trading activity gamma = sigma * V / P, where sigma is volatility, V is volume, and P is price.The key predictions are:
- Bet size scales as
V * gamma^(-2/3) - Number of bets per period scales as
gamma^(2/3) - Price impact per bet scales as
gamma^(1/3)
Square-Root Impact
Square-Root Impact
The Kyle-Obizhaeva impact model predicts that temporary price impact scales as the square root of trade size normalized by the invariant bet size:
Delta_P = lambda * sigma * sqrt(Q / V*)where lambda is a universal constant (approximately 1), sigma is volatility, Q is trade size, and V* is the invariant bet size. The square-root law arises from the assumption that informed traders optimally split their bets.Informed Trade Detection
Informed Trade Detection
Under invariance, the natural trade size V* represents the equilibrium bet of an informed trader. Trades significantly larger than V* (e.g., 2-3x) are unlikely to come from informed traders optimally splitting orders. Instead they suggest either: (1) highly informed traders with very short-lived information, or (2) uninformed institutional flow. Both cases warrant wider spreads.