#!/usr/bin/Rscript require(methods) library(logging) args <- commandArgs(trailingOnly=TRUE) if(.Platform$OS.type == "unix"){ root.dir <- "/home/share/CorpCDOs" }else{ root.dir <- "//WDSENTINEL/share/CorpCDOs" } basicConfig() removeHandler('basic.stdout') addHandler(writeToFile, file=file.path(root.dir, "logs", "calibrate_tranches_MF.log")) options(warn=2) code.dir <- if(Sys.getenv("CODE_DIR")!="") Sys.getenv("CODE_DIR") else root.dir source(file.path(code.dir, "code", "R", "yieldcurve.R")) source(file.path(code.dir, "code", "R", "optimization.R")) source(file.path(code.dir, "code", "R", "calibration.R"), chdir=TRUE) source(file.path(code.dir, "code", "R", "serenitasdb.R")) source(file.path(code.dir, "code", "R", "creditIndex.R")) source(file.path(code.dir, "code", "R", "tranche_functions.R")) ##figure out the tradedate if(length(args) >= 1){ tradedate <- as.Date(args[1]) }else{ tradedate <- addBusDay(Sys.Date(), -1) } exportYC(tradedate) ## calibrate HY23 ## calibrate the single names curves index <- creditIndex("hy23", "5yr") index <- set.index.desc(index, tradedate) index <- set.singlenamesdata(index, tradedate) ## load tranche data index <- set.tranchedata(index, tradedate) ##calibrate by modifying the factor distribution index$w.mod <- build.MFdist(index) dist <- MFlossdist(index) write.table(data.frame(Z=index$Z, w=index$w.mod), file=file.path(root.dir, "Scenarios", "Calibration", paste0("calibration-", tradedate, ".csv")), col.names=T, row.names=F, sep=",") save(index, dist, file = file.path(root.dir, "Scenarios", "Calibration", paste0("marketdata-", tradedate, ".RData")), compress="xz")