aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/analytics/tranche_basket.py3
-rw-r--r--python/risk/tranches.py44
2 files changed, 23 insertions, 24 deletions
diff --git a/python/analytics/tranche_basket.py b/python/analytics/tranche_basket.py
index 0e431173..53303cc6 100644
--- a/python/analytics/tranche_basket.py
+++ b/python/analytics/tranche_basket.py
@@ -178,7 +178,8 @@ class DualCorrTranche:
"WHERE redindexcode=%s AND maturity = %s",
(redcode, maturity),
)
- index_type, series, tenor = c.fetchone()
+ index_type, series, tenor = c.fetchone()
+ serenitas_pool.putconn(conn)
self._index = BasketIndex(index_type, series, [tenor], value_date=value_date)
self.index_type = index_type
diff --git a/python/risk/tranches.py b/python/risk/tranches.py
index 93c433f4..ecd4672a 100644
--- a/python/risk/tranches.py
+++ b/python/risk/tranches.py
@@ -9,38 +9,34 @@ def get_tranche_portfolio(date, conn, by_strat=False, fund="SERCGMAST", **kwargs
sql_string = "SELECT * from list_tranche_positions_by_strat(%s, %s)"
params = (date, fund)
else:
- sql_string = (
- "SELECT folder, id from list_cds(%s, %s) "
- "WHERE orig_attach IS NOT NULL ORDER BY trade_date"
- )
+ sql_string = "SELECT * FROM list_cds(%s, %s) WHERE orig_attach IS NOT NULL "
params = (date, fund)
with conn.cursor() as c:
c.execute(sql_string, params)
- trade_ids = [tuple(e) for e in c]
+ trade_ids = list(c)
+
+ portf = Portfolio(
+ [
+ DualCorrTranche(
+ redcode=t.security_id,
+ maturity=t.maturity,
+ notional=t.notional,
+ tranche_running=t.fixed_rate * 100,
+ attach=t.orig_attach,
+ detach=t.orig_detach,
+ corr_attach=None,
+ corr_detach=None,
+ )
+ for t in trade_ids
+ ]
+ )
if by_strat:
- portf = Portfolio(
- [
- DualCorrTranche(
- redcode=t.security_id,
- maturity=t.maturity,
- notional=t.notional,
- tranche_running=t.fixed_rate * 100,
- attach=t.orig_attach,
- detach=t.orig_detach,
- corr_attach=None,
- corr_detach=None,
- )
- for t in trade_ids
- ]
- )
portf.trade_ids = [
(tid.folder, f"{t.index_type} {t.series} {t.tenor} {t.attach}-{t.detach}")
for tid, t in zip(trade_ids, portf.trades)
]
else:
- portf = Portfolio(
- [DualCorrTranche.from_tradeid(dealid) for _, dealid in trade_ids], trade_ids
- )
+ portf.trade_ids = [(t.folder, t.id) for t in trade_ids]
portf.value_date = date
portf.mark(**kwargs)
return portf
@@ -50,6 +46,7 @@ def insert_tranche_portfolio(portf, conn):
cols = [
"date",
"tranche_id",
+ "notional",
"clean_nav",
"accrued",
"duration",
@@ -90,6 +87,7 @@ def insert_tranche_portfolio(portf, conn):
(
trade.value_date,
trade_id,
+ trade.notional,
trade.clean_pv,
trade.accrued,
trade.duration,