merton.calibration.bayesian_mcmc¶
Bayesian MCMC calibration via emcee.
Where merton.calibration.duan_mle() returns a single point estimate
plus asymptotic standard errors, the Bayesian MCMC calibrator returns a
posterior distribution over (\mu, \sigma_A) — which propagates
cleanly into credible intervals on DD, PD, and credit spread.
The likelihood is the Duan (1994) transformed-data likelihood; the
default priors are uniform on bounded ranges (\mu \in [-5, 5],
\sigma_A \in [0.001, 5]). Pass custom priors via the prior_log_pdf
argument.
Implementation¶
We use emcee.EnsembleSampler with the affine-invariant stretch
move. The walker count defaults to 2 * ndim (the emcee minimum) but
32+ is recommended for tight posteriors.
References
Goodman, J., Weare, J. (2010). Ensemble samplers with affine invariance. Communications in Applied Mathematics and Computational Science 5 (1).
Foreman-Mackey, D., Hogg, D. W., Lang, D., Goodman, J. (2013). emcee: The MCMC Hammer. PASP 125 (925), 306-312.
Attributes¶
Classes¶
Output of |
|
OO wrapper around |
Functions¶
|
Sample the Bayesian posterior of |
Module Contents¶
- class merton.calibration.bayesian_mcmc.BayesianCalibrationResult[source]¶
Bases:
merton.calibration.base.CalibrationResultOutput of
bayesian_mcmc(). ExtendsCalibrationResultwith the posterior chain plus credible-interval helpers.- credible_interval(param: str, level: float = 0.95) merton.calibration.covariance.ConfInt[source]¶
Empirical highest-density / percentile credible interval.
- merton.calibration.bayesian_mcmc.bayesian_mcmc(*, equity_series: merton._typing.FloatArray, debt: float, rf: float, T: float, dt: float = 1.0 / 252.0, dividend_yield: float = 0.0, survivor_bias_correction: bool = False, n_walkers: int = 32, n_steps: int = 2000, burn_in: int = 500, thin: int = 5, seed: int | None = None, mu_range: tuple[float, float] = DEFAULT_MU_RANGE, sigma_range: tuple[float, float] = DEFAULT_SIGMA_RANGE, prior_log_pdf: collections.abc.Callable[[numpy.ndarray], float] | None = None) BayesianCalibrationResult[source]¶
Sample the Bayesian posterior of
(μ, σ_A)via emcee.- Parameters:
equity_series – 1-D array of equity observations (≥ 30 points recommended).
debt – Standard Duan-MLE inputs.
rf – Standard Duan-MLE inputs.
T – Standard Duan-MLE inputs.
dt – Standard Duan-MLE inputs.
dividend_yield – Standard Duan-MLE inputs.
survivor_bias_correction – Pass to the underlying likelihood. Defaults to
Falsebecause the correction makes the optimiser landscape harder to sample.n_walkers – emcee parameters; sane defaults from the user guide.
n_steps – emcee parameters; sane defaults from the user guide.
burn_in – emcee parameters; sane defaults from the user guide.
thin – emcee parameters; sane defaults from the user guide.
seed – emcee parameters; sane defaults from the user guide.
mu_range – Bounds for the default uniform prior. Ignored when
prior_log_pdfis passed.sigma_range – Bounds for the default uniform prior. Ignored when
prior_log_pdfis passed.prior_log_pdf – Optional custom log-prior. Must accept a 1-D array
[μ, σ_A]and return a float.
- class merton.calibration.bayesian_mcmc.BayesianMCMCCalibrator(*, n_walkers: int = 32, n_steps: int = 2000, burn_in: int = 500, thin: int = 5, seed: int | None = None, tol: float = 1e-06, max_iter: int = 200)[source]¶
Bases:
merton.calibration.base.CalibratorOO wrapper around
bayesian_mcmc().- fit(firm: merton.core.firm.Firm) BayesianCalibrationResult[source]¶
Infer asset value & volatility for
firm.