aboutsummaryrefslogtreecommitdiffstats
path: root/R/yieldcurve.R
diff options
context:
space:
mode:
Diffstat (limited to 'R/yieldcurve.R')
-rw-r--r--R/yieldcurve.R41
1 files changed, 15 insertions, 26 deletions
diff --git a/R/yieldcurve.R b/R/yieldcurve.R
index f7c6b47a..c0fc77de 100644
--- a/R/yieldcurve.R
+++ b/R/yieldcurve.R
@@ -33,28 +33,20 @@ getMarkitIRData <- function(date=Sys.Date()) {
return( xmlToList(paste(filename,".xml", sep="")) )
}
-basic.advance <- function(date, n, unit){
- ## advance a date by a given amount, whithout taking into account, business days
- ## n is the number of steps
- ## unit is the unit (belongs in "day", "month" or "year"
- stopifnot(class(date)=="Date")
- return(seq.Date(date, length=2, by=paste(n, unit))[2])
-
-}
-
thirdwed <- function(x) {
- d <- x - as.POSIXlt(x)$mday + 1
- n <- (3-as.POSIXlt(d)$wday) %% 7 + 1
- d + 14 + n - 1
+ d <- x - as.POSIXlt(x)$mday + 1
+ n <- (3-as.POSIXlt(d)$wday) %% 7 + 1
+ d + 14 + n - 1
}
nextthirdwed <- function(x) {
- y <- thirdwed(x)
- thirdwed(y + 30 * (y < x))
+ y <- thirdwed(x)
+ thirdwed(y + 30 * (y < x))
}
buildMarkitYC <- function(MarkitData, futurequotes, tradeDate=Sys.Date()){
settleDate <- advance(calendar="UnitedKingdom",dates=tradeDate, 2, 0)
+ names(settleDate) <- NULL
params <- list(tradeDate=tradeDate,
settleDate=settleDate,
dt=dt,
@@ -66,16 +58,15 @@ buildMarkitYC <- function(MarkitData, futurequotes, tradeDate=Sys.Date()){
short.term <- list(d1m=as.numeric(MarkitData$deposits[5]$curvepoint$parrate),
d3m=as.numeric(MarkitData$deposits[7]$curvepoint$parrate))
}else{
- immdate <- settleDate
for(i in seq_along(futurequotes)){
short.term[[paste0("fut",i)]] <- futurequotes[i]
- immdate <- nextthirdwed(immdate)
}
- #advance last futures date by 3 months
- lastfuturedate <- basic.advance(immdate, 3, "month")
+ ## get last imm date
+ lastimmdate <- nextthirdwed(advance(dates=tradeDate, n=21, timeUnit=2, bdc=4))
+ lastfuturematurity <- advance(dates=lastimmdate, n=3, timeUnit=2, bdc=4)
## find out the 2 year swap rate maturity
- s2ymaturity <- basic.advance(settleDate, 2, "year")
- if(s2ymaturity == lastfuturedate){
+ s2ymaturity <- advance(calendar="UnitedKingdom", dates=settleDate, 2, 3)
+ if(s2ymaturity == lastfuturematurity){
short.term[["fut8"]] <- NULL
}
}
@@ -105,8 +96,11 @@ exportYC <- function(tradedate=Sys.Date()){
futurequotes <- read.csv(file.path(root.dir, "data", "Yield Curves",
sprintf("futures-%s.csv", tradedate)), header=F)
##retrieve yield curve data
+ evaldate <- adjust(calendar="UnitedKingdom", dates=tradedate)
+ names(evaldate) <- NULL
+ setEvaluationDate(evaldate)
MarkitData <- getMarkitIRData(tradedate)
- Libor <- buildMarkitYC(MarkitData, futurequotes[,2], tradedate)
+ Libor <- buildMarkitYC(MarkitData, futurequotes[,2], evaldate)
L1m <- Libor
L2m <- Libor
L3m <- Libor
@@ -117,11 +111,6 @@ exportYC <- function(tradedate=Sys.Date()){
L3m$params$dt <- 1/4
L6m$params$dt <- 1/2
L12m$params$dt <- 1
- evaldate <- tradedate
- if(advance(calendar="TARGET",tradedate, 2, 0)!=Libor$params$settleDate){
- evaldate <- tradedate+1
- }
- setEvaluationDate(evaldate)
assign("L1m", L1m, env = parent.env(environment()))
assign("L2m", L2m, env = parent.env(environment()))
assign("L3m", L3m, env = parent.env(environment()))