Dear all,
I have used the following R function in order to estimate the upper bound PD given the number of obligors and defaults, considering the Pluto & Tasche approach. I'd be so grateful if you tell me how can I achieve the same results, however, just using PROC IML and SAS native functions, instead of having the R running in the background?
Thanks in advance.
Rgs,
Raphael
proc iml;
submit / R;
# Estimates the Upper Pound PD given the number of obligors and defaults
plutotashe <- function(n, i, theta, rho, T, Conf, N) {
hh = uniroot(error, interval=c(0,1), lower=0.000000001, upper=0.999999999, tol = 1e-8, maxiter=500,
n=n, i=i, theta=theta, rho=rho, T=T, Conf=Conf, N=N)
names(hh) = c("UpperBoundPD", "Function", "iter", "estim.prec")
return(hh)
}
# Error Function
error <- function(pd, n, i, theta, rho, T, Conf, N) {
AverageSim = 1-mean(replicate(N, sim(pd,n,i,theta,rho, T)))
error = AverageSim-Conf
return(error)
}
# Simulation Run
sim = function(pd, n, i, theta, rho, T) {
# Generate a state of the economy
Z=array(0,c(T,1))
Z[1] = rnorm(1)
if (T > 1) {
for (j in 2:T) {
Z[j] = theta*Z[j-1]+sqrt(1-theta^2)*rnorm(1)
}
rm(j)
}
p = 1-prod(1 - pnorm((qnorm(pd)-Z*sqrt(rho))/sqrt(1-rho))) # Prob of Defaulting
(tt=binom_cum(n,p,i))
return(tt)
}
# Cumulative Binomial
binom_cum = function (n,p,i) {
bc = 0
for (j in 0:i) {
bc = bc + choose(n,j)*(p^j)*((1-p)^(n-j))
}
return(bc)
}
n <- 800 #number of obligors
i <- 0 #number of defaults
theta <- 0.30 #year-to-year correlation
rho <- 0.12 #asset correlation
T <- 5 #number of years
Conf <- 0.99 #confidence level
N <- 1000 #number of simulations
plutotashe(n, i, theta,rho,T,Conf, N)
endsubmit;
quit;