简体   繁体   中英

Solve systems of nonlinear equations in R / BlackScholesMerton Model

I am writing my Masters final project in which I am deriving probability of default using Black Scholes Merton Model.I have got stuck in R code. Mathematically, I want to solve this system of nonlinear equations with the package nleqslv :

library(nleqslv)
T <- 1
D1 <- 20010.75
R <- 0.8516
sigmaS <- .11
SO1 <- 1311.74
fnewton <- function(x){
  y <- numeric(2)
  d1 <- (log(x[1]/D1)+(R+x[2]^2/2)*T)/x[2]*sqrt(T)
  d2 <- d1 - x[2]*sqrt(T)
  y[1] <- SO1 - (x[1]*pnorm(d1) - exp(-R*T)*D1*pnorm(d2))
  y[2] <- sigmaS*SO1 - pnorm(d1)*x[2]*x[1]
  y
}

xstart <- c(1311.74,0.11)
nleqslv(xstart, fnewton, method="Broyden")
# $x
# [1] 1311.74    0.11

# $fvec
# [1] 1311.7400  144.2914

# $termcd
# [1] 6

# $message
# [1] "Jacobian is singular (see allowSingular option)"

# $scalex
# [1] 1 1

# $nfcnt
# [1] 0

# $njcnt
# [1] 1

# $iter
# [1] 1

I have tried this with many values of the 5 inputs( stated above that I have computed for 2 companies for different years), but I am not getting the final values of S0 and sigma V. I am getting message as "Jacobian is singular (see allowSingular option)" If I allow singular Jacobean using "control=list(trace=1,allowSingular=TRUE)", then also no answer is displayed. I do not know how to obtain the solution of these 2 variables now.

I really don't know, what I am doing wrong as I oriented my model on Teterevas slides ( on slide no.5 is her model code), who's presentation is the first result by googeling https://www.google.de/search?q=moodys+KMV+in+R&rlz=1C1SVED_enDE401DE401&aq=f&oq=moodys+KMV+in+R&aqs=chrome.0.57.13309j0&sourceid=chrome&ie=UTF-8#q=distance+to+default+in+R q=distance+to+default+in+R Like me, however more successful, she calculates the Distance to Default risk measure via the Black Scholes Merton approach. In this model, the value of equity (usually represented by the market capitalization, > SO1) can be written as a European call option.

The other variables are:

x[1]: the variable I want to derive, value of total assets   
x[2]: the variable I want to derive, volatility of total assets    
D1: the book value of debt (19982009)    
R: a riskfree interest rate   
T: is set to 1 year (time)    
sigmaS: estimated (historical) equity volatility

You should be able to use the initial values of SO1 and sigmaS as starting values for nleqslv .

First of all the R code given by Tetereva doesn't seem quite correct (the variable Z should be D1 as you have named it; similar changes for her S0 and D ). I have modified Tetereva's into this:

library(nleqslv)
T <- 1
D1 <- 33404048
R <- 2.32
sigmaS <- .02396919
SO1 <- 4740291  # Ve?
fnewton <- function(x){
  y <- numeric(2)
  d1 <- (log(x[1]/D1)+(R+x[2]^2/2)*T)/x[2]*sqrt(T)
  d2 <- d1 - x[2]*sqrt(T)
  y[1] <- SO1 - (x[1]*pnorm(d1) - exp(-R*T)*D1*pnorm(d2))
  y[2] <- sigmaS*SO1 - pnorm(d1)*x[2]*x[1]
  y
}

xstart <- c(SO1,sigmaS)

nleqslv(xstart, fnewton, method="Broyden",control=list(trace=1)) 
nleqslv(xstart, fnewton, method="Newton",control=list(trace=1))

which will give the solution given by Tetereva. (I use trace=1 here just to check the iteration steps.)

I believe the value you give for R should be 8.516 and not something else. Using your values for the parameters

T <- 1
D1 <- 20010.75
R <- 8.516  # modified
sigmaS <- .11
SO1 <- 1311.74

like this

xstart <- c(1311.74,0.11)
nleqslv(xstart, fnewton, method="Broyden")
nleqslv(xstart, fnewton, method="Newton")

Then running nleqslv with these values converges very quickly. If one uses R <- 2.32 (like Tetereva) nleqslv will also converge albeit with more iterations.

I cannot help you with what R should actually be but from Tetereva's presentation I assume R is in percentages. Since I don't have enough knowledge on the Black-Scholes model I can't be of any help for finding out what the correct values are for the various parameters. It's up to you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM