Pro Feature. Requires a Pro or Ultra subscription. Get started at api.mathematicalcompany.com
Characteristic Function Pricing
Prediction market contracts are binary options: they pay 1 dollar if an event occurs and 0 otherwise. Standard Black-Scholes assumes log-normal returns, which ignores volatility smiles, jumps, and fat tails. Horizon implements three stochastic models that capture these features via characteristic function inversion: Heston (stochastic volatility), Merton (jump-diffusion), and Variance Gamma (pure-jump). All numerical integration and root-finding runs in Rust.Heston Model
Stochastic volatility with mean reversion. Captures volatility smiles and term structure.
Merton Jump-Diffusion
Diffusion plus Poisson jumps. Captures sudden event-driven moves.
Variance Gamma
Pure-jump process with no diffusion component. Captures skewness and excess kurtosis.
Implied Volatility
hz.implied_vol_from_binary() backs out the implied volatility from an observed binary price.Model Parameters
HestonParams
Parameters for the Heston stochastic volatility model.| Field | Type | Description |
|---|---|---|
v0 | float | Initial instantaneous variance |
kappa | float | Mean reversion speed of variance (must be positive) |
theta | float | Long-run variance level (must be positive) |
sigma | float | Volatility of variance (vol of vol, must be positive) |
rho | float | Correlation between asset returns and variance (-1 to 1) |
The Feller condition 2 * kappa * theta > sigma^2 ensures variance stays positive. If violated, the variance process can hit zero, which is handled numerically but may produce less reliable prices.
MertonParams
Parameters for the Merton jump-diffusion model.| Field | Type | Description |
|---|---|---|
sigma | float | Diffusion volatility (continuous component) |
jump_intensity | float | Poisson intensity (expected number of jumps per year) |
jump_mean | float | Mean of log-normal jump size distribution |
jump_vol | float | Standard deviation of log-normal jump size distribution |
VGParams
Parameters for the Variance Gamma model.| Field | Type | Description |
|---|---|---|
sigma | float | Volatility of the subordinated Brownian motion |
theta | float | Drift of the subordinated Brownian motion (negative = left skew) |
nu | float | Variance rate of the gamma subordinator (larger = fatter tails) |
Pricing Functions
hz.binary_price_heston
Price a binary option under the Heston stochastic volatility model.hz.binary_price_merton
Price a binary option under the Merton jump-diffusion model.hz.binary_price_vg
Price a binary option under the Variance Gamma model.Common Parameters
All three pricing functions share these parameters:| Parameter | Type | Description |
|---|---|---|
params | model params | HestonParams, MertonParams, or VGParams |
s0 | float | Current underlying price or probability |
strike | float | Binary strike level (contract pays 1 if S_T >= strike) |
t | float | Time to expiry in days |
r | float | Risk-free rate (annualized). Use 0.0 for prediction markets |
BinaryPrice Type
| Field | Type | Description |
|---|---|---|
price | float | Fair value of the binary option (0 to 1) |
delta | float | Sensitivity to underlying price (dPrice/dS) |
vega | float | Sensitivity to volatility (dPrice/dSigma) |
model | str | Model name: "heston", "merton", or "vg" |
hz.implied_vol_from_binary
Back out the implied volatility from an observed binary option price using Brent’s root-finding method.| Parameter | Type | Description |
|---|---|---|
observed_price | float | Observed market price of the binary option |
s0 | float | Current underlying price |
strike | float | Binary strike level |
t | float | Time to expiry in days |
float: the annualized implied volatility. Returns NaN if root-finding fails to converge.
Comparing Models
Pipeline Integration
Thehz.pricing_signal() pipeline function computes model-implied fair values each cycle and injects them into ctx.params["pricing"].
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
feed | str | required | Feed name to read the current price from |
model | str | "heston" | Pricing model: "heston", "merton", or "vg" |
params | model params | required | Model parameters (HestonParams, MertonParams, or VGParams) |
strike | float | 0.50 | Binary strike level |
horizon_days | float | 30.0 | Time to expiry in days |
Mathematical Background
Characteristic Function Inversion
Characteristic Function Inversion
A binary option price is P(S_T >= K) under the risk-neutral measure. This probability can be recovered from the characteristic function phi(u) of log(S_T) via the Gil-Pelaez inversion formula:P(S_T >= K) = 0.5 + (1/pi) * integral_0^inf Re[exp(-iu*ln(K)) * phi(u) / (iu)] duEach model provides a closed-form characteristic function, and the integral is evaluated numerically using adaptive Gauss-Kronrod quadrature in Rust.
Heston Model
Heston Model
The Heston (1993) model specifies:dS/S = mu*dt + sqrt(V)dW_1
dV = kappa(theta - V)dt + sigmasqrt(V)*dW_2
corr(dW_1, dW_2) = rhoThe characteristic function has a known closed form involving complex logarithms. Negative rho (the typical case) produces a left-skewed return distribution, matching the empirical observation that large downward moves are accompanied by volatility spikes.
Merton Jump-Diffusion
Merton Jump-Diffusion
The Merton (1976) model adds compound Poisson jumps to geometric Brownian motion:dS/S = mudt + sigmadW + (e^J - 1)*dNwhere N is a Poisson process with intensity lambda, and J ~ Normal(mu_J, sigma_J^2). The characteristic function decomposes into a diffusion part and a jump part, each with a closed form. This model is useful when prediction markets experience sudden, discrete price moves (e.g., breaking news).
Variance Gamma
Variance Gamma
The Variance Gamma (Madan, Carr, Chang 1998) model is a pure-jump process constructed by subordinating a Brownian motion with drift by a gamma process:X(t) = thetaG(t) + sigmaW(G(t))where G(t) is a gamma process with unit mean rate and variance rate nu. The VG model has three parameters controlling volatility (sigma), skewness (theta), and kurtosis (nu). It produces return distributions with heavier tails than normal and can capture the empirical observation that prediction market returns are leptokurtic.