I am receiving a "non-numeric argument to binary operator" when executing the below code:
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)