aboutsummaryrefslogtreecommitdiffstats
path: root/R/creditIndex.R
diff options
context:
space:
mode:
Diffstat (limited to 'R/creditIndex.R')
-rw-r--r--R/creditIndex.R46
1 files changed, 21 insertions, 25 deletions
diff --git a/R/creditIndex.R b/R/creditIndex.R
index 7d8859a3..a2421869 100644
--- a/R/creditIndex.R
+++ b/R/creditIndex.R
@@ -99,29 +99,25 @@ tocsv <- function(index){
return(paste(row, collapse=","))
}
-tosql <- function(index){
- ## write sql representation of the index object
- 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))
+as.data.frame.creditIndex <- function(index) {
+ data.frame(tranche_id = index$tranches$id,
+ date = index$tradedate,
+ index = index$type,
+ series = index$series,
+ tenor = index$tenor,
+ index_price = index$quotes$price,
+ index_basis = index$basis,
+ index_el = index$EL,
+ index_duration = index$duration,
+ index_theta = index$theta,
+ attach = as.integer(index$K.orig[-length(index$K.orig)]*100),
+ detach = as.integer(index$K.orig[-1]*100),
+ corr_at_detach = index$rho[-1],
+ delta = index$tranche$delta,
+ forward_delta = index$tranche$fw.delta,
+ gamma = index$tranches$gamma,
+ theta = index$tranches$theta,
+ corr01 = index$tranches$corr01,
+ duration = index$tranches$duration,
+ EL = index$tranches$EL)
}