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

BayesianCalibrationResult

Output of bayesian_mcmc(). Extends CalibrationResult with

BayesianMCMCCalibrator

OO wrapper around bayesian_mcmc().

Functions

bayesian_mcmc(→ BayesianCalibrationResult)

Sample the Bayesian posterior of (μ, σ_A) via emcee.

Module Contents

merton.calibration.bayesian_mcmc.DEFAULT_MU_RANGE[source]
merton.calibration.bayesian_mcmc.DEFAULT_SIGMA_RANGE = (0.001, 5.0)[source]
class merton.calibration.bayesian_mcmc.BayesianCalibrationResult[source]

Bases: merton.calibration.base.CalibrationResult

Output of bayesian_mcmc(). Extends CalibrationResult with the posterior chain plus credible-interval helpers.

chain: merton._typing.FloatArray[source]
log_probs: merton._typing.FloatArray[source]
acceptance_fraction: float = 0.0[source]
autocorr_time: merton._typing.FloatArray | None = None[source]
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 False because 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_pdf is passed.

  • sigma_range – Bounds for the default uniform prior. Ignored when prior_log_pdf is 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.Calibrator

OO wrapper around bayesian_mcmc().

method = 'bayesian_mcmc'[source]
n_walkers = 32[source]
n_steps = 2000[source]
burn_in = 500[source]
thin = 5[source]
seed = None[source]
tol = 1e-06[source]
max_iter = 200[source]
fit(firm: merton.core.firm.Firm) BayesianCalibrationResult[source]

Infer asset value & volatility for firm.