diff options
Diffstat (limited to 'R')
| -rw-r--r-- | R/tranches_RV_BC.R | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/R/tranches_RV_BC.R b/R/tranches_RV_BC.R index 9576481c..e5179d7d 100644 --- a/R/tranches_RV_BC.R +++ b/R/tranches_RV_BC.R @@ -26,16 +26,15 @@ args <- parse_args(OptionParser(option_list=option_list, description=
"This script prices index2 using the skew from index1."))
if(is.null(args$config)){
- if(is.null(args$index) || is.null(args$index2)){
+ if(is.null(args$index1) || is.null(args$index2)){
stop("Please provide both index1 and index2")
}
- runs <- list(name1=args$index1, name2=args$index2, tenor1=args$tenor1, tenor2=args$tenor2)
+ runs <- list(mappings=list(c(args$index1, args$tenor1, args$index2, args$tenor2)))
}else{
library(yaml)
runs <- yaml.load_file(file.path(root.dir, "code", "etc", args$config))
}
-source(file.path(root.dir, "code", "R", "yieldcurve.R"))
source(file.path(root.dir, "code", "R", "optimization.R"))
source(file.path(root.dir, "code", "R", "calibration.R"), chdir=TRUE)
source(file.path(root.dir, "code", "R", "serenitasdb.R"))
@@ -68,7 +67,7 @@ for(r in runs$mappings){ }
alldates <- seq(begin.date, as.Date(as.character(args$until)), by="1 day")
bus.dates <- alldates[isBusinessDay(calendar="UnitedStates/GovernmentBond", alldates)]
-
+ addheaders <- TRUE
for(j in seq_along(bus.dates)){
tradedate <- bus.dates[j]
index1 <- load.index(index.name1, tenor1, tradedate)
@@ -82,20 +81,21 @@ for(r in runs$mappings){ mappedpv <- list()
for(method in c("ATM", "TLP", "PM")){
index2$rho <- adjust.skew(index1, index2, method)
- if(length(grep("ig", index2$name))>0){
+ if(substr(index2$name, 1, 2) %in% c("ig", "xo")){
mappedpv[[method]] <- BCtranche.pv(index2, protection=TRUE)$bp + accrued2
}else{
mappedpv[[method]] <- BCtranche.pv(index2)$bp - accrued2
}
}
row <- c(as.character(tradedate), index2$tranches$upfront, unlist(mappedpv)*100)
- if(j==1 && !args$update){
+ if(addheaders && !args$update){
headers <- c("date", paste(index2$name, row.names(index2$tranches), "Quotes"),
paste(index2$name, row.names(index2$tranches), "ATM PV"),
paste(index2$name, row.names(index2$tranches), "TLP PV"),
paste(index2$name, row.names(index2$tranches), "PM PV"))
cat(paste(headers, collapse=","), "\n", file=filename)
}
+ addheaders <- FALSE
cat(paste(row, collapse=","), sep="\n", file=filename, append=TRUE)
}
|
