# We start by defining the quantities whose value is known.
S0=3; # Equity at time 0, i.e. today.
sigmaS=0.8; # Instantaneous volatility of equity
r=0.05; # Risk-free rate on the market
T=1; # Maturity
B=10; # Face value of debt obligation, i.e. liabilities.
# We then need to write down the function we will minimize in order to obtain
# V0, the value of company’s assets today, and sigmaV, assets’ volatility
# To write a function in R, we use the command “function”. Refer to the R intro
# for more details.
Merton_solve=function(parm){
V0=parm[1] #initial value for V0
sigmaV=parm[2] #initial value for sigmaV
# And now, all the quantities we have seen in the slides.
d1=(log(V0/B)+(r+sigmaV^2/2)*T)/(sigmaV*sqrt(T))
d2=d1-sigmaV*sqrt(T)
F=V0*pnorm(d1)-B*exp(-r*T)*pnorm(d2)-S0
G=pnorm(d1)*sigmaV*V0-sigmaS*S0
# Finally the result of our function:
return(F^2+G^2)
}
# For the minimization step, in order to find V_0 and sigma_V,
# we need to specify two initial values.
# Let us choose V_0=13, and sigmaV=0.5.
# Other plausible values can obviously be chosen.
solutions=optim(c(V0=13,sigmaV=0.5),Merton_solve)
# What are the estimated values?
V0=solutions$par[1]
sigmaV=solutions$par[2]
# Let us compute d1 and d2 explicitly:
d1=(log(V0/B)+(r+sigmaV^2/2)*T)/(sigmaV*sqrt(T))
d2=d1-sigmaV*sqrt(T)
# And finally the probability of default in one year for our company
pnorm(-d2)