aboutsummaryrefslogtreecommitdiffstats
path: root/R/creditIndex.R
diff options
context:
space:
mode:
Diffstat (limited to 'R/creditIndex.R')
-rw-r--r--R/creditIndex.R50
1 files changed, 40 insertions, 10 deletions
diff --git a/R/creditIndex.R b/R/creditIndex.R
index 9748d6e4..b1f15a42 100644
--- a/R/creditIndex.R
+++ b/R/creditIndex.R
@@ -35,21 +35,19 @@ print.creditIndex <- function(index){
cat("losstodate:", index$loss, "\n\n")
}
if("quotes" %in% names(index)){
- cat("Index ref:", index$quotes$price*100, "\n")
+ cat("Index ref:", index$quotes$ref, "\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]
+ colnames.toprint <- c("upfront", "running", "mkt.delta", "delta",
+ "gamma", "theta", "corr01")
+ available.colnames <- colnames.toprint[colnames.toprint %in% names(index$tranches)]
+ df <- index$tranches[available.colnames]
##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]
+ if(!is.null(index$rho)){
+ df <- cbind(df, data.frame(rho=index$rho[-1]))
+ }
print(df, digits=4)
}
@@ -59,3 +57,35 @@ load.index <- function(name, tenor, date){
paste0(paste(name, tenor, date, sep="_"),".RData")))
return(index)
}
+
+csvheaders <- function(index){
+ if(class(index)!="creditIndex"){
+ stop("argument needs to be of class creditIndex")
+ }
+ tranche.names <- row.names(index$tranches)
+ headers <- c("date", "indexprice", "indexref", "indexBasis", "indexEL", "indexTheta",
+ paste(tranche.names, "Upfront"),
+ paste(tranche.names, "Dealer Delta"),
+ paste(tranche.names, "Model Delta"),
+ paste(tranche.names, "Forward Deltas"),
+ paste(tranche.names, "Gamma"),
+ paste(tranche.names, "Theta"),
+ paste(index$K.orig[-1]*100, "Corr"),
+ paste(tranche.names, "Corr01"),
+ paste(tranche.names, "Dur"),
+ paste(tranche.names, "EL"))
+ return(paste(headers, collapse=","))
+}
+
+tocsv <- function(index){
+ ##write a one line csv representation of the index object
+ if(class(index)!="creditIndex"){
+ stop("argument needs to be of class creditIndex")
+ }
+ row <- c(as.character(index$tradedate), index$quotes$price, index$quotes$ref, index$basis,
+ index$EL, index$theta,
+ unlist(index$tranches[c("upfront", "mkt.delta", "delta", "fw.delta","gamma",
+ "theta")]), index$rho[-1],
+ unlist(index$tranches[c("corr01", "duration", "EL")]))
+ return(paste(row, collapse=","))
+}