简体   繁体   English

R / BlackScholesMerton模型中的非线性方程组的求解

[英]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. 我正在编写Masters最终项目,其中使用Black Scholes Merton模型推导了违约概率,但我陷入了R代码中。 Mathematically, I want to solve this system of nonlinear equations with the package nleqslv : 在数学上,我想使用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. 我已经尝试使用5个输入的许多值来进行此操作(如上所述,我已经为2家公司计算了不同的年份),但是我没有得到S0和sigma V的最终值。我收到的消息是"Jacobian is singular (see allowSingular option)"如果我使用” control = list(trace = 1,allowSingular = TRUE)“允许使用奇异的Jacobean,则也不会显示任何答案。 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. 我真的不知道,当我将模型定位于Teterevas幻灯片时(在第5张幻灯片上是她的模型代码),我做错了什么,谁演示的是googeling https://www.google.de/的第一个结果搜索?q = moodys + KMV + in + R&rlz = 1C1SVED_enDE401DE401&aq = f&oq = moodys + KMV + in + R&aqs = chrome.0.57.1​​3309j0&sourceid = chrome&ie = UTF-8#q = distance + to + default + in + R + q = distance + to + default + in + R和我一样,尽管成功得多,她还是通过Black Scholes Merton方法计算了“违约距离”风险度量。 In this model, the value of equity (usually represented by the market capitalization, > SO1) can be written as a European call option. 在此模型中,权益价值(通常由市值表示,> SO1)可以写为欧洲看涨期权。

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 . 您应该能够将SO1sigmaS初始值用作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 ). 首先,Tetereva给出的R代码似乎不太正确(变量Z应该像您所命名的那样为D1 ;对她的S0D进行类似的更改)。 I have modified Tetereva's into this: 我已经将Tetereva修改为:

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. 这将提供Tetereva提供的解决方案。 (I use trace=1 here just to check the iteration steps.) (我在这里使用trace=1只是为了检查迭代步骤。)

I believe the value you give for R should be 8.516 and not something else. 我相信您给R的值应该是8.516,而不是其他。 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. 然后,使用这些值运行nleqslv很快收敛。 If one uses R <- 2.32 (like Tetereva) nleqslv will also converge albeit with more iterations. 如果使用R <- 2.32 -2.32(例如Tetereva), nleqslv也将收敛,尽管迭代次数更多。

I cannot help you with what R should actually be but from Tetereva's presentation I assume R is in percentages. 我不能帮助您确定R应该是多少,但是根据Tetereva的介绍,我认为R是百分比。 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. 由于我对Black-Scholes模型没有足够的了解,因此对于找出各种参数的正确值没有任何帮助。 It's up to you. 由你决定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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