A primary model picks the side, a secondary model trained on "was the primary right" decides whether to act - raising precision, lowering recall, and paying for itself in costs. The trap is training the secondary on rows the primary was fitted on. TRIGGER - meta-labeling, metalabeling, meta labels, secondary model, primary model side, get_events side_prediction, bin in {0,1}, "should I take this signal", precision vs recall trade-off in trading, F1 of a trading model, filter model, trade filter, "my model has high recall but loses money", "how do I improve a strategy without changing its signal", Lopez de Prado chapter 3 section 3.6, AFML meta-labeling. SKIP for producing the triple-barrier labels and the `side` argument itself (triple-barrier-labeling), for turning the secondary's probability into a position size (bet-sizing), for the Kelly fraction (position-sizing-kelly), for purged cross-validation of either model (lib-purgedcv), and for which features matter (feature-importance-financial).
Ships in fin-ml. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Two models, two questions. The primary answers "long or short". The secondary answers "is the primary right this time", as a binary {0, 1} problem, from features about the state of the market rather than its direction. Advances in Financial Machine Learning (Lopez de Prado 2018), chapter 3, section 3.6. It is one of the few techniques that improves a strategy without touching its signal — and it has one failure mode that silently disables it.
The failure mode: the secondary must be trained on rows where the primary's prediction was out of sample. Fit the primary, predict on its own training rows, and those predictions are better than the primary can actually do. The meta-labels are then too optimistic, the secondary learns "act almost always", and you have added a component that filters nothing.
Every number below is printed by scripts/meta_labeling.py (numpy, seed 0, 2.9 s,
scikit-learn optional).
24,000 bars from a hidden two-state chain (P(stay) = 0.985, mean regime length 67 bars). In
state 1 momentum continues; in state 0 it reverses; state 0 is also the noisier one. ✅ Measured
realized volatility: 0.01584 in state 0 against 0.01150 in state 1 — so volatility is a real
but imperfect clue about which state you are in, which is exactly the kind of thing a secondary
model can learn and a directional model cannot use.
4,759 non-overlapping 5-bar bets, split into thirds: primary-train / meta-train / test. Bets
are spaced by the holding period on purpose — overlap is a separate problem with a separate fix
(../sample-weights-and-uniqueness/SKILL.md).
The primary is a logistic regression on the momentum feature plus 100 pure-noise columns. That is not a straw man: it is what every real primary model has — capacity beyond its signal — and it is the whole reason section 3 happens.
✅ The script's numpy IRLS logistic matches sklearn.linear_model.LogisticRegression(solver="lbfgs", C=1/ridge) to 2.8e-09 in predicted probability on the same standardised design, so the
dependency-free implementation is checked rather than assumed.
The positive class is "this bet was profitable". The primary alone acts on every signal, so its recall is 1.0 by construction and its precision is its hit rate. ✅ On the held-out third:
| precision | recall | F1 | bets taken | coverage | |
|---|---|---|---|---|---|
| primary alone | 0.6408 | 1.0000 | 0.7811 | 1,587 | 100.0 % |
| primary + meta | 0.7200 | 0.7483 | 0.7338 | 1,057 | 66.6 % |
✅ Precision +0.0791 (+12.3 % relative), recall -0.2517. The secondary turns 33 % of the signals into no-trades. That is the entire mechanism: it converts false positives into missed opportunities.
🚨 F1 goes DOWN (0.7811 → 0.7338), and that is fine. F1 weights precision and recall equally; a trader does not. A missed trade costs zero plus opportunity; a taken loser costs the loss plus the round trip. Do not select a meta model on F1 — select it on the after-cost objective in section 4. If you report F1 at all, report it next to coverage so the reader can see what was given up.
✅ Measured on the same data, changing one thing — the meta model is trained on the first third, where the primary's predictions were made in sample:
| on the test third | precision | recall | F1 | coverage |
|---|---|---|---|---|
| primary alone | 0.6408 | 1.0000 | 0.7811 | 100.0 % |
| primary + honest meta | 0.7200 | 0.7483 | 0.7338 | 66.6 % |
| primary + leaked meta | 0.6516 | 0.9381 | 0.7690 | 92.2 % |
🚨 The leaked secondary acts on 92.2 % of signals instead of 66.6 %, and its test precision is 0.0683 below the honest one — barely above the unfiltered primary's 0.6408. It was trained to believe the primary is right 70 % of the time, so it almost never says no. The component is present, it runs, it produces probabilities, and it does nothing.
🚨 Its higher F1 (0.7690 vs 0.7338) makes it look better. The leaked model wins on the metric people report and loses on the money.
✅ Annualised over the test third, cost charged on every bet actually taken:
| cost per bet | primary alone | primary + meta | primary + leaked meta |
|---|---|---|---|
| 0 bp | 3.312 | 3.468 | 3.346 |
| 5 bp | 3.252 | 3.432 | 3.291 |
| 20 bp | 3.071 | 3.320 | 3.125 |
| 50 bp | 2.710 | 3.092 | 2.793 |
✅ The threshold is a free parameter and it trades coverage against precision:
| threshold | coverage | precision | Sharpe @ 20 bp |
|---|---|---|---|
| 0.40 | 94.2 % | 0.6475 | 3.107 |
| 0.50 | 66.6 % | 0.7200 | 3.320 |
| 0.55 | 55.1 % | 0.7543 | 3.360 |
| 0.60 | 47.6 % | 0.8122 | 3.541 |
| 0.65 | 41.8 % | 0.8522 | 3.630 |
✅ A continuous size clip(2 * (p - 0.5), 0, 1) instead of a switch: Sharpe 3.433 at 20 bp
with a mean gross exposure of 0.317 — close to the best threshold's Sharpe on a third of the
capital deployed.
🚨 The threshold is a researcher degree of freedom. Five thresholds tried on the test set is
five trials; the table above is reported after the split precisely so it can be counted. Record
it in ../../../fin-core/skills/backtest-validation/scripts/trial_ledger.py. The sizing rule
itself belongs to ../bet-sizing/SKILL.md, and the Kelly fraction to
../../../fin-strategies/skills/position-sizing-kelly/SKILL.md.
../../../fin-libraries/skills/lib-purgedcv/SKILL.md) and label those. If the primary is a
fixed rule with no fitted parameters, this trap does not apply — but check that "no parameters"
is true, including the ones you chose by looking at the data.|momentum| and mean absolute return — all sign-free.fit_logistic
using training rows only and carries mu/sd to prediction time. A single
(X - X.mean()) / X.std() over the whole array before splitting leaks the test set's moments
into training. Check with
../../../fin-core/skills/signal-construction/scripts/assert_causal.py.../triple-barrier-labeling/SKILL.md, ../sample-weights-and-uniqueness/SKILL.md).get_events(side_prediction=...) path changes the label set. With side
supplied, get_bins returns bin in {0, 1} and forces a 0 whenever the realised return is
non-positive, whatever barrier was touched — ✅ source-verified in mlfinpy 0.1.2
(mlfinpy/labeling/labeling.py). A meta-label is "did this bet make money", not "which barrier".scripts/meta_labeling.py — the two-state generator, causal features, non-overlapping bets, a
numpy IRLS logistic regression checked against scikit-learn, the honest and leaked meta pipelines,
precision/recall/F1, Sharpe after costs at four levels, and the threshold/continuous-size sweep.
numpy only; sklearn is imported inside one function and the demo says so when it is missing.
Seed 0, 2.9 s.../triple-barrier-labeling/SKILL.md produces the side the primary supplies and the {0, 1}
meta-labels themselves. ../bet-sizing/SKILL.md turns the secondary's probability into a position
and owns averaging and discretisation.
../../../fin-strategies/skills/position-sizing-kelly/SKILL.md owns the Kelly fraction — this
skill does not repeat it. ../../../fin-libraries/skills/lib-purgedcv/SKILL.md owns the purged
cross-validation that produces honest primary predictions on overlapping labels.
../sample-weights-and-uniqueness/SKILL.md owns the weights once the bets do overlap.
../feature-importance-financial/SKILL.md owns which of the secondary's state features actually
matter. ../../../fin-core/skills/backtest-validation/SKILL.md owns the trial ledger for the
threshold.
What SKILL.md sets; muted values are Claude Code's defaults
7 skills in this plugin
/bet-sizingTurn a predicted probability into a position - the 2*Phi(z)-1 size curve, averaging concurrent bets instead of adding them, discretising to buy turnover, and the concurrency budget whose divisor is usually a look-ahead. TRIGGER - bet sizing, getSignal, get_signal, getBetSize, bet size from probability, avgActiveSignals, average active bets, discreteSignal, discrete signal, step size, position from predict_proba, "how big should this trade be", "my positions flip every bar", turnover from a probability, concurrent bets leverage, budgeting bets, Lopez de Prado chapter 10, AFML bet sizing. SKIP for the Kelly fraction and how large the book should be overall (position-sizing-kelly - it owns Kelly, do not repeat it), for the secondary model that produces the probability (meta-labeling), for volatility targeting and risk budgets (portfolio-and-risk), and for the execution schedule once the size is chosen (execution-algorithms)./feature-importance-financialRank features without believing MDI - it is in-sample, it favours columns with many distinct values, and it splits credit between substitutable features; MDA under-states collinear pairs and leaks outright on a shuffled k-fold. TRIGGER - feature_importances_, feature importance, MDI, mean decrease impurity, Gini importance, MDA, mean decrease accuracy, permutation importance, permutation_importance, single feature importance, SFI, clustered feature importance, "which features matter", "my random forest says this random column is important", "importance changes every run", correlated features importance, substitution effect, Lopez de Prado chapter 8, AFML feature importance. SKIP for purged and embargoed cross-validation itself (lib-purgedcv), for the overlapping-label weights (sample-weights-and-uniqueness), for feature construction and causality (signal-construction), for factor-return attribution (factor-models), and for the trials a feature search spends (backtest-validation)./fractional-differentiationMake a price series stationary without throwing away the memory a model needs - the weight recursion, the fixed-width window, and the scan for the smallest d that passes ADF. TRIGGER - fractional differentiation, fractional differencing, fracdiff, frac_diff, frac_diff_ffd, get_weights_ffd, plotMinFFD, plot_min_ffd, "minimum d", ARFIMA, long memory, (1-B)^d, binomial weights, fixed-width window fracdiff; "my model only sees returns", "prices are non-stationary so I differenced them", "ADF says my feature is non-stationary", "should I feed prices or returns to the model", Lopez de Prado chapter 5, AFML fracdiff. SKIP for the cointegration ADF table and the fitted-residual null (stat-arb-cointegration), for unit-root and ARIMA model selection generally (time-series-forecasting-models), for making a feature causal and its warm-up (signal-construction), and for labels rather than features (triple-barrier-labeling)./sample-weights-and-uniquenessOverlapping labels are not independent observations - compute concurrency, average uniqueness and return-attributed weights, and divide your t-statistics by the overlap factor before believing any of them. TRIGGER - sample weights, average uniqueness, concurrency, overlapping labels, numCoEvents, num_concurrent_events, getAvgUniqueness, tW, sample_weight in fit(), getWeightsByReturn, get_weights_by_return, time decay weights, getTimeDecay, sequential bootstrap, seq_bootstrap, indicator matrix, effective sample size, "my labels overlap", "my t-stat is 4 but it does not hold up", "overlapping forward returns", Lopez de Prado chapter 4, AFML sample weights. SKIP for purged and embargoed cross-validation of the same labels (lib-purgedcv owns it, do not re-implement), for producing the labels and their t1 touch times (triple-barrier-labeling), for feature importance under overlap (feature-importance-financial), and for Sharpe deflation (backtest-validation)./structural-breaksSample events with the symmetric CUSUM filter instead of on a clock, and test for explosive behaviour with SADF instead of one full-sample ADF that has no power against a bubble in part of the sample. TRIGGER - CUSUM filter, cusum_filter, symmetric CUSUM, event-based sampling, t_events, event sampling for labels, SADF, supremum ADF, sup ADF, get_sadf, BSADF, backward SADF, Phillips-Shi-Yu, explosiveness test, bubble detection, structural break test, Chow test, "how do I pick the bars to label", "my ADF says nothing but the chart is obviously a bubble", "when did the regime change", Lopez de Prado chapter 17, AFML structural breaks. SKIP for labelling the events once they are sampled (triple-barrier-labeling), for making a feature stationary (fractional-differentiation), for the cointegration ADF table (stat-arb-cointegration), for hidden-state / volatility regime labels (regime-detection), and for unit-root and ARIMA selection generally (time-series-forecasting-models)./triple-barrier-labelingLabel a trade by which of profit-taking, stop loss and the holding-period limit is hit FIRST, with barriers scaled to the volatility at the event - instead of by the sign of the return N bars later, which describes a path you would have been stopped out of. TRIGGER - triple barrier, triple-barrier method, getEvents, get_events, getBins, get_bins, barrier_touched, add_vertical_barrier, pt_sl, vertical barrier, t1 touch time, getDailyVol, get_daily_vol, meta-label 0/1, fixed-time horizon labeling, fixed horizon labels, "label = sign of the 5-day forward return", "my classifier is 90 % accurate but loses money", "how do I label financial data for ML", Lopez de Prado chapter 3, AFML labeling. SKIP for weighting the overlapping labels (sample-weights-and-uniqueness), for cross-validating them (lib-purgedcv), for the secondary model (meta-labeling), for the CUSUM event sampler (structural-breaks), and for stationary features (fractional-differentiation)./fin-ml:meta-labelingfrom fin-ml
npx claudepluginhub howard-lynn-ye/fin-rsi --plugin fin-mlOther plugins' skills for the same job