aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--R/build_portfolios.R33
-rw-r--r--R/cds_functions_generic.R24
-rw-r--r--R/intex_deal_functions.R17
-rw-r--r--sql/et_tables.sql12
4 files changed, 52 insertions, 34 deletions
diff --git a/R/build_portfolios.R b/R/build_portfolios.R
index 31c34000..1b49a287 100644
--- a/R/build_portfolios.R
+++ b/R/build_portfolios.R
@@ -80,33 +80,40 @@ for(deal.name in dealnames){
S <- 1 - sapply(deal.portfolio$SC, attr, "recov")
deal.weights <- deal.portfolio$notional/sum(deal.portfolio$notional)
deal.dates <- getdealschedule(deal.data)
- deal.spread <- portfoliospread(deal.portfolio, hy19$maturity)
+ deal.spread5y <- portfoliospread(deal.portfolio, hy19$maturity)
+ deal.spreadatmaturity <- portfoliospread(deal.portfolio)
save.dir <- file.path(root.dir, "Scenarios", paste("Portfolios", workdate, sep="_"))
if(!file.exists(save.dir)){
dir.create(save.dir)
}
- save(deal.portfolio, A, S, deal.weights, deal.dates, deal.spread,
- file=file.path(save.dir, paste0(deal.name, ".RData")))
+ save(deal.portfolio, A, S, deal.weights, deal.dates, deal.spread5y,
+ deal.spreadatmaturity, file=file.path(save.dir, paste0(deal.name, ".RData")))
cat(deal.name, "... done\n")
dealupdatedate <- currdealnames$updatedate[currdealnames$dealname %in% deal.name]
if(length(dealupdatedate) && dealupdatedate == workdate){
- sqlstring <- sprintf(paste0("UPDATE et_deal_model_numbers SET dealspread = %s, cdopercentage = %s,",
- "stalepercentage= %s WHERE dealname= '%s' and updatedate = '%s'"),
- deal.spread,
- deal.portfolio$cdopercentage,
- deal.portfolio$stale,
- deal.name,
- as.Date(workdate))
+ sqlstring <- sprintf(
+ paste0("UPDATE et_deal_model_numbers SET dealspread5y = %s,",
+ "dealspread = %s, cdopercentage = %s, stalepercentage= %s ",
+ "WHERE dealname= '%s' and updatedate = '%s'"),
+ deal.spread5y,
+ deal.spreadatmaturity,
+ deal.portfolio$cdopercentage,
+ deal.portfolio$stale,
+ deal.name,
+ as.Date(workdate))
dbGetQuery(dbCon, sqlstring)
}else{
sqlstring <- sprintf(paste0("INSERT INTO et_deal_model_numbers ",
- "VALUES('%s', %s, %s, %s, %s, '%s')"),
+ "VALUES('%s', %s, %s, %s, %s, '%s', '%s')"),
deal.name,
deal.portfolio$cdopercentage,
deal.portfolio$stale,
- deal.spread,
+ deal.spread5y,
crossprod(deal.portfolio$notional, deal.portfolio$price)/100,
- workdate)
+ workdate,
+ NULL,
+ deal.spreadatmaturity
+ )
dbGetQuery(dbCon, sqlstring)
currdealnames <- c(currdealnames, deal.name)
}
diff --git a/R/cds_functions_generic.R b/R/cds_functions_generic.R
index b1fd4dfc..1491db69 100644
--- a/R/cds_functions_generic.R
+++ b/R/cds_functions_generic.R
@@ -537,10 +537,18 @@ indexspread <- function(portfolio, index){
}
portfoliospread <- function(portfolio, maturity){
- ## computes the spread of a portfolio of survival curves and notional for a given maturity
+ ## computes the spread of a portfolio defined by notionals and survivalcurves
+ ## for a given maturity.
+ ## if maturity is missing, we use the intrinsic maturity for each curve
S <- 0
d <- rep(0, length(portfolio$SC))
+ if(missing(maturity)){
+ maturityvec <- as.Date(sapply(portfolio$SC, creditcurve.maturity), origin="1970-01-01")
+ }
for(i in 1:length(portfolio$SC)){
+ if(missing(maturity)){
+ maturity <- maturityvec[i]
+ }
d[i] <- cdsduration(portfolio$SC[[i]]@curve, maturity) * portfolio$notional[i]
S <- S + d[i] * cdsspread(portfolio$SC[[i]]@curve, maturity, portfolio$SC[[i]]@recovery)
}
@@ -685,3 +693,17 @@ forwardportfolioprice <- function(portfolio, startdate, maturity, coupontype, ma
}
return(mean(r))
}
+
+
+creditcurve.maturity <- function(creditcurve){
+ if(class(creditcurve)=="creditcurve"){
+ dates <- creditcurve@curve@dates
+ if(length(dates)){
+ return( dates[length(dates)] )
+ }else{
+ return( creditcurve@startdate )
+ }
+ }else{
+ stop("not of class creditcurve")
+ }
+}
diff --git a/R/intex_deal_functions.R b/R/intex_deal_functions.R
index 251c5fed..2ed3f2fa 100644
--- a/R/intex_deal_functions.R
+++ b/R/intex_deal_functions.R
@@ -137,20 +137,6 @@ fithazardrate <- function(collateral){
return( optimize(f, c(0,1), tol=1e-6)$minimum )
}
-
-maturity <- function(creditcurve){
- if(class(creditcurve)=="creditcurve"){
- dates <- creditcurve@curve@dates
- if(length(dates)){
- return( dates[length(dates)] )
- }else{
- return( creditcurve@startdate )
- }
- }else{
- stop("not of class creditcurve")
- }
-}
-
stackcurve <- function(SC, line.item, global.params, startdate){
if(line.item$nextpaydate> line.item$maturity){
SC@curve@hazardrates <- 0
@@ -239,7 +225,7 @@ buildSC <- function(line.item, reinvdate, dealmaturity, global.params, startdate
SC@curve <- try
}
}
- if(!is.na(reinvdate) && maturity(SC) <= reinvdate){
+ if(!is.na(reinvdate) && creditcurve.maturity(SC) <= reinvdate){
## if reinvdate is missing, assume no reinvestment
## otherwise reinvest
newstartdate <- line.item$maturity
@@ -288,6 +274,7 @@ buildSC.portfolio <- function(dealname, dealdata, cusipdata, global.params, star
cdonotional <- cdonotional + line.item$currentbalance
}else{
if(is.na(line.item$price)){
+ browser()
missingpricenotional <- missingpricenotional + line.item$currentbalance
}
}
diff --git a/sql/et_tables.sql b/sql/et_tables.sql
index f0eb185f..3d674c59 100644
--- a/sql/et_tables.sql
+++ b/sql/et_tables.sql
@@ -451,14 +451,15 @@ CREATE OR REPLACE FUNCTION et_cusip_details(p_cusips VARIADIC varchar(10)[])
RETURNS TABLE(orig_moody text, curr_moody text, empty1 unknown, issuer text,
manager text, empty2 unknown, spread float, issuedate date,
reinvenddate date, maturity date, stale_percentage float,
- cdo_percentage float, wap_basis float, portfolio_spread float,
- subordination float, thickness float, empty3 unknown, pricingdate date,
- delta float, duration float, wal float, price float) AS $$
+ cdo_percentage float, wap_basis float, portfolio_spread_5y float,
+ portfolio_spread float, subordination float, thickness float,
+ empty3 unknown, pricingdate date, delta float, duration float, wal float, price float) AS $$
BEGIN
RETURN QUERY SELECT a.Orig_Moody, a.Curr_Moody, NULL, b."Deal Name", b.manager, NULL,
a.Spread/100, b."Deal Issue Date", b."Reinv End Date", b.Maturity,
- e.stalepercentage, greatest(b."CDO Percentage"/100, e.cdopercentage), e.wapbasis, e.dealspread,
- a.subordination, a.thickness, NULL, d.updatedate, d.delta, d.duration, d.wal, d.price
+ e.stalepercentage, greatest(b."CDO Percentage"/100, e.cdopercentage), e.wapbasis,
+ e.dealspread5y, e.dealspread, a.subordination, a.thickness, NULL, d.updatedate,
+ d.delta, d.duration, d.wal, d.price
FROM latest_cusip_universe a LEFT JOIN latest_clo_universe b
ON a.dealname = b.dealname
LEFT JOIN latest_deal_model_numbers e
@@ -558,6 +559,7 @@ CREATE TABLE et_deal_model_numbers(
cdopercentage float,
stalepercentage float,
dealspread float,
+ dealspread5y float,
marketvalue float,
updatedate date,
wapbasis float,