diff options
| -rw-r--r-- | python/position.py | 22 | ||||
| -rw-r--r-- | sql/dawn.sql | 16 | ||||
| -rw-r--r-- | sql/serenitasdb.sql | 8 |
3 files changed, 44 insertions, 2 deletions
diff --git a/python/position.py b/python/position.py index f7df233a..789c4afe 100644 --- a/python/position.py +++ b/python/position.py @@ -224,6 +224,27 @@ def update_swap_rates(conn, session, c.execute(sql_str, data[ticker]) conn.commit() +def update_cash_rates(conn, session, start_date=None): + securities = {"FEDL01 Index": "FED_FUND", + "US0001M Index": "1M_LIBOR", + "US0003M Index": "3M_LIBOR"} + if start_date is None: + data = retrieve_data(session, list(securities.keys()), + ["PX_LAST", "LAST_UPDATE_DT"]) + else: + data = retrieve_data(session, list(securities.keys()), + ["PX_LAST"], start_date=start_date.date()) + sql_str = "INSERT INTO rates VALUES(%s, %s, %s) ON CONFLICT DO NOTHING" + with conn.cursor() as c: + if start_date is None: + for k, v in data.items(): + c.execute(sql_str, (v["LAST_UPDATE_DT"], securities[k], v["PX_LAST"])) + else: + for k, v in data.items(): + for d, r in v["PX_LAST"].items(): + c.execute(sql_str, (d, securities[k], r)) + conn.commit() + def populate_cashflow_history(engine, session, workdate=None, fund="SERCGMAST"): securities = get_list(engine, workdate, fund=fund) data = retrieve_data(session, securities.index.tolist(), @@ -283,6 +304,7 @@ if __name__ == "__main__": populate_cashflow_history(dawn_engine, session, workdate, "BRINKER") update_fx(dawn_conn, session, ['EURUSD', 'CADUSD']) update_swap_rates(serenitas_conn, session) + data = update_cash_rates(serenitas_conn, session) for vol_type in ["N", "V"]: update_swaption_vol(serenitas_conn, session, vol_type=vol_type) serenitas_pool.putconn(serenitas_conn) diff --git a/sql/dawn.sql b/sql/dawn.sql index 6482803b..443dfe8b 100644 --- a/sql/dawn.sql +++ b/sql/dawn.sql @@ -1284,14 +1284,15 @@ CREATE TYPE INDEXFAMILY AS ENUM('ITRAXX-Asian', 'LCDXNA', 'MCDXNA', 'ITRAXX-SOVX', 'ITRAXX-SDI', 'ITRAXX-L', 'CDX', 'ITRAXX-European'); CREATE TYPE curr AS ENUM('USD', 'EUR', 'JPY', 'GBP', 'CAD'); -IMPORT FOREIGN SCHEMA public FROM SERVER postgresql_server LIMIT TO +IMPORT FOREIGN SCHEMA public LIMIT TO (index_desc, index_version, index_version_markit, index_maturity, index_quotes, markit_tranche_quotes, - risk_num_per_quote) INTO public; + risk_num_per_quote, + rates) FROM SERVER postgresql_server INTO public; CREATE FOREIGN TABLE model_versions( @@ -1660,3 +1661,14 @@ CREATE TABLE fcm_im( amount float NOT NULL, PRIMARY KEY(date, account, currency) ) + +CREATE TABLE strategy_im( + date date NOT NULL, + broker text NOT NULL, + strategy strategy NOT NULL, + amount float NOT NULL, + currency currency NOT NULL, + PRIMARY KEY (date, strategy, broker) +) + +CREATE TYPE cash_rate AS ENUM('FED_FUND', '1M_LIBOR', '3M_LIBOR'); diff --git a/sql/serenitasdb.sql b/sql/serenitasdb.sql index fa570fa7..efa6b1c0 100644 --- a/sql/serenitasdb.sql +++ b/sql/serenitasdb.sql @@ -1052,3 +1052,11 @@ CREATE TABLE defaulted( seniority sen,
PRIMARY KEY (id, seniority)
FOREIGN KEY (id, seniority) REFERENCES bbg_issuers)
+
+CREATE TYPE cash_rate AS ENUM('FED_FUND', '1M_LIBOR', '3M_LIBOR');
+
+CREATE TABLE rates(
+ date date NOT NULL,
+ name cash_rate NOT NULL,
+ rate float not NULL
+ PRIMARY KEY (date, name));
|
