aboutsummaryrefslogtreecommitdiffstats
path: root/R
diff options
context:
space:
mode:
Diffstat (limited to 'R')
-rw-r--r--R/calibration.R8
-rw-r--r--R/cds_functions_generic.R8
-rw-r--r--R/yieldcurve.R19
3 files changed, 15 insertions, 20 deletions
diff --git a/R/calibration.R b/R/calibration.R
index 040c8b8f..ea3c6d14 100644
--- a/R/calibration.R
+++ b/R/calibration.R
@@ -1,10 +1,4 @@
-if(.Platform$OS.type == "unix"){
- root.dir <- "/home/share/CorpCDOs"
-}else{
- root.dir <- "//WDSENTINEL/share/CorpCDOs"
-}
-source(file.path(root.dir, "code", "R", "cds_utils.R"))
-source(file.path(root.dir, "code", "R", "cds_functions_generic.R"))
+source("cds_functions_generic.R")
buildSC <- function(quote, cs, cdsdates){
SC <- new("creditcurve",
diff --git a/R/cds_functions_generic.R b/R/cds_functions_generic.R
index 53432c5b..be01c103 100644
--- a/R/cds_functions_generic.R
+++ b/R/cds_functions_generic.R
@@ -2,13 +2,7 @@ library("methods")
library("doParallel")
library("itertools")
-if(.Platform$OS.type == "unix"){
- root.dir <- "/home/share/CorpCDOs/"
-}else{
- root.dir <- "//WDSENTINEL/share/CorpCDOs/"
-}
-
-source(file.path(root.dir, "code/R/cds_utils.R"))
+source("cds_utils.R")
## TODO:
## - switch hazard rates and prepay curves to functions
diff --git a/R/yieldcurve.R b/R/yieldcurve.R
index 90f7b2ba..b117d6f6 100644
--- a/R/yieldcurve.R
+++ b/R/yieldcurve.R
@@ -1,4 +1,11 @@
require(RQuantLib)
+
+if(.Platform$OS.type == "unix"){
+ data.dir <- "/home/share/CorpCDOs/data"
+}else{
+ data.dir <- "//WDSENTINEL/share/CorpCDOs/data"
+}
+
getMarkitIRData <- function(date=Sys.Date()) {
## downloads the latest available interest rates data from Markit
## before date and returns the parsed file into a list
@@ -8,10 +15,10 @@ getMarkitIRData <- function(date=Sys.Date()) {
lastdate <- format(date-i, "%Y%m%d")
filename <- paste("InterestRates", "USD", lastdate, sep="_")
filename.ext <- paste0(filename,".xml")
- if( filename.ext %in% dir(file.path(root.dir, "/data/Yield Curves"))){
- return( xmlToList(file.path(root.dir, "data/Yield Curves", filename.ext)) )
+ if( filename.ext %in% dir(file.path(data.dir, "Yield Curves"))){
+ return( xmlToList(file.path(data.dir, "Yield Curves", filename.ext)) )
}else{
- temp <- tempfile(tmpdir = file.path(root.dir, "/data/Yield Curves"))
+ temp <- tempfile(tmpdir = file.path(data.dir, "Yield Curves"))
download.file(paste("http://www.markit.com/news/", filename, ".zip", sep=""), temp, quiet=T)
con <- file(temp, "r")
firstline <- readLines(con, 1, warn=FALSE)
@@ -24,9 +31,9 @@ getMarkitIRData <- function(date=Sys.Date()) {
cat("downloaded data for:", lastdate,"\n")
close(con)
## we unzip it
- unzip(temp, exdir = file.path(root.dir, "/data/Yield Curves"))
+ unzip(temp, exdir = file.path(data.dir, "Yield Curves"))
unlink(temp)
- return( xmlToList(file.path(root.dir, "data/Yield Curves", filename.ext)) )
+ return( xmlToList(file.path(data.dir, "Yield Curves", filename.ext)) )
}
}
}
@@ -93,7 +100,7 @@ buildMarkitYC <- function(MarkitData, futurequotes, tradeDate=Sys.Date()){
exportYC <- function(tradedate=Sys.Date()){
## export the Yield Curve into the environment
require(RQuantLib)
- futurefile <- file.path(root.dir, "data", "Yield Curves",
+ futurefile <- file.path(data.dir, "Yield Curves",
sprintf("futures-%s.csv", tradedate))
if(file.exists(futurefile)){
futurequotes <- read.csv(futurefile, header=F)