if(.Platform$OS.type == "unix"){ root.dir <- "/home/share/CorpCDOs" }else{ root.dir <- "//WDSENTINEL/share/CorpCDOs" } library(lossdistrib) n.int <- 250 gh <- GHquad(n.int) Ngrid <- 201 creditIndex <- function(name, tenor="5yr", Z=gh$Z, w=gh$w, N=Ngrid) { ## constructor for the index object ## FIXME: figure out what to do with the recovery r <- list(name=name, tenor=tenor, Z=Z, w=w, N=N, recovery=0.4) return( structure(r, class="creditIndex") ) } `$<-.creditIndex` <- function(x, name, value){ unclass(x) x[[name]] <- value class(x) <- "creditIndex" return(x) } c.creditIndex <- function(..., recursive = FALSE){ structure(c(unlist(lapply(list(...), unclass), recursive=FALSE)), class="creditIndex") } print.creditIndex <- function(index){ cat(index$name, index$tenor, as.character(index$tradedate), "\n\n") if("maturity" %in% names(index)){ cat("maturity:", as.character(index$maturity), "\n") cat("factor:", index$factor, "\n") cat("losstodate:", index$loss, "\n\n") } if("quotes" %in% names(index)){ cat("Index ref:", index$quotes$price*100, "\n") cat("Index basis:", index$basis, "\n\n") } row <- paste(index$K.orig[-length(index$K.orig)]*100, index$K.orig[-1]*100, sep="-") ##mapping to some prettier names colnames.toprint <- c("tranche.upf", "tranche.running", "thetas", "deltas", "forward.deltas", "gammas", "rho", "corr01") short.names <- c("upfront", "running", "theta", "delta", "fw.delta","gamma", "rho", "corr01") names(short.names) <- colnames.toprint colnames.available <- names(index)[names(index) %in% colnames.toprint] ##FIXME: need to check if it's bottom-up or top-down index$rho <- index$rho[-1] df <- data.frame(index[colnames.available], row.names=row) names(df) <- short.names[colnames.available] print(df, digits=4) } load.index <- function(name, tenor, date){ ## load a creditIndex which was previously saved load(file.path(root.dir, "Tranche_data", "Objects", paste0(paste(name, tenor, date, sep="_"),".RData"))) return(index) }