1
votes

I am getting an "non-numeric argument to binary operator" when running the code below;

    R = function(PD, AVC) {AVC*(0.12*(1-exp(-50*PD))/(1-exp(-50)) + 
                              0.24*(1-(1-exp(-50*PD))/(1-exp(-50))))}

b = function(PD) {(0.11852-0.05478*log(PD))^2}

integrand = function(PD=0.1, AVC =1, LGD = 1,q=0.999) {pnorm(sqrt(1/(1-R(PD, AVC)))*qnorm(PD) + 
                                                               sqrt(R(PD, AVC)/(1-R(PD, AVC)))*qnorm(q))}
integrate(integrand, lower = 0.999, upper = 1)

K_ES = function(PD,AVC =1, LGD = 1,q=0.999) {LGD/(1-q)*integrate(integrand, lower = q, upper = 1)-PD*LGD}

K_ES(PD=0.1,AVC =1, LGD = 1,q=0.999)

What might be causing this error and how do I resolve it?

1

1 Answers

0
votes

integrate returns a list, not a numeric vector. You probably want the value element:

K_ES = function(PD,
                AVC = 1,
                LGD = 1,
                q = 0.999) {
  LGD / (1 - q) * integrate(integrand, lower = q, upper = 1)$value - PD * LGD
}

K_ES(PD = 0.1, AVC = 1 , LGD = 1, q = 0.999)
# [1] 0.9