Objective
The Bayesian Estimation lesson listed three conjugate pairs (Beta–Binomial, Normal–Normal with known variance, Gamma–Poisson) and showed that the posterior mean is a shrinkage estimator. This lesson explains why those pairs exist, handles the case that matters most for returns (mean and variance both unknown), extends the Beta to many categories, and shows how to test whether a fitted Bayesian model actually reproduces the data. By the end you should be able to write down a conjugate update from the likelihood alone, compute a Student-t predictive interval by hand, and design a posterior predictive check.
Where conjugacy comes from
A family is an exponential family if its density can be written
with natural parameter , sufficient statistic and log-normaliser . For independent draws the likelihood is times a factor free of . Any prior of the same shape in ,
is conjugate, because multiplying the two just adds exponents:
So the prior is literally pseudo-data: prior observations whose sufficient statistics sum to . Three consequences are worth knowing:
- The posterior mean of is linear in the data: (Diaconis–Ylvisaker). Every shrinkage formula in the earlier lesson is a special case.
- Predictive and evidence are ratios of normalisers. The posterior predictive is and the marginal likelihood is . The second formula is what makes exact Bayes factors possible in the model-comparison lesson.
- Outside exponential families there is no fixed-size conjugate prior. By the Pitman–Koopman–Darmois theorem, only exponential families (under regularity) have sufficient statistics of fixed dimension. A Student-t likelihood for fat-tailed returns has none, which is one reason MCMC exists.
Check with the Bernoulli: , so , , . The conjugate prior equals in -space; converting to a density in with the Jacobian gives : prior successes in prior trials.
Normal data, mean and variance both unknown
Returns have an unknown mean and an unknown volatility, and with a short history the uncertainty in the volatility matters. The conjugate prior is the Normal–Inverse-Gamma (NIG):
Read as the number of prior observations behind , and as the number behind the variance guess (the prior mean of is ). With observations, mean and sum of squares , the posterior is NIG with
The three pieces of are the prior's scale, the scatter within the sample, and a penalty for disagreement between the prior mean and the sample mean: a surprising makes you less sure of the volatility too.
Integrating out gives Student-t distributions. Integrating over leaves , which is a kernel with degrees of freedom. So
where the second argument is the squared scale. The predictive is wider than the plug-in for two reasons: the factor adds uncertainty about , and the tails add uncertainty about . With small samples the tail difference is large.
In the limit , , (the prior ) you get and : the classical interval, now with a probability statement attached.
Worked example
a new strategy with twelve months of returns
A strategy has 12 monthly returns with mean and sample standard deviation . Your prior, from similar strategies: , (worth four months), , (prior mean variance , i.e. about 4% monthly vol). Find the posterior for , , and a 95% predictive interval for next month. Compare the chance of a month below with the plug-in normal answer.
Show solutionHide solution
Update. .
- , .
- , so degrees of freedom.
- .
The mean. Squared scale , scale . So . With the 95% credible interval is , and . The sample mean of 1% was pulled to 0.75% because the prior is worth 4 of the 16 effective observations.
Next month. Squared scale , scale . The 95% predictive interval is .
Tail. Under the predictive, . The plug-in gives . The Bayesian answer is almost twice as large: twelve months cannot pin down the volatility, and the plug-in pretends they can. Note also the posterior mean of is (about 3.2% vol), higher than , because the prior expected more volatility.
Many categories: Dirichlet–Multinomial
For outcomes with probabilities and counts from trials, the conjugate prior is the Dirichlet, , and
With , each margin is , so
The components are negatively correlated, since they sum to one. Uses in quant work: the next tick direction (up, flat, down), the frequency of market regimes, each row of a Markov transition matrix (a credit-rating or regime-switching matrix estimated from few transitions), and order-type mixes. The prior's job is mostly to stop a category with zero observed counts from getting probability zero: with the predictive is Laplace's rule of succession generalised to outcomes.
Worked example
next tick direction
You model the next mid-price move in an illiquid name as up, flat or down, with prior . In 10 moves you see 7 up, 2 flat and 1 down. Find the posterior, the predictive probabilities for the next move, the posterior SD of , , and the probability that the next two moves are both up.
Show solutionHide solution
Posterior. with .
Predictive. up, flat, down. The raw frequencies are pulled towards each by six pseudo-observations.
Uncertainty. , SD . The margin is , and : ten moves leave a lot of doubt about whether up-moves are even the majority.
Two ups in a row. The predictive for a pair is , not :
compared with . Equivalently, update on the first up (to ) and then predict : . Future draws are positively correlated through the unknown ; treating them as independent at the posterior mean understates the chance of runs.
Posterior predictive checks
A posterior is only as good as the model. A posterior predictive check asks whether data simulated from the fitted model look like the data you have:
- Draw from the posterior.
- Simulate a replicated data set of the same size from .
- Compute a test statistic on each replicate and on the real data, and report (or the other tail).
A near 0 or 1 means the model cannot reproduce that feature. Choose to target what you will use the model for: tails (minimum, kurtosis, count of 3-sigma days) for risk, autocorrelation for forecasting. Statistics the model fits directly, like the sample mean in a normal model, almost always pass, because the data were used to fit them; that pass tells you nothing.
The code below fits the NIG model to 60 months of returns that contain a few crash months, then checks the mean and the minimum.
import random, statistics as st
random.seed(7)
# "Observed" monthly returns (%): mostly calm, occasionally a crash month.
y = [random.gauss(1.0, 2.0) if random.random() > 0.08 else random.gauss(-8.0, 3.0)
for _ in range(60)]
n, ybar = len(y), st.mean(y)
ss = sum((v - ybar) ** 2 for v in y)
# Weak Normal-Inverse-Gamma prior: m0 = 0, kappa0 = 1, a0 = 2, b0 = 4.
k0, m0, a0, b0 = 1.0, 0.0, 2.0, 4.0
kn = k0 + n
mn = (k0 * m0 + n * ybar) / kn
an, bn = a0 + n / 2, b0 + ss / 2 + k0 * n * (ybar - m0) ** 2 / (2 * kn)
def draw_posterior():
sigma2 = 1 / random.gammavariate(an, 1 / bn) # sigma^2 ~ Inv-Gamma(an, bn)
mu = random.gauss(mn, (sigma2 / kn) ** 0.5)
return mu, sigma2
stats = {"mean": st.mean, "min": min}
obs = {k: f(y) for k, f in stats.items()}
hits = {k: 0 for k in stats}
R = 4000
for _ in range(R):
mu, s2 = draw_posterior()
rep = [random.gauss(mu, s2 ** 0.5) for _ in range(n)]
for k, f in stats.items():
hits[k] += f(rep) <= obs[k]
for k in stats:
print(f"T = {k:4s} observed {obs[k]:6.2f} P(T_rep <= T_obs) = {hits[k] / R:.3f}")
Output:
T = mean observed 0.32 P(T_rep <= T_obs) = 0.503
T = min observed -11.03 P(T_rep <= T_obs) = 0.011
The mean check is perfect and meaningless. The minimum check fails: only about 1% of replicated histories contain a month as bad as , although the real history does. A normal model is fine for estimating the average return here but should not be trusted for drawdown or VaR; a Student-t or mixture likelihood is the next step, and it is no longer conjugate.
Knowledge check
With an NIG prior , , and , you observe returns with mean . What are the posterior mean of and the degrees of freedom of its Student-t marginal?
Knowledge check
Next moves are up, flat or down with prior . In 8 moves you see 5 up, 3 flat and 0 down. What is the posterior predictive probability that the next move is down?
Knowledge check
You fit a normal model to 500 daily returns and run posterior predictive checks. The posterior predictive p-value is 0.48 for the sample mean and 0.001 for the sample kurtosis. What should you conclude?
Knowledge check
With 12 months of data, why is the NIG posterior predictive for next month's return wider in the tails than a normal distribution with the sample mean and sample variance?
Key takeaways
- Exponential families have conjugate priors of the form : the prior is pseudo-observations with summed statistics , and updating adds the data's sufficient statistics.
- Predictives and marginal likelihoods in conjugate models are ratios of normalising constants, so they are available in closed form.
- For a normal model with unknown mean and variance use the NIG prior; the posterior of and the predictive are Student-t with degrees of freedom. With short histories the predictive tails are much heavier than the plug-in normal's.
- The flat-prior limit reproduces the classical interval.
- Dirichlet–Multinomial: add counts to ; the predictive is ; joint predictions of several future draws are not products of single predictions.
- Posterior predictive checks test whether the model reproduces features you care about. Use statistics the model was not fitted to, especially tails.
Practice problems
Finished reading?
Answer the 4 knowledge checks to complete this lesson (0 done).