aboutsummaryrefslogtreecommitdiffstats
path: root/python/risk
diff options
context:
space:
mode:
Diffstat (limited to 'python/risk')
-rw-r--r--python/risk/bonds.py18
1 files changed, 8 insertions, 10 deletions
diff --git a/python/risk/bonds.py b/python/risk/bonds.py
index c671ed8b..2a8b28c5 100644
--- a/python/risk/bonds.py
+++ b/python/risk/bonds.py
@@ -244,20 +244,18 @@ def crt_risk(date, dawn_conn, crt_engine, fund="SERCGMAST"):
if scen_type is None and date < d:
scen_type = s
sql_string = (
- "SELECT distinct timestamp FROM priced_at_market "
- "where model_des = %s "
- "AND timestamp BETWEEN %s AND date_add(%s, INTERVAL 1 DAY) order by timestamp desc"
+ "SELECT a.* FROM crt.priced_at_market a "
+ "JOIN (SELECT cusip, MAX(timestamp) timestamp "
+ "FROM crt.priced_at_market where timestamp between %s "
+ "AND date_add(%s, INTERVAL 1 DAY) "
+ "and model_des = %s GROUP BY cusip) b "
+ "ON a.cusip= b.cusip AND a.timestamp = b.timestamp;"
)
- with crt_engine.connect() as c:
- r = c.execute(sql_string, (scen_type, date - datetime.timedelta(days=15), date))
- model_date = r.fetchone()
- if model_date:
- model_date = model_date[0]
df_model = pd.read_sql_query(
- "SELECT * from priced_at_market WHERE timestamp = %s",
+ sql_string,
crt_engine,
"cusip",
- params=(model_date,),
+ params=(date - datetime.timedelta(days=15), date, scen_type),
)
if any(~df_model["delta.ir"].isna()):
df_model = df_model[~df_model["delta.ir"].isna()]