aboutsummaryrefslogtreecommitdiffstats
path: root/python/risk
diff options
context:
space:
mode:
Diffstat (limited to 'python/risk')
-rw-r--r--python/risk/tranches.py44
1 files changed, 21 insertions, 23 deletions
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,