[R-SIG-Finance] Credit Migration Matrix

Konrad Hoppe konradhoppe at hotmail.de
Tue Jan 12 16:53:30 CET 2010


Hi Rick,

I wrote a small code snippet for you. It calculates the credit migration for
one institute. You can pack it in a function and apply it to every institute
you want to. But be careful with the relative proportions, I'm not deep in
this topic and unsure about the exact definition.


# credit migration:

#sampling the data:
dat <- sample(c("A","AA","AAA"), 100, replace=T)

# give numerical names for the ratings:
dat[which(dat=="A")] <- 1
dat[which(dat=="AA")] <- 2
dat[which(dat=="AAA")] <- 3
dat <- as.numeric(dat)

migrationMat <- matrix(0,nrow=3,ncol=3)

for(i in 1:(length(dat)-1)){
	origin <- dat[i]
	target <- dat[i+1]
	migrationMat[origin,target] <- migrationMat[origin,target]+1
}
rownames(migrationMat) <- c("A","AA","AAA")
colnames(migrationMat) <- c("A","AA","AAA")

#relative proportions:
migrationMatRel <- matrix(0, nrow=3,ncol=3)

for(i in 1:nrow(migrationMat)){
	for(j in 1:ncol(migrationMat)){
		migrationMatRel[i,j] <-
migrationMat[i,j]/sum(migrationMat[,j])
	}
}
rownames(migrationMatRel) <- c("A","AA","AAA")
colnames(migrationMatRel) <- c("A","AA","AAA")
migrationMatRel


All the best,
--
Konrad Hoppe
http://www.konrad-hoppe.com/

-----Ursprüngliche Nachricht-----
Von: r-sig-finance-bounces at stat.math.ethz.ch
[mailto:r-sig-finance-bounces at stat.math.ethz.ch] Im Auftrag von Ricardo
Ginçalves Silva
Gesendet: Dienstag, 12. Januar 2010 15:41
An: R-Finance
Betreff: [R-SIG-Finance] Credit Migration Matrix

Dear Users,

I  would like to know how can I compute credit rating migration matrix using
R.
I have 10 years data (monthly rates for each firm) and I would like 
to compute 12 (and more) months ahead migrations.
Any hints? Or a general purpose code to do it?

Best 

Rick
	[[alternative HTML version deleted]]

_______________________________________________
R-SIG-Finance at stat.math.ethz.ch mailing list

-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions
should go.



More information about the R-SIG-Finance mailing list