Portable Alpha
A strategy can appear profitable when it is just riding market beta. Horizon’s portable alpha module decomposes returns into alpha (skill) and beta (market exposure), tracks factor betas incrementally, and calculates the hedge ratios needed to neutralize unwanted exposures. All regression math is in Rust.Overview
Beta Decomposition
hz.beta_decompose() separates alpha from market exposure via OLS.Factor Exposures
hz.compute_factor_exposures() computes betas across multiple factors.Neutrality Adjustment
hz.neutrality_adjustment() calculates hedge ratios to reach target betas.Incremental Beta
hz.incremental_beta_update() tracks beta in O(1) per cycle via EWMA.Core Functions
hz.beta_decompose
Decompose portfolio returns into alpha + beta * factor returns via OLS.| Parameter | Type | Description |
|---|---|---|
portfolio_returns | list[float] | Portfolio return series |
factor_returns | list[float] | Factor/benchmark return series |
AlphaDecomposition with fields: alpha, beta, r_squared, tracking_error, information_ratio.
hz.compute_factor_exposures
Multi-factor regression: compute betas across multiple factors.hz.neutrality_adjustment
Calculate hedge ratios needed to reach target betas.hz.incremental_beta_update
O(1) EWMA-based beta tracking. No need to store full history.| Parameter | Type | Description |
|---|---|---|
prev_cov | float | Previous EWMA covariance |
prev_var | float | Previous EWMA variance |
portfolio_return | float | Latest portfolio return |
factor_return | float | Latest factor return |
decay | float | EWMA decay factor (e.g. 0.94) |
Pipeline Functions
hz.beta_decompose_pipeline
Decompose returns into alpha + beta each cycle.| Parameter | Type | Default | Description |
|---|---|---|---|
portfolio_feed | str | required | Feed name for portfolio |
factor_feed | str | required | Feed name for factor/benchmark |
window | int | 50 | Rolling window for OLS |
hz.market_neutral
Track live beta and calculate hedge ratios for neutrality.| Parameter | Type | Default | Description |
|---|---|---|---|
portfolio_feed | str | required | Portfolio feed |
factor_feed | str | required | Factor feed |
target_beta | float | 0.0 | Target beta exposure |
tolerance | float | 0.05 | Acceptable deviation from target |
decay | float | 0.94 | EWMA decay factor |
hz.portable_alpha
Full multi-factor portable alpha with exposure tracking and adjustment signals.hz.factor_model
Track factor betas incrementally (O(1) per cycle).Examples
Market-Neutral Strategy
Mathematical Background
OLS Beta Decomposition
OLS Beta Decomposition
For portfolio returns R_p and factor returns R_f:R_p = alpha + beta * R_f + epsilonBeta = Cov(R_p, R_f) / Var(R_f). Alpha is the intercept (excess return after removing factor exposure). R-squared measures the fraction of variance explained by the factor.
EWMA Incremental Beta
EWMA Incremental Beta
Instead of storing full history, use exponentially weighted moving averages:
cov_t = decay * cov_{t-1} + (1 - decay) * R_p * R_fvar_t = decay * var_{t-1} + (1 - decay) * R_f^2beta_t = cov_t / var_tWith decay = 0.94 (approx 15-day half-life), recent observations matter more. This runs in O(1) per update.Neutrality Adjustment
Neutrality Adjustment
To reach target beta from current beta:hedge_ratio = -(current_beta - target_beta)A positive hedge_ratio means add long factor exposure; negative means short it.