if(.Platform$OS.type == "unix"){ root.dir <- "/home/share/CorpCDOs" }else{ root.dir <- "//WDSENTINEL/share/CorpCDOs" } 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")) source(file.path(root.dir, "code", "R", "creditIndex.R")) library(lossdistrib) alldates <- seq(as.Date("2013-10-04"), as.Date("2014-09-02"), by="1 day") bus.dates <- as.Date(names(which(isBusinessDay(calendar="UnitedStates/GovernmentBond", alldates)))) index.name1 <- "hy21" tenor1 <- "3yr" index.name2 <- "hy17" tenor2 <- "5yr" filename <- file.path(root.dir,"Tranche_data","Runs", paste0(paste(index.name2, tenor2, "using", index.name1, tenor1),".csv")) for(i in seq_along(bus.dates)){ tradedate <- bus.dates[i] index1 <- load.index(index.name1, tenor1, tradedate) index2 <- load.index(index.name2, tenor2, tradedate) tradedate <- bus.dates[i] accrued2 <- cdsAccrued(tradedate, index2$tranches$running) mappedpv <- list() for(method in c("ATM", "TLP", "PM")){ index2$rho <- adjust.skew(index1, index2, method) mappedpv[[method]] <- BCtranche.pv(index2)$bp - accrued2 } row <- c(as.character(tradedate), index2$tranches$upfront, unlist(mappedpv)*100) if(i==1){ 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) } cat(paste(row, collapse=","), "\n", file=filename, append=TRUE) }