1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
library(XML)
getMarkitIRData <- function(date=Sys.Date()) {
## downloads the latest available interest rates data from Markit
## before date and returns the parsed file into a list
require(XML)
i <- 0
temp <- tempfile()
while( TRUE ) {
lastdate <- format(date-i,"%Y%m%d")
filename <- paste("InterestRates_USD_", lastdate, sep="")
download.file(paste("http://www.markit.com/news/", filename, ".zip", sep=""), temp, quiet=T)
con <- file(temp, "r")
firstline <- readLines(con, 1)
# Markit returns a plain text file if there is no data.
if(firstline == "Interest Rates not available, please check date entered") {
i <- i + 1
close(con)
} else {
cat("downloaded data for:", lastdate,"\n")
close(con)
# we unzip it
unzip(temp)
unlink(temp)
break
}
}
return( xmlToList(paste(filename,".xml", sep="")) )
}
buildMarkitYC <- function(MarkitData, dt=0.25){
settledate <- as.Date(MarkitData$deposits$spotdate)
params <- list(tradeDate=as.Date(MarkitData$effectiveasof,format="%Y-%m-%d"),
settleDate=settledate,
dt=dt,
interpWhat="discount",
interpHow="loglinear")
tsQuotes <- list(d1m=as.numeric(MarkitData$deposits[5]$curvepoint$parrate),
#d2m=as.numeric(MarkitData$deposits[6]$curvepoint$parrate),
d3m=as.numeric(MarkitData$deposits[7]$curvepoint$parrate),
## d6m=as.numeric(MarkitData$deposits[8]$curvepoint$parrate),
## d9m=as.numeric(MarkitData$deposits[9]$curvepoint$parrate),
## d1y=as.numeric(MarkitData$deposits[10]$curvepoint$parrate),
s2y=as.numeric(MarkitData$swaps[8]$curvepoint$parrate),
s3y=as.numeric(MarkitData$swaps[9]$curvepoint$parrate),
#s4y=as.numeric(MarkitData$swaps[10]$curvepoint$parrate),
s5y=as.numeric(MarkitData$swaps[11]$curvepoint$parrate),
#s6y=as.numeric(MarkitData$swaps[12]$curvepoint$parrate),
#s7y=as.numeric(MarkitData$swaps[13]$curvepoint$parrate),
#s8y=as.numeric(MarkitData$swaps[14]$curvepoint$parrate),
#s9y=as.numeric(MarkitData$swaps[15]$curvepoint$parrate),
s10y=as.numeric(MarkitData$swaps[16]$curvepoint$parrate),
#s12y=as.numeric(MarkitData$swaps[17]$curvepoint$parrate),
s15y=as.numeric(MarkitData$swaps[18]$curvepoint$parrate),
s20y=as.numeric(MarkitData$swaps[19]$curvepoint$parrate),
#s25y=as.numeric(MarkitData$swaps[20]$curvepoint$parrate),
s30y=as.numeric(MarkitData$swaps[21]$curvepoint$parrate))
YC.USD <- list(params=params, tsQuotes=tsQuotes)
return( YC.USD )
}
|