aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--R/creditIndex.R35
1 files changed, 34 insertions, 1 deletions
diff --git a/R/creditIndex.R b/R/creditIndex.R
index 8ef15093..e3002b3f 100644
--- a/R/creditIndex.R
+++ b/R/creditIndex.R
@@ -90,7 +90,7 @@ csvheaders <- function(index){
}
tocsv <- function(index){
- ##write a one line csv representation of the index object
+ ## write a one line csv representation of the index object
if(class(index)!="creditIndex"){
stop("argument needs to be of class creditIndex")
}
@@ -101,3 +101,36 @@ tocsv <- function(index){
unlist(index$tranches[c("corr01", "duration", "EL")]))
return(paste(row, collapse=","))
}
+
+sqlArray <- function(vec){
+ vec[is.na(vec)] <- "NULL"
+ return( sprintf("Array[%s]", paste(vec, collapse=",")) )
+}
+
+sqlQuote <- function(s){
+ return( sprintf("'%s'", s) )
+}
+
+tosql <- function(index){
+ ## write sql representation of the index object
+ values <- c(sqlQuote(index$tradedate),
+ sqlQuote(index$type),
+ sqlQuote(index$series),
+ sqlQuote(index$tenor),
+ index$quotes$price,
+ index$basis,
+ index$EL,
+ index$duration,
+ index$theta,
+ sqlArray(as.integer(index$K.orig*100)),
+ sqlArray(index$rho[-1]),
+ sqlArray(index$tranches$mkt.delta),
+ sqlArray(index$tranches$delta),
+ sqlArray(index$tranches$fw.delta),
+ sqlArray(index$tranches$gamma),
+ sqlArray(index$tranches$theta),
+ sqlArray(index$tranches$corr01),
+ sqlArray(index$tranches$duration),
+ sqlArray(index$tranches$EL))
+ sprintf("INSERT INTO risk_numbers VALUES(%s)",paste(values,collapse=","))
+}