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.py12
1 files changed, 5 insertions, 7 deletions
diff --git a/python/cds_curve.py b/python/cds_curve.py
index 80903c91..69ae8623 100644
--- a/python/cds_curve.py
+++ b/python/cds_curve.py
@@ -31,7 +31,6 @@ def all_curves_pv(curves, today_date, jp_yc, start_date, step_in_date, value_dat
def calibrate_portfolio(index_type, series, tenors=['3yr', '5yr', '7yr', '10yr'],
start_date=None):
index = MarkitBasketIndex(index_type, series, tenors)
- r = []
if start_date:
index.index_quotes = index.index_quotes[start_date:]
for value_date, v in index.index_quotes.groupby('date')['id']:
@@ -40,9 +39,8 @@ def calibrate_portfolio(index_type, series, tenors=['3yr', '5yr', '7yr', '10yr']
df = pd.concat([index.theta(),
index.duration(),
pd.Series(index.tweaks, index=tenors, name='tweak')], axis=1)
- df.index = v.values
- r.append(df)
- return pd.concat(r)
+ for (_, t), id in v.items():
+ yield (id, df.loc[t])
if __name__ == "__main__":
@@ -68,12 +66,12 @@ if __name__ == "__main__":
else:
start_date = None
- df = calibrate_portfolio(index, series, ['3yr', '5yr', '7yr', '10yr'],
+ g = calibrate_portfolio(index, series, ['3yr', '5yr', '7yr', '10yr'],
start_date)
with conn.cursor() as c:
- for t in df.itertuples():
+ for id, t in g:
c.execute("INSERT INTO index_risk2 VALUES(%s, %s, %s, %s) ON CONFLICT (id) "
"DO UPDATE SET theta=%s, duration=%s, tweak=%s",
- t + t[1:])
+ (id,) + tuple(t) + tuple(t))
conn.commit()
conn.close()