diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/risk/__main__.py | 4 | ||||
| -rw-r--r-- | python/risk/indices.py | 19 |
2 files changed, 15 insertions, 8 deletions
diff --git a/python/risk/__main__.py b/python/risk/__main__.py index dfd61eb7..e9c6c577 100644 --- a/python/risk/__main__.py +++ b/python/risk/__main__.py @@ -30,7 +30,9 @@ with dbconn("dawndb") as conn: for fund in ("SERCGMAST", "BOWDST"): portf = get_tranche_portfolio(workdate, conn, fund=fund) insert_tranche_portfolio(portf, conn) - insert_curve_risk(workdate, conn, ("SER_IGCURVE", "SER_ITRXCURVE", "XCURVE")) + insert_curve_risk( + workdate, conn, fund, ("SER_IGCURVE", "SER_ITRXCURVE", "XCURVE") + ) with dbconn("etdb") as etconn, dbconn("dawndb") as dawnconn: diff --git a/python/risk/indices.py b/python/risk/indices.py index e1f576d7..50aebe66 100644 --- a/python/risk/indices.py +++ b/python/risk/indices.py @@ -5,7 +5,7 @@ from analytics.curve_trades import on_the_run from analytics.index_data import index_returns from math import sqrt from psycopg2.extensions import connection -from typing import Tuple, Union +from typing import Iterable, Tuple, Union def get_index_portfolio( @@ -13,7 +13,7 @@ def get_index_portfolio( conn: connection, fund: str = "SERCGMAST", strategies: Union[Tuple[str], None] = None, - exclude_redcode=(), + exclude_redcode: Iterable[str] = (), **kwargs ): sql_str = ( @@ -92,20 +92,25 @@ def VaR(portf: Portfolio, quantile=0.05, years: int = 5, period="monthly"): def insert_curve_risk( - d: datetime.date, conn: connection, strategies: Tuple[str] = ("SER_IGCURVE",) + d: datetime.date, + conn: connection, + fund: str = "SERCGMAST", + strategies: Tuple[str] = ("SER_IGCURVE",), ): sql_str = ( - "INSERT INTO curve_risk VALUES(%s, %s, %s, %s) " + "INSERT INTO curve_risk VALUES(%s, %s, %s, %s, %s) " "ON CONFLICT (date, strategy) DO UPDATE SET " - '"VaR"=excluded."VaR", currency=excluded.currency' + '"VaR"=excluded."VaR", currency=excluded.currency, fund=excluded.fund' ) # add a portfolio with all strategies strategies = (*strategies, strategies) with conn.cursor() as c: for strat in strategies: - portf = get_index_portfolio(d, conn, strat, exclude_redcode=["2I65BYDU6"]) + portf = get_index_portfolio( + d, conn, fund, strat, exclude_redcode=("2I65BYDU6",) + ) if portf: var = VaR(portf, period="daily") strat_name = "*" if isinstance(strat, tuple) else strat - c.execute(sql_str, (d, strat_name, var, "USD")) + c.execute(sql_str, (d, strat_name, var, "USD", fund)) conn.commit() |
