Merton Model Credit Risk Calculator

This is a credit risk calculator based on a simplified version of the Merton model. One of my assignments for MAT1856 was to compare different credit risk models, the Merton model being one of them. I thought the math behind it was fairly interesting, and so I decided to make a write-up and public implementation for it. The Merton model is based on the Black-Scholes formula for option prices, and views a company's equity as a call option on its assets. Section I is the calculator itself. The background for the Merton model can be found in section II. Section III contains the optimizer used for finding asset and asset volatility. Appendix A contains more detailed calculations. For software packages, I am using Math.js for matrix calculations and CDF evaluations, and MathJax for rendering LaTeX in HTML. You can see all my code at the GitHub repository. If you are interested in learning more about this, feel free to watch my professor's lecture.

I. Calculator

If you need help finding these values, you can go to the following sites (after choosing a company):

The placeholders provide some example values.







Output






II. Background

II.1 The Black-Scholes Formula

The Blach-Scholes formula for call options is:

\begin{align} E &= VN(d_1) - K e^{-rt} N(d_2), \tag{BSF}\\ d_1 &= \frac{\log \frac{V}{K} + \left(r + \frac{\sigma^2}{2} \right)t}{\sigma \sqrt{t}} \\ d_2 &= d_1 - \sigma \sqrt{t} \\ N(x) &= \int_{-\infty}^x \frac{1}{\sqrt{2\pi}} e^{- \frac{y^2}{2}} dy \end{align}

There are a lot of variables in this equation, so here is a legend for what they represent.

The Greeks

Buying options is risky. To quantify this risk, we use "the Greeks" which are essentially names given to varying derivatives of the BSF with respect to its inputs. The Merton model uses a few of them, and the derivation of their simplified values can be found in Appendix A.

II.2 Merton Model

As stated before, the Merton model looks at a companies equity ($E$) as a call option on its assets ($V$) with the strike price as its debt ($K$). That is, $E = \max(V - K, 0)$. When we exercise this option, it means the company has not defaulted and we find $E = V - K$. It can be shown the probability of this happening is $N(d_2)$. Thus, the probability of default is given by $1 - N(d_2) = N(-d_2)$. So, if we can find $d_2$, we are good to go! However, there is a slight caveat. Frequently, a companies assets and asset volatility cannot be directly observed. So, we need to derive them from other known values. One value that is frequently observed is equity. The equity of a company can (rougly) be calculated as $E = (\text{number of outstanding shares}) \times (\text{stock price})$. By going to Yahoo! Finance, you can get the daily values for $E$. With the daily values, you can also get the equity volatility. Equity volatility and asset volatility are related via:

\begin{equation} \sigma_E E = \sigma_V V \partial_V E = \sigma_V V \Delta \tag{2} \end{equation}

Let's summarize two facts we know so far:

Thus, we can create a root-finding problem to find $(V, \sigma_V)$, which takes the following form.

\begin{equation} f(V, \sigma_V; E_0, \sigma_E, K, r, t) = (f_1, f_2) = \Bigg(E(V, \sigma_V); K, r, t) - E_0, \sigma_E E(V, \sigma_V; K, r, t) - \sigma_V V \Delta(V, \sigma_V; K, r, t) \Bigg) \end{equation}

III. Powell's Dog Leg Method

To find the roots of $f$, I used Powell's Dog Leg Method (PDL from now on). PDL is the method used by SciPy's fsolve (which calls MINPACK's hybrd/hybrj). Powell's dog leg method essentially combines the Gauss-Newton algorithm and the gradient descent algorithm. I think the Wikipedia page does a good enough job explaining how it works. My 2D specific implementation can be found in the function findPDLStep.

Appendix A: Derivations

In this section, I go through some derivations that simplify computations and code. We will denote the PDF of the CDF $N(\cdot)$ as $n(\cdot) = \frac{1}{\sqrt{2\pi}} e^{-(\cdot)^2/2}$. Note that $\partial_V d_1$ and $\partial d_2 d_2$ are given by:

\begin{align} \partial_V d_1 &= \frac{\partial}{\partial V} \frac{\log \frac{V}{K} + \left(r + \frac{\sigma^2}{2}\right)t}{\sigma \sqrt{t}} = \frac{1}{V\sigma \sqrt{t}} & \partial_V d_2 &= \partial_V d_1 \\ \end{align}

And $\partial_\sigma d_1$ and $\partial_\sigma d_2$ are given by:

\begin{align} \partial_\sigma d_1 &= \frac{\partial}{\partial \sigma} \frac{\log \frac{V}{K} + \left(r + \frac{\sigma^2}{2}\right)t}{\sigma \sqrt{t}} \\ &= \frac{\sigma t \cdot \sigma \sqrt{t} - \left[\log \frac{V}{K} + \left(r + \frac{\sigma^2}{2}\right)t\right] \sqrt{t}}{\sigma^2 t} \\ &= \frac{\sigma^2 t - \log\frac{V}{K} - \left(r + \frac{\sigma^2}{2}\right)t}{\sigma^2\sqrt{t}} \\ \partial_\sigma d_1 &= -\frac{d_2}{\sigma} \\ \partial_\sigma d_2 &= \partial_\sigma d_1 - \sqrt{t} \\ &= -\frac{d_2}{\sigma} - \sqrt{t} \\ \partial_\sigma d_2 &= -\frac{d_1}{\sigma} \end{align}

A.1 The Greeks

Here, we will compute simplified expressions for the Greeks.

A.1.1 Delta

First, let's compute the arbitrary quantity $n(d_2)/n(d_1)$. First, we note that we can rewrite $d_1 = \frac{\log \frac{V}{Ke^{-rt}} + \frac{\sigma^2 t}{2}}{\sigma\sqrt{t}} = A + B$ with $d_2 = A - B$.

\begin{align} \frac{n(d_1)}{n(d_2)} &= \exp\left( -\frac{1}{2} \Big((A - B)^2 - (A + B)^2\Big)\right) = \exp\Big(2AB\Big) = \exp \left(2 \cdot \frac{\log\frac{V}{Ke^{-rt}}}{\sigma\sqrt{t}} \cdot \frac{\sigma^2 t}{2\sigma\sqrt{t}}\right) = \frac{V}{Ke^{-rt}} \end{align}

With this in hand, we can compute $\Delta = \partial_V E$.

\begin{align} \partial_V E &= N(d_1) + V n(d_1)\partial_V d_1 - Ke^{-rt}n(d_2)\partial_V d_2 \\ &= N(d_1) + \frac{1}{\sigma\sqrt{t}} \left( n(d_1) - \frac{Ke^{-rt}}{V} n(d_2) \right) \\ &= N(d_1) + \frac{n(d_1)}{\sigma\sqrt{t}} \left( 1 - \frac{Ke^{-rt}}{V} \frac{n(d_2)}{n(d_1)} \right) \\ \Delta &= N(d_1) \end{align}

A.1.2 Vega

Vega is given by $\nu = \partial_\sigma E$. Let's compute vega.

\begin{align} \partial_\sigma E &= Vn(d_1)\partial_\sigma d_1 - Ke^{-rt}n(d_2)\partial_\sigma d_2 \\ &= \frac{Vn(d_1)}{\sigma} \left(-d_2 + \frac{Ke^{-rt}}{V} \frac{n(d_2)}{n(d_1)}(d_1) \right) \\ &= \frac{Vn(d_1)}{\sigma} \Big( d_1 - d_2\Big) \\ &= Vn(d_1)\sqrt{t} \end{align}

A.1.3 Gamma

Gamma is given by $\Gamma = \partial_V^2 E$. It's given by,

\begin{align} \partial_V^2 E = \partial_V \Delta = \partial_V N(d_1) = n(d_1)\partial_V d_1 = \frac{n(d_1)}{V\sigma\sqrt{t}} \end{align}

A.1.4 Vanna

Vanna, which we will denote by $M$, is $M = \partial_\sigma \Delta$. It can be computed as follows,

\begin{align} \partial_\sigma \Delta = \partial_\sigma N(d_1) = n(d_1) \partial_\sigma d_1 = - \frac{n(d_1)d_2}{\sigma} \end{align}

A.2 PDL Jacobian

To compute the Jacobian used in the PDL, we need to find the Jacobian of $f = (f_1, f_2)$. The first function, $f_1$ is easy as it is just $E - E_0$ so that $\partial_V f_1 = \Delta$ and $\partial_\sigma f_1 = \nu$. The second function is a little more involved, but still not that difficult with the representations we've built so far.

\begin{align} \partial_V f_2 &= (\sigma_S - \sigma_V)\Delta - \sigma_V V \Gamma \\ \partial_\sigma f_2 &= \sigma_S \nu - V \Delta - \sigma_V V M \end{align}

This gives the final Jacobian value as:

$$ J = \begin{pmatrix} \Delta & \nu \\ \Big(\sigma_S - \sigma_V\Big) \Delta - \sigma_V V \Gamma & \sigma_s \nu - V \Big(\Delta - \sigma_V M\Big) \end{pmatrix} $$