Stock Market Hedging
Prediction market positions often correlate with traditional financial assets. A trader long “Will the Fed cut rates?” can hedge with bond ETFs (TLT) or rate-sensitive stocks. Horizon’s hedge module covers ratio calculation, effectiveness tracking, multi-ticker optimization, and automated rebalancing. All math is in Rust.Overview
OLS Hedge Ratio
hz.hedge_ratio_ols() computes the hedge ratio from rolling price windows.Effectiveness & Basis Risk
hz.hedge_effectiveness() and hz.basis_risk() measure how well the hedge is working.Multi-Ticker Optimization
hz.multi_ticker_hedge() finds weights across multiple hedge instruments.Scenario Analysis
hz.hedge_scenario() shows portfolio P&L under different spot moves.Core Functions
All math runs in Rust. Every output is guarded against NaN/Inf.hz.hedge_ratio_ols
Compute the hedge ratio: h* = Cov(dS, dF) / Var(dF).| Parameter | Type | Default | Description |
|---|---|---|---|
spot_prices | list[float] | required | Prediction market price series |
hedge_prices | list[float] | required | Stock/ETF price series |
window | int | 60 | Rolling window size for return calculation |
hz.rolling_correlation
Rolling Pearson correlation between two price series.| Parameter | Type | Default | Description |
|---|---|---|---|
series_a | list[float] | required | First price series |
series_b | list[float] | required | Second price series |
window | int | 60 | Rolling window size |
hz.hedge_effectiveness
Hedge effectiveness: HE = 1 − Var(hedged) / Var(unhedged). Values close to 1.0 indicate a good hedge.| Parameter | Type | Description |
|---|---|---|
spot_returns | list[float] | Spot instrument return series |
hedge_returns | list[float] | Hedge instrument return series |
hedge_ratio | float | Hedge ratio (from hedge_ratio_ols) |
hz.basis_risk
Residual variance after hedging. Lower is better.| Parameter | Type | Description |
|---|---|---|
spot_returns | list[float] | Spot instrument return series |
hedge_returns | list[float] | Hedge instrument return series |
hedge_ratio | float | Hedge ratio |
hz.optimal_hedge_size
Calculate optimal hedge notional with optional cap.| Parameter | Type | Default | Description |
|---|---|---|---|
spot_notional | float | required | Notional value of the spot position |
hedge_ratio | float | required | Hedge ratio |
max_hedge_notional | float | inf | Maximum hedge notional cap |
hz.compute_hedge_sensitivities
Returns aHedgeSensitivities object with risk metrics.
| Field | Description |
|---|---|
delta | dV/dS via finite differences |
cross_gamma | d²V/dSdF cross-gamma |
beta | OLS beta of hedge on spot |
tracking_error | Annualized std(residuals) × √252 |
hedge_decay | Drift of recent hedge ratio from full-window ratio |
hz.multi_ticker_hedge
Multi-instrument hedge optimization. Returns aMultiHedgeResult.
| Parameter | Type | Description |
|---|---|---|
spot_returns | list[float] | Spot instrument return series |
hedge_returns_matrix | list[list[float]] | Return series for each hedge instrument |
tickers | list[str] | Ticker labels for each hedge instrument |
hz.hedge_scenario
P&L projection under a given spot move.| Parameter | Type | Default | Description |
|---|---|---|---|
spot_position | float | required | Number of spot contracts |
spot_price | float | required | Current spot price |
hedge_position | float | required | Number of hedge shares (negative = short) |
hedge_price | float | required | Current hedge instrument price |
spot_move_pct | float | required | Spot move as decimal (e.g., -0.10 for -10%) |
correlation | float | 0.75 | Assumed correlation between spot and hedge |
hedge_vol | float | 0.20 | Annualized hedge volatility |
spot_vol | float | 0.30 | Annualized spot volatility |
Pipeline Functions
These functions return callables for use insidehz.run() pipelines. Call the factory to configure, get back a function you can put in the pipeline list.
hz.hedge_monitor
Computes hedge metrics each cycle. Returns a dict passed to the next pipeline stage.| Parameter | Type | Default | Description |
|---|---|---|---|
prediction_feed | str | required | Feed name for the prediction market |
stock_feed | str | required | Feed name for the hedge instrument |
window | int | 60 | Rolling window for calculations |
hz.hedge_executor
Monitors hedge drift and flags rebalancing. Withauto_rebalance=True, generates OrderRequest objects for Alpaca.
hz.correlation_tracker
Track pairwise correlations across multiple feeds.| Parameter | Type | Default | Description |
|---|---|---|---|
feeds | list[str] | required | Feed names to track |
window | int | 60 | Rolling correlation window |
hz.stock_hedge
Combineshedge_monitor + hedge_executor. Use this if you want both in one call.
Standalone Analysis
These functions run outsidehz.run() for research and one-off analysis.
hz.compute_hedge_report
Returns a full hedge report as a dictionary.| Parameter | Type | Default | Description |
|---|---|---|---|
spot_prices | list[float] | required | Spot price series |
hedge_prices | list[float] | required | Hedge price series |
window | int | 60 | Rolling window |
position_size | float | 1.0 | Position size for sensitivity calculation |
hz.run_scenario
Run multiple scenarios at once:Cost Tracking
TheHedgeCostTracker tracks cumulative rebalancing costs:
Examples
Basic Hedge Ratio Calculation
Multi-Ticker Portfolio Hedge
Scenario Analysis
Hedged Pipeline Strategy
Mathematical Background
Minimum-Variance Hedge Ratio
Minimum-Variance Hedge Ratio
The OLS hedge ratio minimizes the variance of the hedged portfolio:h = Cov(dS, dF) / Var(dF)*Where dS and dF are log returns of the spot and hedge instruments. This is the slope from regressing spot returns on hedge returns. The ratio is recomputed over a rolling window so it adjusts as correlations shift.
Hedge Effectiveness
Hedge Effectiveness
Hedge effectiveness measures how much variance the hedge removes:HE = 1 − Var(hedged) / Var(unhedged)Where hedged return = spot return − h × hedge return. Values near 1.0 mean the hedge is working well. Values below 0.5 mean the hedge instrument is a poor match for the spot position.
Multi-Ticker Optimization
Multi-Ticker Optimization
For multiple hedge instruments, the weight vector is:w = Σ_FF⁻¹ × Σ_FSWhere Σ_FF is the covariance matrix of hedge returns and Σ_FS is the cross-covariance vector between hedge and spot returns. Solved via Cholesky decomposition, with fallback to diagonal solve when the matrix is near-singular.
Scenario Analysis Model
Scenario Analysis Model
P&L under a hypothetical spot move:
- Spot P&L = position × price × move
- Hedge move = correlation × (spot_vol / hedge_vol) × spot_move
- Hedge P&L = hedge_position × hedge_price × hedge_move
- Portfolio P&L = Spot P&L + Hedge P&L
- Hedge benefit = Portfolio P&L − Unhedged P&L