diff options
| -rw-r--r-- | R/calibrate_tranches_BC.R | 4 | ||||
| -rw-r--r-- | R/creditIndex.R | 43 |
2 files changed, 26 insertions, 21 deletions
diff --git a/R/calibrate_tranches_BC.R b/R/calibrate_tranches_BC.R index 345cca70..0dd9d047 100644 --- a/R/calibrate_tranches_BC.R +++ b/R/calibrate_tranches_BC.R @@ -118,7 +118,9 @@ for(i in seq_along(runs$name)){ cat(csvheaders(index), sep="\n", file=filename)
}
cat(tocsv(index), sep="\n", file=filename, append=TRUE)
- r <- dbSendQuery(serenitasdb, tosql(index))
+
+ r <- with(tosql(index),
+ dbSendQuery(serenitasdb, stmt, params))
if(dbHasCompleted(r)){
dbClearResult(r)
}
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)) } |
