Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PD <- c(0.05,0.10,0.50,1,2,5,25)/100
- total <- c(5,10,20,25,20,15,5)/100
- raw <- rbind(PD,total)*100
- defaulted <- total*PD
- nondefaulted <- total*(1-PD)
- n <- sum(total)
- portfolio <- rbind(defaulted,nondefaulted)/n
- portfolio
- ### ASE
- x <- portfolio
- wr <- n^2-sum(sapply(1:nrow(x), function(i) sum(x[i,])^2))
- A <- function(x,i,j) {
- xr <- nrow(x)
- xc <- ncol(x)
- sum(x[1:xr>i,1:xc>j])+sum(x[1:xr<i,1:xc<j])
- }
- D <- function(x,i,j) {
- xr <- nrow(x)
- xc <- ncol(x)
- sum(x[1:xr>i,1:xc<j])+sum(x[1:xr<i,1:xc>j])
- }
- Pf <- function(x) {
- xr <- nrow(x)
- xc <- ncol(x)
- tmp <- NULL
- for (i in 1:xr)
- for (j in 1:xc)
- tmp <- c(tmp,x[i,j]*A(x,i,j))
- sum(tmp)
- }
- Qf <- function(x) {
- xr <- nrow(x)
- xc <- ncol(x)
- tmp <- NULL
- for (i in 1:xr)
- for (j in 1:xc)
- tmp <- c(tmp,x[i,j]*D(x,i,j))
- sum(tmp)
- }
- P <- Pf(x)
- Q <- Qf(x)
- # ASE1
- tmp2 <- NULL
- for (i in 1:nrow(x))
- for (j in 1:ncol(x))
- tmp2 <- c( tmp2, x[i,j] * ( wr*(A(x,i,j)-D(x,i,j)) - (P-Q)*(sum(x)-sum(x[i,])) )^2 )
- # ASE0
- tmp <- NULL
- for (i in 1:nrow(x))
- for (j in 1:ncol(x))
- tmp <- c( tmp, x[i,j]*(A(x,i,j)-D(x,i,j))^2 )
- # Somers' D
- # -0.6839158
- (P-Q)/wr
- # ASE1
- # 2.378
- 2/wr^2*sqrt(sum(tmp2))
- # ASE0 - hypothesis of independence
- 2/wr*sqrt( sum(tmp)-(P-Q)^2/sum(x) )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement