diff options
Diffstat (limited to 'python/risk/tranches.py')
| -rw-r--r-- | python/risk/tranches.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/python/risk/tranches.py b/python/risk/tranches.py new file mode 100644 index 00000000..2c13daf7 --- /dev/null +++ b/python/risk/tranches.py @@ -0,0 +1,16 @@ +from db import dbconn, dbengine +from analytics import Portfolio, DualCorrTranche +import datetime +import pandas as pd + +sql_string = ("SELECT id, sum(notional * case when protection='Buyer' then -1 else 1 end) " + "OVER (partition by security_id, attach) AS ntl_agg " + "FROM cds WHERE swap_type='CD_INDEX_TRANCHE' AND termination_cp IS NULL") +conn = dbconn('dawndb') +with conn.cursor() as c: + c.execute(sql_string) + trade_ids = [dealid for dealid, ntl in c if ntl != 0] +portf = Portfolio([DualCorrTranche.from_tradeid(dealid) for dealid in trade_ids], + trade_ids) +portf.value_date = datetime.date(2018, 10, 10) +portf.mark() |
