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.| Parameter | Type | Description |
|---|---|---|
volume | float | Trading volume over the period (positive) |
volatility | float | Return volatility over the same period (positive) |
price | float | Current market price (positive) |
float: the trading activity measure gamma.
hz.invariant_bet_size
Compute the natural bet size implied by the invariance hypothesis.| Parameter | Type | Description |
|---|---|---|
volume | float | Trading volume over the period (positive) |
volatility | float | Return volatility over the same period (positive) |
price | float | Current market price (positive) |
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.
| Parameter | Type | Description |
|---|---|---|
size | float | Trade size to evaluate (positive) |
volume | float | Trading volume over the period (positive) |
volatility | float | Return volatility (positive) |
price | float | Current market price (positive) |
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.| Parameter | Type | Description |
|---|---|---|
size | float | Observed trade size (positive) |
volume | float | Trading volume over the period (positive) |
volatility | float | Return volatility (positive) |
price | float | Current market price (positive) |
threshold | float | Multiple of invariant bet size to flag (default: 2.0) |
bool.
hz.invariance_analysis
Run a complete invariance analysis, returning all derived quantities in a single call.| Parameter | Type | Description |
|---|---|---|
volume | float | Trading volume (positive) |
volatility | float | Return volatility (positive) |
price | float | Current market price (positive) |
trade_size | float | Trade size to evaluate (positive) |
InvarianceResult Type
| Field | Type | Description |
|---|---|---|
trading_activity | float | Kyle-Obizhaeva gamma measure |
invariant_bet_size | float | Natural bet size V* in contracts |
impact_coefficient | float | Kyle’s lambda from invariance scaling |
expected_impact | float | Estimated price impact for the given trade size |
size_ratio | float | trade_size / invariant_bet_size |
is_informed | bool | Whether size_ratio exceeds 2.0 |
Pipeline Integration
hz.invariance_monitor
Pipeline function that computes invariance metrics each cycle and injects them intoctx.params["invariance"].
ctx.params["invariance"] dict contains:
| Key | Type | Description |
|---|---|---|
trading_activity | float | Current gamma measure |
invariant_bet_size | float | Current V* estimate |
impact_coefficient | float | Kyle’s lambda |
expected_impact | float | Impact for a 1x V* trade |
is_informed | bool | Whether recent flow exceeds 2x V* |
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.