aboutsummaryrefslogtreecommitdiffstats
path: root/R
diff options
context:
space:
mode:
Diffstat (limited to 'R')
-rw-r--r--R/calibrate_tranches_BC.R8
-rw-r--r--R/tranche_functions.R10
2 files changed, 10 insertions, 8 deletions
diff --git a/R/calibrate_tranches_BC.R b/R/calibrate_tranches_BC.R
index 37a44e2a..c52ec88d 100644
--- a/R/calibrate_tranches_BC.R
+++ b/R/calibrate_tranches_BC.R
@@ -3,7 +3,7 @@ code.dir <- Sys.getenv("CODE_DIR")
tranchedata.dir <- file.path(Sys.getenv("BASE_DIR"), "Tranche_data")
library(logging)
basicConfig()
-if(!interactive()){
+if(!interactive()) {
removeHandler('basic.stdout')
addHandler(writeToFile, file=file.path(Sys.getenv("LOG_DIR"), "calibrate_tranches_BC.log"))
library(optparse)
@@ -18,12 +18,12 @@ if(!interactive()){
help="last date to run [default %default]"))
args <- parse_args(OptionParser(option_list=option_list))
## default values
- if(is.null(args$config)){
- if(is.null(args$index)){
+ if(is.null(args$config)) {
+ if(is.null(args$index)) {
stop("Please provide an index name")
}
config <- list(runs=list(c(args$index, args$tenor)))
- }else{
+ } else {
config <- yaml::yaml.load_file(file.path(code.dir, "etc", args$config))
}
} else {
diff --git a/R/tranche_functions.R b/R/tranche_functions.R
index b33ec339..41d55295 100644
--- a/R/tranche_functions.R
+++ b/R/tranche_functions.R
@@ -214,7 +214,7 @@ adjust.skew <- function(index1, index2, method=c("ATM", "TLP", "PM")) {
pmax(pmin(x, 0.99), 0.01)
}
- if(method=="ATM") {
+ if(method == "ATM") {
K1eq <- el1/el2 * K2
} else if(method == "TLP") {
K1eq <- c()
@@ -280,6 +280,8 @@ BCtranche.delta <- function(index, complement=FALSE) {
deltas <- (bp[,2]-bp[,3])/(indexbp[2]-indexbp[3])*tranche.factor(index)/index$factor
deltasplus <- (bp[,4]-bp[,1])/(indexbp[4]-indexbp[1])*tranche.factor(index)/index$factor
+ print(deltas)
+ print(deltasplus)
gammas <- (deltasplus-deltas)/(indexbp[2]-indexbp[1])/100
return( data.frame(delta=deltas, gamma=gammas) )
@@ -354,10 +356,10 @@ EL <- function(index, discounted=TRUE, shortened=0) {
df <- index$cs$df[1:(Ncol-shortened)]
}
ELvec <- as.numeric(crossprod(index$issuerweights * (1-index$recov), DP))
- if(!discounted){
+ if(!discounted) {
return( ELvec[length(ELvec)] )
- }else{
- return( sum(df*diff(c(0, ELvec))) )
+ } else {
+ return( sum(df*diff(c(0, ELvec))) )
}
}