Code covered by the BSD License  

Highlights from
Merton Structural Credit Model (Matrixwise Solver)

5.0 | 2 ratings Rate this file 36 Downloads (last 30 days) File Size: 2.9 KB File ID: #39717
image thumbnail

Merton Structural Credit Model (Matrixwise Solver)



04 Jan 2013 (Updated )

Matrixwise Calculation Firm Asset Value, Volatility, Debt Value, Spread, Default Prob, Exp-Recovery

| Watch this File

File Information

Calculates the Value of Firm Assets, Volatility of Firm Assets,
  Debt-Value, Credit-Spread, Default Probability and Recovery Rate as per
  Merton's Structural Credit Model. The value and volatility of firm assets
  are found by Bivariate Newton Root-Finding Method of the Merton
  Simultaneous Equations. The Newton Method is carried out matrixwise
  (i.e. fully vectorised) in a 3d Jacobian so that bivariate ranges of
  (E_t,sig_E,K,T) values may simultaneously calculated. (See Examples)
   Function requires mtimesx.m available on the Matlab File Exchange at
    A_t: Value of Firm's Assets [A_t = Call(K,sig_A,A_t,t,T,r)]
    sig_A: Volatility of Firm's Assets
    D_t: Value of Firm Debt [D_t = pv(K) - Put(K,sig_A,A_t,t,T,r)]
    s: Credit Spread
    p: Default Probability
    R: Expected Recovery
    d: Black-Scholes Parameter Anonymous Function
    E_t: Value of Equity
    sig_E: Equity Volatility
    K: Debt Barrier
    t: Estimation Time (Years)
    T: Maturity Time (Years)
    r: Risk-free-Rate
  Example 1
    T = 5;
    t = 0;
    K = 500;
    sig_E = 0.5;
    r = 0.05;
    E_t = 1200;
    [A_t,sig_A,D_t,s,p,R,d1] = calcMertonModel(E_t,sig_E,K,t,T,r);
  Example 2: Variates (sig_E,E_t)
    t = 0; r = 0.05;
    sig_E = (0.05:0.05:0.8)'; E_t = (100:100:2000)';
    [sig_E,E_t] = meshgrid(sig_E,E_t);
    K = repmat(600,size(sig_E)); T = repmat(5,size(sig_E));
    [A_t,sig_A,D_t,s,p,R,d1] = calcMertonModel(E_t,sig_E,K,t,T,r);
  Example 3: Variates (K,T)
    t = 0; r = 0.05;
    K = (100:100:4000)'; T = (0.1:0.1:10)';
    [K,T] = meshgrid(K,T);
    sig_E = repmat(0.4,size(K)); E_t = repmat(1300,size(K));
    [A_t,sig_A,D_t,s,p,R,d1] = calcMertonModel(E_t,sig_E,K,t,T,r);


Mtimesx Fast Matrix Multiply With Multi Dimensional Support inspired this file.

Required Products MATLAB
MATLAB release MATLAB 7.12 (R2011a)
Other requirements mtimesx.m
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (8)
21 Apr 2014 Mark Whirdy

There is a bug with Microsoft's SDK 7.1 which Matlab have provided a troubleshoot for at

Hope this helps

Comment only
07 Apr 2014 Mark Whirdy

Hi Joacim - possible incompatability between the compiler you installed and the version of matlab?

Comment only
07 Apr 2014 Joacim

Joacim (view profile)

Im trying to follow the instructions in a previous comment, setting up mtimesx, but it wont work. It seems like Matlab can't find any compliers even though I installed them, any suggestions on what to do?

Comment only
23 Aug 2013 Hannes

Hannes (view profile)

user-friendly and fast calculating implementation of the Merton model.
fast adaptable and convenient for sensitivty analysis

17 May 2013 Jung

Jung (view profile)

16 May 2013 Mark Whirdy

To get mtimesx working, type

mex -setup

Select a compiler, [1] is the C compiler shipped with Matlab and will do

Then run


which will create a .mex32 file in your path. This is Matlabs "interface" to the C code

Comment only
16 May 2013 Henok Tewolde

I really don't know why I am getting this error

Error using mtimesx_build (line 169)
A C/C++ compiler has not been selected with mex -setup

Comment only
09 May 2013 Jaeho

Jaeho (view profile)

This model is excellent! Very flexible and user-friendly. It's been very useful for calculating credit spreads of bonds with different asset values, and volatilities.

Comment only
07 Jan 2013

Added Expected-Recovery calclulation

[A_t,sig_A,D_t,s,p,R] = calcMertonModel(E_t,sig_E,K,t,T,r);

25 Feb 2013

Minor code refactoring, code returns the Black-Scholes Parameter to allow for further sensitivity analysis & calculation of greeks

d = @(z,A_t,sig_A,T,t,K,r)
z=+1/-1 for Call/Put

25 Feb 2013

Added the Black-Scholes Parameter Anonymous Function Handle as an Output to allow for further analysis (sensitivity, greeks etc)

d = @(z,A_t,sig_A,T,t,K,r)((1/(sig_A*sqrt(T-t)))*(log(A_t/K) + (r + (z)*0.5*sig_A^2)*(T-t)));

z = +1/-1

14 May 2013

Removed fsolve dependency (Optim Toolbox) for efficiency increase (even in scalar inputs case)

Full Code re-factorization to facilitate matrixwise calculation of bivariate ranges of {E_t,sig_E,K,T} values using 3d Newton Jacobian solution.

Contact us