Pro Feature. Requires a Pro or Ultra subscription. Get started at api.mathematicalcompany.com
Alpha Research
Horizon ships four pure-Python research modules inspired by Lopez de Prado’s Advances in Financial Machine Learning. Use them standalone for offline analysis or drop their pipeline functions intohz.run() for live monitoring.
Meta-Labeling
Triple-barrier labeling: primary model gives direction, meta-label model decides sizing.
Feature Importance
MDA, SFI, and clustered MDA with purged cross-validation to prevent leakage.
Alpha Decay
Track information coefficient over time, estimate half-life, detect dying edges.
PnL Attribution
Break down returns by market, time period, and factor exposure.
Meta-Labeling (AFML Ch. 3)
A two-model framework. The primary model predicts direction (+1 long, -1 short). The meta-label model then decides whether to act on that signal (1) or abstain (0), using a triple-barrier method: profit-taking, stop-loss, and a vertical (time) barrier. This separation lets you use a high-recall primary model (catches most opportunities) and a high-precision meta-label model (filters out bad trades), which is far more effective than trying to build a single model that does both.compute_meta_labels
Compute meta-labels from primary model signals using triple barriers. For each primary signal, scans forward from the signal index and applies three barriers:- Profit-taking (PT): Return exceeds
vol * pt_sl[0]in the direction of the primary signal. Meta-label = 1 (act). - Stop-loss (SL): Return exceeds
vol * pt_sl[1]against the primary signal. Meta-label = 0 (abstain). - Vertical barrier:
max_holdingbars elapse with no barrier hit. Meta-label = 1 if cumulative return > 0, else 0.
Parameters
Returns
List ofMetaLabel objects.
MetaLabel
meta_label_pipeline
Pipeline function forhz.run(). Reads the primary model’s signal from ctx.params, maintains a rolling buffer of price observations, and injects meta-label decisions.
Parameters
Injected into ctx.params
If the primary signal is 0 or missing, the pipeline passes through with
meta_label=0 and meta_confidence=0.0.Feature Importance (AFML Ch. 8)
Model-agnostic feature importance methods with purged cross-validation. Standard k-fold CV leaks information in time-series data because adjacent samples are correlated. Purged CV removes training samples within a configurable gap of each test fold, preventing look-ahead bias. All methods accept a genericscore_fn(X_train, y_train, X_test, y_test) -> float so they work with any model (sklearn, xgboost, a simple function, etc.).
mda_importance
Mean Decrease Accuracy (permutation importance). For each CV fold, computes a baseline test score, then shuffles each feature column individually and re-scores. Importance = mean decrease in score caused by shuffling.Parameters
Returns
List ofFeatureImportance sorted by importance descending.
sfi_importance
Single Feature Importance (AFML Ch. 8.6). Trains the model on each feature individually and evaluates via cross-validation. The importance of a feature is its cross-validated score when used as the sole predictor.Parameters
Returns
List ofFeatureImportance sorted by importance descending.
clustered_mda
Clustered Feature Importance (AFML Ch. 8.7). Groups features by correlation using agglomerative clustering (distance = 1 - |correlation|), then permutes entire clusters at once. When one feature in a correlated group is shuffled, the model can compensate by using the remaining correlated features. Shuffling the entire cluster eliminates this substitution effect, giving a more accurate picture of the group’s true importance.Parameters
Returns
List ofFeatureImportance, one per cluster. The feature field contains comma-separated names of features in that cluster. Sorted by importance descending.
FeatureImportance
Alpha Decay Tracking
Monitor whether your trading edge is dying. TheAlphaDecayTracker computes rolling IC (Spearman rank correlation between predictions and outcomes), estimates half-life via AR(1) fit, and detects negative trend via linear regression on the IC series.
AlphaDecayTracker
Stateful tracker that accumulates predictions and outcomes over time.Constructor Parameters
update()
Add a new batch of predictions/outcomes and compute the report.
Returns
AlphaDecayReport if enough data has accumulated (at least window // 2 observations), None otherwise.
report()
Force compute the current alpha decay state. ReturnsAlphaDecayReport regardless of data size.
AlphaDecayReport
alpha_decay_pipeline
Pipeline function forhz.run(). Uses predictions from ctx.params["predictions"] and outcomes derived from fills to track alpha decay in real time.
Parameters
Injected into ctx.params
The pipeline logs a warning when
is_decaying transitions from False to True, including the current IC, trend slope, and half-life.PnL Attribution
Break down portfolio PnL by market, time period, and factor exposure to understand where returns come from.attribute_pnl
Extract positions from an engine and compute per-market PnL breakdown. Results are sorted by absolute PnL descending.Parameters
Returns
AttributionReport with by_market populated.
attribute_by_time
Group fills by time period and compute PnL per period.Parameters
Returns
List ofTimeBreakdown sorted chronologically.
attribute_by_factor
Factor-based PnL attribution. Maps positions to factors via exposure weights and computes each factor’s PnL contribution and R-squared.Parameters
Returns
List ofFactorBreakdown, one per factor.
pnl_attribution_pipeline
Pipeline function forhz.run() that adds attribution data each cycle.