Quant Memo
Advanced

Hierarchical Bayesian Models

How to estimate many related quantities at once — one win rate per trader, one beta per sector — so that groups with little data automatically borrow strength from the whole population instead of producing wild, unstable estimates on their own.

Prerequisites: Bayes' Theorem, Conjugate Priors

You run 50 traders and want to estimate each one's true skill from their track record. Some have three years of history; some started last month. If you estimate each trader's win rate completely independently, the rookies' estimates will swing wildly — one trader with 4 wins out of 5 trades looks like a genius on paper, purely from small-sample luck. If instead you pool everyone into one number, you throw away all the real differences in skill that clearly exist. A hierarchical Bayesian model is the compromise that's usually right: it estimates each trader's number and a population-level distribution describing how traders' numbers tend to vary, and it lets each individual estimate lean on the population whenever its own data is thin. The less data a group has, the more it gets pulled toward the group average — automatically, without you having to decide by hand how much to trust each one.

An analogy: guessing a stranger's height from a little information

If you're told a stranger is 6'5", your best guess for their height is 6'5" — you have direct evidence. If you're told a stranger's cousin says "I think he's around 6'5", but I've never actually measured," you should guess somewhere between 6'5" and the average adult height, because that secondhand, uncertain report deserves less weight than a real measurement. A hierarchical model applies exactly this logic to every group in your data simultaneously: a trader with three years of consistent 60% win rate is treated like the confident measurement — mostly believed as-is. A trader with five trades and an 80% win rate is treated like the shaky secondhand report — pulled substantially toward the overall average, because five trades is barely more informative than a rumor.

population mean n=5, raw shrunk (a lot) n=50, raw n=1000, raw shrunk (barely)
Three traders' raw estimates (red) get pulled toward the population mean (dashed line). The trader with only 5 trades moves the most; the trader with 1,000 trades barely moves at all — shrinkage strength is automatically set by how much data backs each estimate.

The model, one symbol at a time

Let j=1,,Jj = 1, \dots, J index the groups (traders), and let θj\theta_j ("theta sub j") be trader jj's true win rate. Rather than treating each θj\theta_j as unrelated, a hierarchical model says they're all draws from a shared population distribution:

θjN(μ,τ2),yjθjobserved data for trader j.\theta_j \sim N(\mu, \tau^2), \qquad y_j \mid \theta_j \sim \text{observed data for trader } j .

In words: each trader's true rate θj\theta_j is itself drawn from a population-level normal distribution with mean μ\mu ("mu," the average trader) and variance τ2\tau^2 ("tau squared," how much traders genuinely differ from each other); then trader jj's observed data is generated given their own θj\theta_j. Both layers — the population parameters (μ,τ2)(\mu, \tau^2) and the individual θj\theta_j's — are estimated jointly from all the data at once, which is what lets information flow between groups.

For a simple Gaussian version, the posterior mean for group jj takes an elegant, interpretable form — the shrinkage estimator:

θ^j=wjyˉj+(1wj)μ,wj=nj/σ2nj/σ2+1/τ2.\hat\theta_j = w_j\, \bar y_j + (1 - w_j)\, \mu, \qquad w_j = \frac{n_j / \sigma^2}{n_j/\sigma^2 + 1/\tau^2} .

In words: the estimate for group jj is a weighted average of that group's own raw sample mean yˉj\bar y_j and the overall population mean μ\mu; the weight wjw_j ("w sub j") on the group's own data grows toward 1 as its sample size njn_j grows, and shrinks toward 0 when njn_j is small or the group-to-group variance τ2\tau^2 is small (meaning groups don't really differ much, so there's little reason to trust any one group's noisy number over the population).

A hierarchical model estimates every group and the population simultaneously, and automatically shrinks each group's estimate toward the population average by an amount that depends on how little data that group has. Groups with lots of data barely move; groups with little data lean heavily on everyone else's information.

Worked example 1: shrinking two traders' win rates

Population parameters (estimated from all 50 traders): μ=0.50\mu = 0.50, τ2=0.0025\tau^2 = 0.0025 (traders' true win rates vary with a standard deviation of 5 points). Assume the sampling variance of an observed win rate is roughly σ2/nj\sigma^2/n_j where a single trade's outcome variance σ20.25\sigma^2 \approx 0.25 (a coin-flip-scale binary outcome).

Trader A: nA=5n_A = 5 trades, raw win rate yˉA=0.80\bar y_A = 0.80. Weight: wA=5/0.255/0.25+1/0.0025=2020+400=20420=0.048w_A = \dfrac{5/0.25}{5/0.25 + 1/0.0025} = \dfrac{20}{20 + 400} = \dfrac{20}{420} = 0.048. Shrunk estimate: θ^A=0.048(0.80)+0.952(0.50)=0.038+0.476=0.514\hat\theta_A = 0.048(0.80) + 0.952(0.50) = 0.038 + 0.476 = 0.514. Trader A's flashy 80% raw win rate becomes a modest 51.4% after accounting for how little evidence backs it.

Trader B: nB=500n_B = 500 trades, raw win rate yˉB=0.58\bar y_B = 0.58. Weight: wB=500/0.25500/0.25+400=20002400=0.833w_B = \dfrac{500/0.25}{500/0.25+400} = \dfrac{2000}{2400} = 0.833. Shrunk estimate: θ^B=0.833(0.58)+0.167(0.50)=0.483+0.083=0.567\hat\theta_B = 0.833(0.58)+0.167(0.50) = 0.483+0.083 = 0.567. Trader B's already-credible 58% barely moves, to 56.7%, because 500 trades is real evidence the model trusts almost fully.

Worked example 2: the population variance itself changes the story

Suppose instead the traders turn out to be far more genuinely different from each other, τ2=0.04\tau^2 = 0.04 (a 20-point true standard deviation) rather than 0.0025. Recompute Trader A's weight: wA=2020+1/0.04=2020+25=2045=0.444w_A = \dfrac{20}{20 + 1/0.04} = \dfrac{20}{20+25} = \dfrac{20}{45} = 0.444. Shrunk estimate: θ^A=0.444(0.80)+0.556(0.50)=0.356+0.278=0.633\hat\theta_A = 0.444(0.80)+0.556(0.50) = 0.356+0.278 = 0.633. With more genuine population spread, the model trusts Trader A's own 80% figure much more — shrinking only to 63.3% instead of 51.4% — because a wide τ2\tau^2 says "traders really do differ a lot, so don't be too quick to explain away an unusual number as pure noise." This is the mechanism by which the model learns, from the whole population's spread, exactly how skeptical to be of any one member's individual result.

Sampling distribution
sample mean →
sample size n 10spread of means 0.332predicted 1/√n 0.316

Set the sample size low in the explorer above and note how wide and unstable a small-sample mean is — that instability is exactly what a hierarchical model detects and down-weights via njn_j in the shrinkage formula.

What this means in practice

  • Multi-strategy or multi-desk Sharpe ratio estimation is the canonical trading use case: pool all strategies' returns to estimate a population Sharpe distribution, then shrink each individual strategy's noisy Sharpe toward it — this is standard practice at multi-manager platforms allocating capital across many young strategies.
  • Fama-MacBeth-style cross-sectional estimation benefits the same way: firm- or sector-level betas estimated with little data get pulled toward the cross-sectional average instead of producing extreme, noise-driven outliers.
  • The population variance τ2\tau^2 is itself estimated from the data, not assumed — it comes out of the fit as naturally as μ\mu does, which is why the model adapts its own skepticism level rather than requiring you to hand-tune a shrinkage amount.
  • Fully Bayesian fits typically use MCMC (see Gibbs sampling) because the joint posterior over μ\mu, τ2\tau^2, and all the θj\theta_j's rarely has a clean closed form outside the simplest Gaussian case shown above.

The classic confusion: treating shrinkage as "cheating" or "diluting" a group's real result. It feels wrong to move Trader A's actual 80% win rate down to 51%, but the shrinkage formula is doing exactly the correct statistical thing: with only 5 trades, an 80% win rate is barely more informative than a coin flip landing heads 4 times in a row, which happens routinely by pure chance. The alternative — trusting every group's raw number equally regardless of sample size — is what actually produces bad decisions, like allocating capital to a "hot" trader whose entire track record is five lucky trades. Shrinkage isn't a compromise imposed on the data; it's the data itself, correctly interpreted, telling you how much to believe.

Related concepts

Practice in interviews

Further reading

  • Gelman & Hill, Data Analysis Using Regression and Multilevel/Hierarchical Models, ch. 11-12
  • Gelman et al., Bayesian Data Analysis, ch. 5
ShareTwitterLinkedIn