diff options
| -rw-r--r-- | R/cds_functions_generic.R | 10 | ||||
| -rw-r--r-- | R/cds_utils.R | 24 | ||||
| -rw-r--r-- | R/yieldcurve.R | 15 |
3 files changed, 23 insertions, 26 deletions
diff --git a/R/cds_functions_generic.R b/R/cds_functions_generic.R index 64176812..9bfccb86 100644 --- a/R/cds_functions_generic.R +++ b/R/cds_functions_generic.R @@ -857,19 +857,17 @@ forward.prot <- function(index, exerciseDate){ defaultAdjustedForwardIndexPrice <- function(index, exerciseDate, fixedRate=0.05){
tes <- addBusDay(exerciseDate)
- df <- DiscountCurve(c(YC$params, list(dt=0.25)), YC$tsQuotes, yearFrac(index$tradedate, tes),
- YC$legparams)$discounts
+ df <- discountFactors(YC, tes)
price <- 1 - FEP(index, exerciseDate) +
- 1/df*(forward.cl(index, exerciseDate)*fixedRate -
- forward.prot(index, exerciseDate)-cdsAccrued(exerciseDate, fixedRate))
+ 1/df * (forward.cl(index, exerciseDate) * fixedRate -
+ forward.prot(index, exerciseDate) - cdsAccrued(exerciseDate, fixedRate))
return( price )
}
forwardflatcds <- function(h, cs, tradeDate, exerciseDate, fixedRate=0.05, R=0.4){
tes <- addBusDay(exerciseDate)
fep <- (1-R)*(1-exp(-h*yearFrac(tradeDate, exerciseDate)))
- df <- DiscountCurve(c(YC$params, list(dt=0.25)), YC$tsQuotes, yearFrac(tradeDate, tes),
- YC$legparams)$discounts
+ df <- discountFactors(YC, tes)
sc <- new("flatcurve", h=h)
cl <- couponleg(cs, sc, startdate=exerciseDate)
pl <- defaultleg(cs, sc, recovery=R, startdate=exerciseDate)
diff --git a/R/cds_utils.R b/R/cds_utils.R index 95dbca65..4c352163 100644 --- a/R/cds_utils.R +++ b/R/cds_utils.R @@ -75,19 +75,17 @@ couponSchedule <- function(nextpaydate=NULL, maturity, }
names(dates) <- NULL
- dt <- switch(frequency,
- Semiannual = 1/2,
- Quarterly = 1/4,
- Monthly = 1/12,
- Bimonthly = 1/6,
- Annual = 1)
- DC <- DiscountCurve(c(YC$params, list(dt=dt)),
- YC$tsQuotes, yearFrac(YC$params$tradeDate, dates), YC$legparams)
-
+ period <- switch(frequency,
+ Semiannual = "6m",
+ Quarterly = "3m",
+ Monthly = "1m",
+ Bimonthly = "2m",
+ Annual = "1y")
+ forwards <- forwardRates(YC, dates, period)
if(is.na(coupontype) || (toupper(coupontype)=="FLOAT" && !is.na(margin))){
## if is.na(margin) probably letter of credit
## we floor the coupon at the current gross rate
- coupons <- pmax(currentcoupon, DC$forwards + margin)
+ coupons <- pmax(currentcoupon, forwards + margin)
}else{
coupons <- rep(currentcoupon, length(dates))
}
@@ -96,10 +94,10 @@ couponSchedule <- function(nextpaydate=NULL, maturity, yf[length(yf)] <- yf[length(yf)]+1/360
coupons <- yf * coupons
- if(tradedate!=DC$params$tradeDate){
- df <- cumprod(exp(-DC$forwards * diff(c(0, yearFrac(tradedate, dates)))))
+ if(tradedate != referenceDate(YC)){
+ df <- cumprod(exp(-forwards * diff(c(0, yearFrac(tradedate, dates)))))
}else{
- df <- DC$discounts
+ df <- discountFactors(YC, dates)
}
return( data.frame(dates=dates, unadj.dates = unadj.dates, coupons=coupons, df = df) )
}
diff --git a/R/yieldcurve.R b/R/yieldcurve.R index 1841c123..c745fb3c 100644 --- a/R/yieldcurve.R +++ b/R/yieldcurve.R @@ -1,11 +1,12 @@ require(RQuantLib)
-
-if(.Platform$OS.type == "unix"){
- data.dir <- "/home/share/CorpCDOs/data"
+root.dir <- if(.Platform$OS.type == "unix"){
+ "/home/share/CorpCDOs"
}else{
- data.dir <- "//WDSENTINEL/share/CorpCDOs/data"
+ "//WDSENTINEL/share/CorpCDOs"
}
+source(file.path(root.dir, "code", "R", "db.R"))
+
getMarkitIRData <- function(date=Sys.Date(), currency=c("USD", "EUR")) {
## returns Markit rates from serenitasdb
currency <- match.arg(currency)
@@ -73,9 +74,9 @@ exportYC <- function(tradedate=Sys.Date(), currency=c("USD", "EUR"), useFutures }
}
MarkitData <- getMarkitIRData(tradedate, currency)
- evaldate <- as.Date(tradedate)
setEvaluationDate(tradedate)
- sDate <- advance(calendar="WeekendsOnly", tradedate, 2, 0)
+ ## sDate <- advance(calendar="WeekendsOnly", tradedate, 2, 0)
+ sDate <- tradedate
setCalendarContext(calendar="WeekendsOnly", fixingDays=2,
settleDate=sDate)
legparams <- switch(currency,
@@ -94,5 +95,5 @@ exportYC <- function(tradedate=Sys.Date(), currency=c("USD", "EUR"), useFutures }else{
quotes <- buildMarkitYC(MarkitData, currency)
}
- YC <<- list(params=params, tsQuotes=quotes, legparams=legparams)
+ YC <<- DiscountCurve(YC$params, YC$tsQuotes, YC$legparams)
}
|
