diff options
Diffstat (limited to 'python/cds_curve.py')
| -rw-r--r-- | python/cds_curve.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/python/cds_curve.py b/python/cds_curve.py index e315b309..1d2e244a 100644 --- a/python/cds_curve.py +++ b/python/cds_curve.py @@ -58,6 +58,8 @@ def calibrate_portfolio( index.theta(), index.duration(), pd.Series(index.tweaks, index=tenors, name="tweak"), + index.dispersion(), + index.dispersion(use_gini=True, use_log=False), ], axis=1, ) @@ -103,12 +105,18 @@ if __name__ == "__main__": else: tenors = ["3yr", "5yr", "7yr", "10yr"] g = calibrate_portfolio(index, series, tenors, start_date) + update_str = ",".join( + [ + f"{c}=EXCLUDED.{c}" + for c in ("theta", "duration", "tweak", "dispersion", "gini") + ] + ) with conn.cursor() as c: 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", - (id,) + tuple(t) + tuple(t), + "INSERT INTO index_risk2 VALUES(%s, %s, %s, %s, %s, %s) ON CONFLICT (id) " + f"DO UPDATE SET {update_str}", + (id,) + tuple(t), ) conn.commit() conn.close() |
