Module 22 · Advanced

A machine-learning early-warning layer

VaR tells you how much you could lose if a position moves against you. It doesn't tell you whichpositions are about to. That's a pattern-recognition problem — and it's exactly what a machine-learning layer adds on top of the risk stack: score every trade for its probability of a negative outcome (a spread blowout, a downgrade, a drawdown or a limit breach) over the next few months, and put the worst offenders in front of a human beforethey hit P&L.

The catch with ML in risk is trust: a black box that says “sell” without a reason is useless on a trading floor. So the model here is kept deliberately simple and fully explainable — a logistic regression, trained live in your browser, where every prediction breaks cleanly into the reasons behind it.

How the model works, in four steps

  1. 1 · Features. Each trade becomes a row of numbers that history says matter for credit: spread momentum (is it already widening?), size vs. the risk budget, rating, liquidity, issuer concentration, and carry cushion.
  2. 2 · Label. From past trades we know which ones went bad. The model learns the mapping from features → outcome.
  3. 3 · Train. Logistic regression finds the weight on each feature by gradient descent — nudging the weights to make its predicted probabilities match what actually happened, over hundreds of passes.
  4. 4 · Predict & explain. For a new trade it outputs p = sigmoid(w·x + b) — a probability between 0 and 1 — and because it's linear, each feature's wⱼ·xⱼ is its exact push on the odds.

We grade it honestly on trades it never saw during training. The headline number is AUC — the chance it ranks a random bad trade above a random good one (0.5 is a coin flip; ~0.9 here is strong).

🎛 Trade risk radar

The model — logistic regression, trained in your browser on 975 labelled trades

AUC

0.868

ranking skill (0.5=coin)

Accuracy

84%

at 0.5 cutoff

Log-loss

0.39

lower is better

Base rate

28%

trades that go bad

What the model learned matters (|weight|)

Spread momentum
+0.98
Size vs risk budget
+0.59
Rating
+0.98
Liquidity tier
+0.51
Issuer concentration
+0.76
Carry cushion
-0.65

Red = raises risk, green = protective. Learned from data, not hand-set — spread momentum and rating dominate.

Live watchlist — P(negative outcome), next 3 months

Octagon CLO Equity
98%driver: Rating
Octagon CLO BB
86%driver: Issuer concentration
Carnival 7.5% 2028
80%driver: Spread momentum
Ford 6.75% 2030
63%driver: Spread momentum
Verizon 3.85% 2032
19%driver: Carry cushion
Apple 4.5% 2033
8%driver: Carry cushion
UST 4.25% 2034
2%driver: Carry cushion

Dashed line = the 40% alert threshold. Anything past it goes on the risk officer's morning call — before it shows up in P&L.

Score a trade — and see exactly why

Spread momentum20 bp/mo
Size vs risk budget0.8 ×
Rating5
Liquidity tier3
Issuer concentration12 %
Carry cushion350 bp

Predicted risk of a negative outcome

86%

FLAG — review

Why — each feature's push on the log-odds

Spread momentum
+1.20
Size vs risk budget
+0.76
Rating
+0.65
Liquidity tier
+0.53
Issuer concentration
+0.81
Carry cushion
-0.72
baseline (bias)
-1.45

Sum of pushes + bias = log-odds 1.7886% after the sigmoid.

This is a real model — trained by gradient descent, evaluated on a held-out set — kept deliberately linear so every score is explainable. A production desk would add more features and a gradient-boosted tree, but the discipline is identical: learn from history, rank tomorrow's trades, and act before the loss. It is decision support, not an oracle — it can only see patterns that were in the training data, and regimes change. Educational tool — not investment advice.

What ML can and can't do here

  • It ranks, it doesn't divine. A 70% score means 7-in-10 similar trades soured — not that this one will. You act on the portfolio of alerts, not any single call.
  • It only knows the past. The model can only spot patterns present in its training data. A brand-new kind of shock (a COVID, a 2022) is, by definition, out-of-sample — which is why ML supplements stress testing, it doesn't replace it.
  • Beware label leakage & overfitting. If a feature secretly encodes the answer, the model looks brilliant in backtest and fails live. Honest holdout evaluation (as above) is the guardrail.
  • Explainability is a control, not a nicety. A PM will override a model — so it has to show its reasons. That's why linear/tree models with per-feature attribution win over opaque ones for risk.

Used this way, ML becomes the triage nurse of the risk desk — reading every trade every morning and pointing the scarce human attention at the handful most likely to hurt.