aboutsummaryrefslogtreecommitdiffstats
path: root/R
diff options
context:
space:
mode:
Diffstat (limited to 'R')
-rw-r--r--R/load_cf.R5
1 files changed, 4 insertions, 1 deletions
diff --git a/R/load_cf.R b/R/load_cf.R
index b2f4c1cb..51e47b70 100644
--- a/R/load_cf.R
+++ b/R/load_cf.R
@@ -173,7 +173,7 @@ getdealcf <- function(dealnames, workdate=Sys.Date()){
sqlstring <- sprintf("select marketvalue from latest_deal_model_numbers where dealname='%s'", dealname)
mv <- dbGetQuery(dbCon, sqlstring)$marketvalue
sqlstring <- sprintf(paste0("select \"Curr Collat Bal\", \"Reinv End Date\", ",
- "\"Deal Next Pay Date\" , maturity from ",
+ "\"Deal Next Pay Date\" , maturity, \"Principal Bal\" from ",
"historical_clo_universe('%s', '%s')"), dealname, workdate)
sqldata <- dbGetQuery(dbCon, sqlstring)
## to get the list of payment dates, we backtrack a little bit, because sometimes the first
@@ -236,6 +236,9 @@ getdealcf <- function(dealnames, workdate=Sys.Date()){
for(tranche in tranches){
cf <- cf+cfdata[[dealname]][[tranche]][,"Cashflow"]
}
+ if(sqldata$"Principal Bal" < 0){
+ cf <- cf-sqldata$"Principal Bal"
+ }
cfdata[[dealname]]$wapbasis <- (mean(cf)- cfdata[[dealname]]$mv)/cfdata[[dealname]]$mv
program <- KLfit(t(cf)/1e8, rep(1/n.scenarios, n.scenarios),
cfdata[[dealname]]$mv/1e8)