aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--python/calibrate_tranches_BC.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/python/calibrate_tranches_BC.py b/python/calibrate_tranches_BC.py
new file mode 100644
index 00000000..7b55ae38
--- /dev/null
+++ b/python/calibrate_tranches_BC.py
@@ -0,0 +1,52 @@
+from db import dbconn, dbengine
+from analytics import TrancheBasket
+import datetime
+import pandas as pd
+from yaml import load
+
+start_dates = {'ig19': datetime.date(2013, 5, 1),
+ 'ig21': datetime.date(2013, 9, 26),
+ 'ig23': datetime.date(2014, 10, 14),
+ 'ig25': datetime.date(2015, 9, 22),
+ 'ig27': datetime.date(2016, 9, 27),
+ 'ig29': datetime.date(2017, 9, 26),
+ 'ig31': datetime.date(2018, 9, 25)}
+
+serenitas_engine = dbengine('serenitasdb')
+
+with open("/home/guillaume/projects/code/etc/runs.yml") as fh:
+ runs = load(fh)['runs']
+ for index, tenor in runs:
+ print(index, tenor)
+ if index not in start_dates:
+ continue
+ else:
+ begin_date = start_dates[index]
+ index, series = index[:2].upper(), int(index[2:])
+ tranche_index = TrancheBasket(index, series, tenor)
+ dr = pd.bdate_range(begin_date, "2018-10-10")
+ for d in dr:
+ print(d)
+ try:
+ tranche_index.value_date = d
+ except ValueError as e:
+ print(e)
+ continue
+ tranche_index.tweak()
+ tranche_index.build_skew()
+ df = pd.concat([tranche_index.tranche_deltas(),
+ tranche_index.tranche_thetas(),
+ tranche_index.tranche_fwd_deltas(),
+ tranche_index.tranche_durations(),
+ tranche_index.tranche_EL(),
+ tranche_index.tranche_spreads()], axis=1)
+ df['index_duration'], df['index_expected_loss'], df['index_price'] = tranche_index.index_pv()
+ df['index_expected_loss'] *= -1
+ df['index_duration'] -= tranche_index.accrued()
+ df['index_basis'] = tranche_index.tweaks[0]
+ df['index_theta'] = tranche_index.theta()[tenor]
+ df['tranche_id'] = tranche_index.tranche_quotes.id.values
+ df['corr_at_detach'] = tranche_index.rho[1:]
+ df['corr01'] = tranche_index.tranche_corr01()
+ del df['fwd_gamma']
+ df.to_sql("tranche_risk", serenitas_engine, if_exists='append', index=False)