# merton_ll: Compute Log-Likelihood of Merton Model In DtD: Distance to Default

## Description

Computes the log-likelihood for a given values of μ and σ.

## Usage

 `1` ```merton_ll(S, D, T., r, time, dt, vol, mu, tol = 1e-12) ```

## Arguments

 `S` numeric vector with observed stock prices. `D` numeric vector or scalar with debt due in `T.`. `T.` numeric vector or scalar with time to maturity. `r` numeric vector or scalar with risk free rates. `time` numeric vector with the observation times. `dt` numeric scalar with time increments between observations. `vol` numeric scalar with the σ value. `mu` numeric scalar with the μ value. `tol` numeric scalar with tolerance to `get_underlying`. The difference is scaled if the absolute of `S` is large than `tol` as in the `tolerance` argument to `all.equal.numeric`.

`BS_fit`
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28``` ```# we get the same if we call `optim` as follows. The former is faster and is # recommended set.seed(4648394) sims <- BS_sim( vol = .1, mu = .05, dt = .1, V_0 = 100, T. = 1, D = rep(80, 20), r = .01) r1 <- with( sims, BS_fit(S = S, D = D, T. = T, r = r, time = time, method = "mle", eps = 1e-8, vol_start = .2)) r2 <- optim(c(mu = 0, log_vol = log(.2)), function(par) -with( sims, merton_ll(S = S, D = D, T. = T, r = r, time = time, mu = par["mu"], vol = exp(par["log_vol"])))) all.equal(r1\$n_iter, unname(r2\$counts[1])) all.equal(r1\$ests[1], r2\$par[1]) all.equal(r1\$ests[2], exp(r2\$par[2]), check.attributes = FALSE) # the log-likelihood integrates to one as it should though likely not the # most stable way to test this ll <- integrate( function(x) sapply(x, function(S) exp(merton_ll( S = c(1, S), D = .8, T. = 3, r = .01, dt = 1/250, vol = .2, mu = .05))), lower = 1e-4, upper = 6) stopifnot(isTRUE(all.equal(ll\$value, 1, tolerance = 1e-5))) ```