aboutsummaryrefslogtreecommitdiffstats
path: root/python/cds_curve.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/cds_curve.py')
-rw-r--r--python/cds_curve.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/python/cds_curve.py b/python/cds_curve.py
index a0d14089..2d9c3dbe 100644
--- a/python/cds_curve.py
+++ b/python/cds_curve.py
@@ -118,8 +118,13 @@ def calibrate_portfolio(index_type, series, tenors=['3yr', '5yr', '7yr', '10yr']
recovery = 0.4
else:
recovery = 0.3
- index_quotes = get_index_quotes(index_type, series,
- tenors)['closeprice'].unstack()
+ index_quotes = (get_index_quotes(index_type, series,
+ tenors)['closeprice'].
+ unstack().
+ reset_index(level='version').
+ groupby(level='date').nth(0).
+ set_index('version', append=True))
+
index_desc = pd.read_sql_query("SELECT tenor, maturity, coupon * 1e-4 AS coupon, " \
"issue_date "\
"FROM index_maturity " \
@@ -135,11 +140,16 @@ def calibrate_portfolio(index_type, series, tenors=['3yr', '5yr', '7yr', '10yr']
curves, _ = get_singlenames_curves(index_type, series, issue_date)
index = CreditIndex(issue_date, maturities, curves)
r = {}
+ old_version = 1
for k, s in index_quotes.iterrows():
- trade_date = k[0]
+ trade_date, version = k
curves, args = get_singlenames_curves(index_type, series, trade_date)
_, jp_yc, _, step_in_date, value_date, _ = args
- index.curves = [c for _, c in curves]
+ if version > old_version:
+ old_version = version
+ index = CreditIndex(issue_date, maturities, curves)
+ else:
+ index.curves = [c for _, c in curves]
tweak, duration, theta = [], [], []
s.name = 'index_quote'
quotes = pd.concat([index_desc, s], axis=1)