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.py11
1 files changed, 5 insertions, 6 deletions
diff --git a/python/cds_curve.py b/python/cds_curve.py
index 7408e0e1..67851f33 100644
--- a/python/cds_curve.py
+++ b/python/cds_curve.py
@@ -37,7 +37,7 @@ def build_curve(r, today_date, yc, start_date, step_in_date, value_date, end_dat
if len(sc) != end_dates.shape[0]:
sc = fill_curve(sc, end_dates)
except ValueError as e:
- print(e)
+ print(r[0], e)
return None
return sc
@@ -97,12 +97,11 @@ def calibrate_portfolio(index_type, series, tenors=['3yr', '5yr', '7yr', '10yr']
else:
recovery = 0.3
index_quotes = (get_index_quotes(index_type, series,
- tenors)['closeprice'].
+ tenors, years=None)['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 " \
@@ -113,8 +112,8 @@ def calibrate_portfolio(index_type, series, tenors=['3yr', '5yr', '7yr', '10yr']
index_quotes.columns = index_desc.loc[index_quotes.columns, "maturity"]
index_quotes = 1 - index_quotes / 100
issue_date = index_desc.issue_date[0]
- index_desc = index_desc.set_index('maturity')
maturities = index_quotes.columns.sort_values().to_pydatetime()
+ index_desc = index_desc.reset_index().set_index('maturity')
start_date = start_date or index_quotes.index.get_level_values(0)[0]
index_quotes = index_quotes[start_date:]
curves, _ = get_singlenames_curves(index_type, series, start_date)
@@ -159,12 +158,12 @@ def calibrate_portfolio(index_type, series, tenors=['3yr', '5yr', '7yr', '10yr']
tweak.append(eps)
r[trade_date] = pd.DataFrame({'duration': duration,
'theta': theta,
- 'tweak': tweak}, index=tenors)
+ 'tweak': tweak}, index=quotes.tenor)
return pd.concat(r)
if __name__=="__main__":
enable_logging()
- index, series = "IG", 23
+ index, series = "IG", 21
df = calibrate_portfolio(index, series, ['3yr', '5yr', '7yr', '10yr'])
conn = dbconn('serenitasdb')
with conn.cursor() as c: