diff options
| -rw-r--r-- | R/cds_utils.R | 14 | ||||
| -rw-r--r-- | R/load_cf.R | 8 | ||||
| -rw-r--r-- | R/tests/test_yieldcurve.R | 2 | ||||
| -rw-r--r-- | R/yieldcurve.R | 31 |
4 files changed, 23 insertions, 32 deletions
diff --git a/R/cds_utils.R b/R/cds_utils.R index 90c71d28..9e5a44ae 100644 --- a/R/cds_utils.R +++ b/R/cds_utils.R @@ -72,12 +72,14 @@ couponSchedule <- function(nextpaydate=NULL, maturity, frequency, coupontype, cu }
names(dates) <- NULL
- DC <- switch(frequency,
- S = DiscountCurve(L6m$params, L6m$tsQuotes, yearFrac(L6m$params$tradeDate, dates)),
- Q = DiscountCurve(L3m$params, L3m$tsQuotes, yearFrac(L3m$params$tradeDate, dates)),
- M = DiscountCurve(L1m$params, L1m$tsQuotes, yearFrac(L1m$params$tradeDate, dates)),
- B = DiscountCurve(L2m$params, L2m$tsQuotes, yearFrac(L2m$params$tradeDate, dates)),
- A = DiscountCurve(L12m$params, L12m$tsQuotes, yearFrac(L12m$params$tradeDate, dates)))
+ dt <- switch(frequency,
+ S = 1/2,
+ Q = 1/4,
+ M = 1/12,
+ B = 1/6,
+ A = 1)
+ DC <- DiscountCurve(c(YC$params, list(dt=dt)),
+ YC$tsQuotes, yearFrac(YC$params$tradeDate, dates), YC$legparams)
if(toupper(coupontype)=="FLOAT" && !is.na(margin)){
## if is.na(margin) probably letter of credit
diff --git a/R/load_cf.R b/R/load_cf.R index 1110b97d..6165540c 100644 --- a/R/load_cf.R +++ b/R/load_cf.R @@ -94,8 +94,8 @@ getdealcf <- function(dealnames, zipfiles, tradedate=Sys.Date()){ alldates <- getdealschedule(dealdata, "1 month")
config <- getconfig(dealname, tradedate)
- T <- ifelse(alldates>=L3m$params$tradeDate, yearFrac(L3m$params$tradeDate, alldates), 0)
- DC <- DiscountCurve(L3m$params, L3m$tsQuotes, T)
+ T <- ifelse(alldates>=YC$params$tradeDate, yearFrac(YC$params$tradeDate, alldates), 0)
+ DC <- DiscountCurve(c(YC$params, list(dt=0.25)), YC$tsQuotes, T, YC$legparams)
df <- data.table(Date=alldates,
Discounts=DC$discounts,
T=T, key="Date")
@@ -223,8 +223,8 @@ getcusipcf <- function(params, cfdata, dist, tradedate=Sys.Date()){ dealname <- dealnames[i]
dealdata <- getdealdata(dealname, tradedate)
alldates <- getdealschedule(dealdata, "1 month", adjust=TRUE)
- T <- ifelse(alldates>=L3m$params$tradeDate, yearFrac(L3m$params$tradeDate, alldates), 0)
- DC <- DiscountCurve(L3m$params, L3m$tsQuotes, T)
+ T <- ifelse(alldates>=YC$params$tradeDate, yearFrac(YC$params$tradeDate, alldates), 0)
+ DC <- DiscountCurve(c(YC$params, list(dt=0.25)), YC$tsQuotes, T, YC$legparams)
df <- data.table(Date=alldates,
Discounts=DC$discounts,
T=T, key="Date")
diff --git a/R/tests/test_yieldcurve.R b/R/tests/test_yieldcurve.R index 7adcb813..6b1930eb 100644 --- a/R/tests/test_yieldcurve.R +++ b/R/tests/test_yieldcurve.R @@ -10,6 +10,6 @@ for(i in 1:length(dates)){ print(day) if(isBusinessDay(calendar="UnitedStates", day)){ exportYC(calibration.date) - test <- DiscountCurve(L3m$params, L3m$tsQuotes, 1) + test <- DiscountCurve(c(YC$params, list(dt=0.25)), YC$tsQuotes, 1, YC$legparams) } } diff --git a/R/yieldcurve.R b/R/yieldcurve.R index 163ac94e..94762c25 100644 --- a/R/yieldcurve.R +++ b/R/yieldcurve.R @@ -107,16 +107,15 @@ exportYC <- function(tradedate=Sys.Date(), currency="USD", useFutures=FALSE){ stop("wrong date")
}
sDate <- as.Date(MarkitData$deposits$spotdate[[1]])
- curveType <- sprintf("%s/%s", "Markit", currency)
- if(.Platform$OS.type == "unix"){
- setCalendarContext(calendar="WeekendsOnly", fixingDays=2,
- settleDate=sDate,
- curveType=curveType)
- }else{
- setCalendarContext(calendar="UnitedKingdom", fixingDays=2,
- settleDate=sDate)
- }
-
+ setCalendarContext(calendar="WeekendsOnly", fixingDays=2,
+ settleDate=sDate)
+ legparams <- switch(currency,
+ USD = list(fixFreq="Semiannual",
+ floatFreq="Quarterly",
+ dayCounter="Thirty360"),
+ EUR = list(fixfreq="Annual",
+ floatFreq="Semiannual",
+ dayCounter="Thirty360"))
params <- list(tradeDate=tradedate,
settleDate=sDate,
interpWhat="discount",
@@ -126,15 +125,5 @@ exportYC <- function(tradedate=Sys.Date(), currency="USD", useFutures=FALSE){ }else{
quotes <- buildMarkitYC(MarkitData, currency)
}
- L1m <- L2m <- L3m <- L6m <- L12m <- list(params=params, tsQuotes=quotes)
- L1m$params$dt <- 1/12
- L2m$params$dt <- 1/6
- L3m$params$dt <- 1/4
- L6m$params$dt <- 1/2
- L12m$params$dt <- 1
- assign("L1m", L1m, env = parent.env(environment()))
- assign("L2m", L2m, env = parent.env(environment()))
- assign("L3m", L3m, env = parent.env(environment()))
- assign("L6m", L6m, env = parent.env(environment()))
- assign("L12m", L12m, env = parent.env(environment()))
+ YC <<- list(params=params, tsQuotes=quotes, legparams=legparams)
}
|
