diff options
| -rw-r--r-- | R/load_cf.R | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/R/load_cf.R b/R/load_cf.R index e798b78a..0b5e7b55 100644 --- a/R/load_cf.R +++ b/R/load_cf.R @@ -113,7 +113,8 @@ getdealcf2 <- function(tb){ setkey(df, Date)
setkey(tb, Date)
tb[,Balance:=max(Balance-`Accum Interest Shortfall`, 0), by=1:nrow(tb)]
- sqlstring <- sprintf("select cusip, dealname, curr_balance, spread from latest_cusip_universe where cusip in ('%s')", paste(cusips, collapse="','"))
+ sqlstring <- sprintf(paste("select cusip, dealname, curr_balance, spread from historical_cusip_universe",
+ "where cusip in ('%s')"), paste(cusips, collapse="','"))
cusipdata <- data.table(dbGetQuery(dbCon, sqlstring), key="cusip")
data <- tb[df][,list(Cashflow=temp <- sum(Cashflow*Discounts),
Principal=sum(Principal*Discounts),
@@ -175,7 +176,7 @@ getdealcf <- function(dealnames, workdate=Sys.Date()){ mv <- dbGetQuery(dbCon, sqlstring)$marketvalue
sqlstring <- sprintf(paste0("select \"Curr Collat Bal\", \"Reinv End Date\", ",
"maturity from ",
- "latest_clo_universe where dealname='%s'"), dealname)
+ "historical_clo_universe('%s', '%s')"), dealname, workdate)
sqldata <- dbGetQuery(dbCon, sqlstring)
alldates <- rev(seq.Date(from=sqldata$maturity, to=workdate-90, by="-1 month"))
@@ -264,7 +265,8 @@ getcusipcf <- function(cusips, cfdata, dist, workdate=Sys.Date()){ T=T, key="Date")
r <- matrix(0, n.scenarios, 5)
colnames(r) <- c(fields, "wal", "duration")
- sqlstring <- sprintf("select curr_balance, spread from latest_cusip_universe where cusip = '%s'", cusip)
+ sqlstring <- sprintf("select curr_balance, spread from historical_cusip_universe('%s', '%s')",
+ cusip, workdate)
indicdata <- dbGetQuery(dbCon, sqlstring)
for(j in 1:n.scenarios){
filename <- sprintf("%s-CF-Scen%s.txt", cusip, j)
|
