# Required packages.
library(tidyquant)
library(tidyr)
library(Sim.DiffProc)
library(dplyr)
# Merton assumes V follows a geometric brownian motion process.
V0.sim <- function(i) { # the argument i is not used here.
GBM(N = 365, T = 1, t0 = 0, x0 = 12.39578, theta = 0.05, sigma = 0.2123041)
}
set.seed(3) # Reproducibility
paths <- sapply(1:100, V0.sim) # Create 10 paths for V.
# Plot results.
matplot(paths, type = "l", col = "black", lwd = 1, lty = 1,
ylab = expression(paste(V[t])), xlab = "Time in days (0 to T)")
abline(h = 10, col = "red", lwd = 2)
points(1, 12.39578, pch = 19, cex = 1.5, col = "blue")
E0 <- 3
rf <- 0.05
TT <- 1
D <- 10
se <- 0.8
eq24.3 <- function(V0, sv) {
((V0 * pnorm((log(V0 / D) + (rf + sv^2 / 2) * TT) / (sv * sqrt(TT))) -
D * exp(-rf * TT) * pnorm(((log(V0 / D) +
(rf + sv^2 / 2) * TT) / (sv * sqrt(TT))) - sv * sqrt(TT)) - E0)) }
eq24.4 <- function(V0, sv) {
((pnorm((log(V0 / D) + (rf + sv^2 / 2) * TT) / (sv * sqrt(TT))) *
sv * V0 - se * E0)) }
min.footnote10 <- function(x)
(eq24.3(x[1], x[2]))^2 + (eq24.4(x[1], x[2]))^2
V0_sv <- optim(c(1, 1), min.footnote10)
V0 <- V0_sv$par[1]
sv <- V0_sv$par[2]
VT <- exp(rnorm(100000, log(V0) + (0.05 - (sv^2) / 2)*TT, sv*sqrt(TT)))
ET <- pmax(VT - D, 0) # payoff function of a typical call option.
plot(sort(VT), sort(ET), type = "l", lwd = 4, xlim = c(5, 20),
ylim = c(0, 10), xlab = "Simulated assets at maturity (V_T)",
ylab ="Simulated equity at maturity (E_T)")
abline(v = 10, lty = 2)