merton.excel.functions

Excel-facing Python wrappers around the merton math primitives.

Each function below mirrors a public =MERTON_* formula exposed to Excel and accepts simple scalar or 1-D array inputs (the natural shape of Excel cell ranges). When xlwings is installed, merton.excel.server applies the @func / @arg decorators to the same functions so they become available as Office.js custom functions.

The wrappers also act as the single source of truth for the formula docstrings and parameter names — the manifest XML and the function-wizard help text are derived from these signatures.

Attributes

ARG_DOCS

EXCEL_FUNCTIONS

(excel_name, description, python_callable) tuples driving every consumer

Functions

merton_dd(→ float)

Distance to default under the Merton (1974) structural model.

merton_pd(→ float)

Risk-neutral probability of default at the horizon T.

merton_spread(→ float)

Implied credit spread (basis points) given LGD.

merton_asset_value(→ float)

Inferred firm asset value A (currency units).

merton_asset_vol(→ float)

Inferred annualised asset volatility σ_A (decimal).

merton_greeks(→ list[list[float]])

Returns a 1×6 array of Greeks: Δ, Γ, Vega, Θ, ρ, ∂PD/∂L.

merton_pd_term(→ list[list[float]])

PD term structure across horizons. Returns a 2-column dynamic array

merton_backtest(→ float)

Compute a single backtest metric over two equal-length ranges.

merton_portfolio_var(→ float)

Basel-IRB Vasicek single-factor VaR (Loss / Exposure).

merton_black_cox(→ float)

Black-Cox first-passage PD with optional barrier-growth rate.

Module Contents

merton.excel.functions.ARG_DOCS: dict[str, dict[str, str]][source]
merton.excel.functions.merton_dd(equity: float, equity_vol: float, debt: float, rf: float, T: float) float[source]

Distance to default under the Merton (1974) structural model.

Inverts the equity-as-call-option pricing to recover the asset value and asset volatility, then returns DD = d₂.

merton.excel.functions.merton_pd(equity: float, equity_vol: float, debt: float, rf: float, T: float) float[source]

Risk-neutral probability of default at the horizon T.

merton.excel.functions.merton_spread(equity: float, equity_vol: float, debt: float, rf: float, T: float, lgd: float = 0.6) float[source]

Implied credit spread (basis points) given LGD.

merton.excel.functions.merton_asset_value(equity: float, equity_vol: float, debt: float, rf: float, T: float) float[source]

Inferred firm asset value A (currency units).

merton.excel.functions.merton_asset_vol(equity: float, equity_vol: float, debt: float, rf: float, T: float) float[source]

Inferred annualised asset volatility σ_A (decimal).

merton.excel.functions.merton_greeks(equity: float, equity_vol: float, debt: float, rf: float, T: float) list[list[float]][source]

Returns a 1×6 array of Greeks: Δ, Γ, Vega, Θ, ρ, ∂PD/∂L.

The first row is the labels (when the Excel range is 2 rows tall) and the second is the values; Excel’s dynamic-array engine will spill the result automatically.

merton.excel.functions.merton_pd_term(equity: float, equity_vol: float, debt: float, rf: float, horizons: collections.abc.Sequence[float]) list[list[float]][source]

PD term structure across horizons. Returns a 2-column dynamic array with headers [horizon_years, pd].

merton.excel.functions.merton_backtest(pd_predictions: collections.abc.Sequence[float], defaults: collections.abc.Sequence[float], metric: str = 'AUC') float[source]

Compute a single backtest metric over two equal-length ranges.

merton.excel.functions.merton_portfolio_var(pd: float, lgd: float = 0.45, rho: float | None = None, alpha: float = 0.999, maturity: float = 1.0) float[source]

Basel-IRB Vasicek single-factor VaR (Loss / Exposure).

merton.excel.functions.merton_black_cox(equity: float, equity_vol: float, debt: float, rf: float, T: float, barrier_growth_rate: float = 0.0) float[source]

Black-Cox first-passage PD with optional barrier-growth rate.

merton.excel.functions.EXCEL_FUNCTIONS: tuple[tuple[str, str, Any], Ellipsis][source]

(excel_name, description, python_callable) tuples driving every consumer (manifest XML, classic xlwings UDFs, the FastAPI server, and docs).