diff options
Diffstat (limited to 'python/risk/indices.py')
| -rw-r--r-- | python/risk/indices.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/python/risk/indices.py b/python/risk/indices.py index 1d4f338d..267e0181 100644 --- a/python/risk/indices.py +++ b/python/risk/indices.py @@ -143,3 +143,39 @@ def insert_curve_risk( strat_name = "*" if isinstance(strat, tuple) else strat c.execute(sql_str, (d, strat_name, var, "USD", fund)) conn.commit() + + +def insert_index_risk(d: datetime.date, conn: Connection, fund: str = "SERCGMAST"): + df = pd.read_sql_query( + "SELECT * FROM list_cds_positions_by_strat(%s, %s)", + conn, + params=(d, "SERCGMAST"), + ) + to_insert = [] + for t in df.itertuples(index=False): + ind = CreditIndex( + redcode=t.security_id, + maturity=t.maturity, + notional=t.notional, + value_date=d, + ) + ind.mark() + to_insert.append( + ( + d, + fund, + t.security_id, + t.maturity, + t.folder, + t.notional, + ind.factor, + ind.hy_equiv, + ) + ) + with conn.cursor() as c: + c.executemany( + "INSERT INTO index_risk VALUES (%s, %s, %s, %s, %s, %s, %s, %s) " + "ON CONFLICT (date, fund, security_id, maturity, folder) DO UPDATE " + "SET notional=EXCLUDED.notional, index_factor=EXCLUDED.index_factor, hy_equiv=EXCLUDED.hy_equiv", + to_insert, + ) |
