aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--R/calibrate_tranches_BC.R8
-rw-r--r--R/tranche_functions.R10
-rw-r--r--python/dates.py2
-rw-r--r--python/pnl_explain.py4
4 files changed, 13 insertions, 11 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))) )
}
}
diff --git a/python/dates.py b/python/dates.py
index fbdc7d98..025949b6 100644
--- a/python/dates.py
+++ b/python/dates.py
@@ -11,7 +11,7 @@ bond_cal = HolidayCalendarFactory('BondCalendar', fed_cal, GoodFriday)
bus_day = CustomBusinessDay(calendar=bond_cal())
def imm_dates(start_date, end_date):
- start_date = bus_day.rollback(start_date)-19*Day()
+ start_date = bus_day.rollback(start_date) - 19 * Day()
start_date = QuarterBegin(startingMonth=3).rollback(start_date)
#should be close=left I think
return (pd.date_range(start_date, end_date, freq='QS-MAR', closed=None).
diff --git a/python/pnl_explain.py b/python/pnl_explain.py
index 0be46854..25af238e 100644
--- a/python/pnl_explain.py
+++ b/python/pnl_explain.py
@@ -4,7 +4,7 @@ import pandas as pd
from db import dbengine
from dates import bus_day, imm_dates, yearfrac
-def get_daycount(identifier, engine = dbengine("dawndb")):
+def get_daycount(identifier, engine=dbengine("dawndb")):
""" retrieve daycount and paydelay for a given identifier"""
conn = engine.raw_connection()
with conn.cursor() as c:
@@ -19,7 +19,7 @@ def get_daycount(identifier, engine = dbengine("dawndb")):
return a, b
def pnl_explain(identifier, start_date = None, end_date = None,
- engine = dbengine("dawndb")):
+ engine=dbengine("dawndb")):
""" if start_date is None, pnl since inception"""
trades = pd.read_sql_query("SELECT * FROM bonds where identifier=%s", engine,
params=(identifier,), parse_dates=['trade_date', 'settle_date'])