aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--R/build_portfolios.R4
-rw-r--r--R/load_cf.R10
2 files changed, 9 insertions, 5 deletions
diff --git a/R/build_portfolios.R b/R/build_portfolios.R
index 468b37e1..4fd2d561 100644
--- a/R/build_portfolios.R
+++ b/R/build_portfolios.R
@@ -11,6 +11,7 @@ if(.Platform$OS.type == "unix"){
source(file.path(root.dir, "code", "R", "intex_deal_functions.R"))
source(file.path(root.dir, "code", "R", "index_definitions.R"))
source(file.path(root.dir, "code", "R", "cds_utils.R"))
+source(file.path(root.dir, "code", "R", "cds_functions_generic.R"))
if(length(args) >=2){
dealnames <- args[-1]
@@ -70,7 +71,7 @@ global.params$beta <- 15
global.params$shape <- function(T)0.5+(1-0.5)*(1-exp(-T/5))
global.params$reinvflag <- TRUE
cusipdata <- cusip.data()
-
+cashspread.discount <- 0.01
currdealnames <- dbGetQuery(dbCon, "select updatedate, dealname from latest_deal_model_numbers")
## build portfolio data
for(i in seq_along(dealnames)){
@@ -89,6 +90,7 @@ for(i in seq_along(dealnames)){
next
}
deal.portfolio <- buildSC.portfolio(deal.name, deal.data, cusipdata, global.params, workdate)
+ ##deal.portfolio$SC <- tweakportfolio(deal.portfolio$SC, -cashspread.discount, multiplicative=FALSE)
A <- SPmatrix2(deal.portfolio$SC, deal.data, freq="3 months", workdate)
S <- 1 - sapply(deal.portfolio$SC, attr, "recov")
deal.weights <- deal.portfolio$notional/sum(deal.portfolio$notional)
diff --git a/R/load_cf.R b/R/load_cf.R
index b312bf4c..ebd8956b 100644
--- a/R/load_cf.R
+++ b/R/load_cf.R
@@ -31,7 +31,7 @@ L3m <- buildMarkitYC(MarkitData)
L6m <- buildMarkitYC(MarkitData, dt = 1/2)
L12m <- buildMarkitYC(MarkitData, dt = 1)
setEvaluationDate(as.Date(MarkitData$effectiveasof))
-
+dm <- 0
sanitize.column <- function(vec){
vec <- gsub(",", "", vec)
index <- grep("\\(", vec)
@@ -120,7 +120,8 @@ getdealcf <- function(dealnames, workdate=Sys.Date()){
if(length(futuredates) == 0){
df <- rep(1, length(pastdates))
}else{
- df <- c(rep(1, length(pastdates)), DC$discounts[1:length(futuredates)])
+ df.dm <- exp(-dm*yearFrac(L3m$params$tradeDate, futuredates))
+ df <- c(rep(1, length(pastdates)), df.dm*DC$discounts[1:length(futuredates)])
}
if(nrow(data)>0){
pv <- c(pv, crossprod(df, data[,field]))
@@ -196,13 +197,14 @@ getcusipcf <- function(cusips, cfdata, dist, workdate=Sys.Date()){
}
futuredates <- data$Date[data$Date >= L3m$params$tradeDate]
pastdates <- data$Date[data$Date < L3m$params$tradeDate]
+ T <- yearFrac(L3m$params$tradeDate, futuredates)
if(i==1||length(futuredates)>length(DC$times)){
- DC <- DiscountCurve(L3m$params, L3m$tsQuotes, yearFrac(L3m$params$tradeDate, futuredates))
+ DC <- DiscountCurve(L3m$params, L3m$tsQuotes, T)
}
if(length(futuredates) == 0){
df <- rep(1, length(pastdates))
}else{
- df <- c(rep(1, length(pastdates)), DC$discounts[1:length(futuredates)])
+ df <- c(rep(1, length(pastdates)), DC$discounts[1:length(futuredates)]*exp(-dm*T))
}
pv <- c()
for(field in fields){