Pro Feature. Requires a Pro or Ultra subscription. Get started at api.mathematicalcompany.com
Volatility Signature
Horizon provides Rust-native tools for analyzing microstructure noise in prediction market tick data. The volatility signature plot reveals how realized volatility estimates vary with sampling frequency, enabling you to separate true volatility from market noise and find the optimal sampling interval.Signature Plot
Realized volatility at multiple sampling frequencies. Visualize the noise-to-signal transition.
Two-Scale Realized Vol
Zhang-Mykland-Ait-Sahalia estimator. Bias-corrected volatility robust to microstructure noise.
Noise Variance
Estimate the variance of microstructure noise from the autocovariance of returns.
Optimal Sampling
Find the sampling frequency that minimizes total estimation error (bias + variance).
hz.volatility_signature
Compute realized volatility at multiple sampling frequencies to produce a volatility signature plot. At very high frequencies, microstructure noise inflates the estimate. At very low frequencies, estimation variance increases. The signature plot reveals both effects.| Parameter | Type | Default | Description |
|---|---|---|---|
prices | list[float] | required | Tick prices |
timestamps | list[float] | required | Tick timestamps (same length as prices) |
max_interval | int | None | Maximum sampling interval to test. None = len(prices) / 4. |
annualize | bool | True | Multiply by sqrt(365) |
SignaturePlot Type
| Field | Type | Description |
|---|---|---|
intervals | list[int] | Sampling intervals tested (1, 2, 3, …, max_interval) |
volatilities | list[float] | Realized volatility at each sampling interval |
optimal_interval | int | Interval where the signature plot flattens (noise becomes negligible) |
noise_ratio | float | Estimated ratio of noise variance to total variance at interval=1 |
hz.two_scale_realized_vol
The Zhang-Mykland-Ait-Sahalia (2005) Two-Scale Realized Volatility (TSRV) estimator. Combines a fast-scale (tick-by-tick) and slow-scale (subsampled) estimator to cancel out microstructure noise bias.| Parameter | Type | Default | Description |
|---|---|---|---|
prices | list[float] | required | Tick prices (at least 10 observations) |
n_slow | int | 5 | Slow-scale subsampling factor. Higher = more noise cancellation, less efficiency. |
annualize | bool | True | Multiply by sqrt(365) |
float: the bias-corrected realized volatility estimate.
TSRV is the recommended estimator when you suspect microstructure noise in your tick data. It converges at rate
n^(-1/6) even in the presence of noise, versus n^(0) for standard realized volatility (which does not converge at all when noise is present).hz.noise_variance_estimate
Estimate the variance of microstructure noise from the first-order autocovariance of high-frequency returns. Under standard noise models, the noise variance equals the negative of the first autocovariance.| Parameter | Type | Description |
|---|---|---|
prices | list[float] | Tick prices (at least 3 observations) |
float: estimated noise variance. Returns 0.0 if the autocovariance is positive (indicating no noise or trending behavior).
hz.optimal_sampling_frequency
Find the sampling frequency that minimizes the total mean squared error of the realized volatility estimator. This balances the bias from microstructure noise (dominant at high frequencies) against the estimation variance (dominant at low frequencies).| Parameter | Type | Description |
|---|---|---|
prices | list[float] | Tick prices |
timestamps | list[float] | Tick timestamps |
int: the optimal number of ticks between samples for realized volatility estimation.
The optimal frequency depends on the noise-to-signal ratio. Noisier markets (e.g., illiquid prediction markets with wide spreads) require lower sampling frequencies. The formula follows Bandi-Russell (2008):
n_opt ~ (noise_var / integrated_quarticity)^(1/3) * T^(2/3).Pipeline Integration
hz.vol_signature_analyzer
Creates a pipeline function that computes the volatility signature and TSRV from a feed and injects microstructure statistics intoctx.params.
| Parameter | Type | Default | Description |
|---|---|---|---|
feed | str | None | Feed name to read prices from. None = first available. |
lookback | int | 500 | Number of ticks to retain for analysis |
max_interval | int | 20 | Maximum sampling interval for signature plot |
n_slow | int | 5 | Slow-scale factor for TSRV |
annualize | bool | True | Annualize volatility estimates |
param_name | str | "vol_sig" | Key in ctx.params |
Injected Parameters
| Key | Type | Description |
|---|---|---|
ctx.params["vol_sig"]["tsrv"] | float | Two-scale realized volatility estimate |
ctx.params["vol_sig"]["noise_variance"] | float | Estimated microstructure noise variance |
ctx.params["vol_sig"]["noise_ratio"] | float | Noise variance / total variance at tick frequency |
ctx.params["vol_sig"]["optimal_interval"] | int | Optimal sampling interval |
ctx.params["vol_sig"]["rv_tick"] | float | Standard realized vol at tick frequency (noise-contaminated) |
Example: Microstructure Analysis
Mathematical Background
Volatility Signature Plot
Volatility Signature Plot
The signature plot computes realized volatility
RV(delta) = sum of squared returns at sampling interval delta. In the absence of noise, RV(delta) is approximately constant for all delta. In the presence of microstructure noise, RV(delta) is inflated at small delta (high frequency) due to the noise term 2 * n * noise_var, where n is the number of returns. The plot should flatten as delta increases past the noise-dominated region.Two-Scale Realized Volatility
Two-Scale Realized Volatility
TSRV combines two estimators:
- Fast scale (all ticks):
RV_fast = sum(r_i^2), biased upward by noise - Slow scale (subsampled):
RV_slow = (1/K) * sumover K subgrids of subsampled RV
TSRV = RV_slow - (n_bar / n) * RV_fast, where n_bar is the average subsample size. The noise terms cancel, yielding a consistent estimator.Noise Variance Estimation
Noise Variance Estimation
Under the model:
observed_price = true_price + noise, where noise is i.i.d., the first-order autocovariance of returns equals negative noise_var. This follows because noise creates negative serial correlation in returns (a positive noise shock is partially reversed in the next return). The estimator: noise_var = -Cov(r_t, r_(t+1)).