aboutsummaryrefslogtreecommitdiffstats
path: root/R/creditIndex.R
diff options
context:
space:
mode:
Diffstat (limited to 'R/creditIndex.R')
-rw-r--r--R/creditIndex.R43
1 files changed, 23 insertions, 20 deletions
diff --git a/R/creditIndex.R b/R/creditIndex.R
index 5fff04f8..cbad046d 100644
--- a/R/creditIndex.R
+++ b/R/creditIndex.R
@@ -104,24 +104,27 @@ tocsv <- function(index){
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=","))
+ params <- list(index$tradedate,
+ index$type,
+ index$series,
+ 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))
+ dollars <- paste(lapply(1:length(params), function(i)sprintf("$%s",i)),
+ collapse=",")
+ return(list(stmt=sprintf("INSERT INTO risk_numbers VALUES(%s)", dollars),
+ params=params))
}