diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/analytics/basket_index.py | 7 | ||||
| -rw-r--r-- | python/analytics/tranche_basket.py | 12 | ||||
| -rw-r--r-- | python/risk/tranches.py | 10 |
3 files changed, 19 insertions, 10 deletions
diff --git a/python/analytics/basket_index.py b/python/analytics/basket_index.py index 4c08c157..612fb733 100644 --- a/python/analytics/basket_index.py +++ b/python/analytics/basket_index.py @@ -121,8 +121,11 @@ class BasketIndex(CreditIndex): def _get_quotes(self, *args): """ allow to tweak based on manually inputed quotes""" - return {m: self._snacpv(s*1e-4, self.coupon(m), self.recovery, m) - for m, s in zip(self.maturities, args[0])} + if self.index_type == "HY": + return {m: (100-p)/100 for m, p in zip(self.maturities, args[0])} + else: + return {m: self._snacpv(s*1e-4, self.coupon(m), self.recovery, m) + for m, s in zip(self.maturities, args[0])} value_date = property(CreditIndex.value_date.__get__) diff --git a/python/analytics/tranche_basket.py b/python/analytics/tranche_basket.py index 8297f83d..930a5a2a 100644 --- a/python/analytics/tranche_basket.py +++ b/python/analytics/tranche_basket.py @@ -167,7 +167,10 @@ class DualCorrTranche(): instance.direction = rec.protection if rec.index_ref is not None: instance._index.tweak([rec.index_ref]) - instance.reset_pv() + try: + instance.reset_pv() + except ValueError: + pass return instance @property @@ -365,7 +368,8 @@ class DualCorrTranche(): spread = args['spread'] else: if not self.index_type == "BS": - sql_query = ("SELECT close_spread from index_quotes_pre " + col_ref = "close_price" if self.index_type == "HY" else "close_spread" + sql_query = (f"SELECT {col_ref} from index_quotes_pre " "WHERE date=%s and index=%s and series=%s and " "tenor=%s and source=%s") conn = serenitas_engine.raw_connection() @@ -373,11 +377,11 @@ class DualCorrTranche(): c.execute(sql_query, (self.value_date, self.index_type, self.series, self.tenor, args.get("source", "MKIT"))) try: - spread, = c.fetchone() + ref, = c.fetchone() except TypeError: raise ValueError("No quote for that date") try: - self._index.tweak([spread]) + self._index.tweak([ref]) except NameError: pass diff --git a/python/risk/tranches.py b/python/risk/tranches.py index f4391f99..98d31357 100644 --- a/python/risk/tranches.py +++ b/python/risk/tranches.py @@ -37,15 +37,17 @@ def get_tranche_portfolio(date, conn, by_strat=False, fund="SERCGMAST"): return portf def insert_tranche_portfolio(portf, conn): - cols = ["clean_nav", "accrued", "theta", "duration", "delta", - "upfront", "running", "index_refprice", "index_refspread", + cols = ["clean_nav", "accrued", "duration", "delta", "gamma", + "theta", "upfront", "running", "corr_attach", "corr_detach", + "index_refprice", "index_refspread", "index_duration"] update_str = ",".join(f"{c} = EXCLUDED.{c}" for c in cols) - sql_str = (f"INSERT INTO tranche_risk VALUES({','.join(['%s'] * 12)}) " + sql_str = (f"INSERT INTO tranche_risk VALUES({','.join(['%s'] * 15)}) " " ON CONFLICT (date, tranche_id) DO UPDATE " f"SET {update_str}") with conn.cursor() as c: for (strat, trade_id), trade in portf.items(): + print(strat, trade_id) c.execute(sql_str, (trade.value_date, trade_id, trade.clean_pv, @@ -55,9 +57,9 @@ def insert_tranche_portfolio(portf, conn): trade.gamma, trade.theta(method="TLP"), trade.upfront, + trade.tranche_running, trade.rho[0], trade.rho[1], - trade.tranche_running, 100 - float(trade._index.pv()) * 100, trade._index._snacspread(trade._index.coupon(), trade._index.recovery, |
