BookmarkSubscribeRSS Feed
raphaelchaves
Fluorite | Level 6

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;

5 REPLIES 5
sbxkoenk
SAS Super FREQ

Koen

raphaelchaves
Fluorite | Level 6

Dear all,

 

I am pleased to inform you that I have developed two distinct SAS macros designed to explain the Low Default Portfolio modeling approach suggested by Pluto & Tasche (https://arxiv.org/pdf/cond-mat/0411699v3). These macros account for both correlated and independent default events. I believe these tools will be highly valuable for the SAS community, particularly in the area of Credit Risk Modeling for Low Default or Zero Default portfolios.

 

Best regards,

Raphael Chaves

Rick_SAS
SAS Super FREQ

Thanks for posting. Your code is beautifully written and commented. I hope others will find it useful.

 

One small comment. I noticed the following lines in the LPD_CORRELATED_DEFAULT.sas file:

inverse_cdf = j(1,&SIMULATIONS-1,.);
do i = 1 to ncol(inverse_cdf);
   call symputx("j", i);
   inverse_cdf[i] = quantile('normal',num(symget("j"))/&SIMULATIONS);
end;

This code uses SYMPUTX to create a macro variable "j", then immediately gets the value, converts it to a numeric value, and uses it.  A more straightforward method is to use 

inverse_cdf[i] = quantile('normal',i/&SIMULATIONS);

directly in the loop.

 

And if you want to improve the efficiency of your SAS IML programs, you can try to replace loops with vector operations. For example, you can eliminate the loop altogether and instead use 

i = 1:(&SIMULATIONS-1);
inverse_cdf = quantile('normal',i/&SIMULATIONS);

Best wishes!

raphaelchaves
Fluorite | Level 6
Hi Ricky!
Thanks for providing me these improvements! Do you have any idea if SAS has any type of data lab, where users could submit some potential new features to be incorporated as part of SAS language? From my point of view, this one is a great example of function do be deployed as part of an particular SAS Proc Statement, such as: PROC LDPT

Regards
Raphael Chaves
Rick_SAS
SAS Super FREQ

Product suggestions can be made at SAS Product Suggestions - SAS Support Communities

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 5 replies
  • 1117 views
  • 5 likes
  • 3 in conversation