diff options
| -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 | ||||
| -rw-r--r-- | sql/dawn.sql | 31 |
4 files changed, 35 insertions, 25 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, diff --git a/sql/dawn.sql b/sql/dawn.sql index f60c8ed9..6482803b 100644 --- a/sql/dawn.sql +++ b/sql/dawn.sql @@ -943,7 +943,7 @@ WITH temp AS (SELECT a.*, c.index, c.series, c.version, c.basketid, d.tenor, LEFT JOIN index_version c ON a.security_id=c.redindexcode LEFT JOIN index_maturity d USING (index, series, maturity)), risk_num AS (SELECT DISTINCT ON (index, series, a.attach, a.detach, tenor) * from risk_num_per_quote a - WHERE quotedate BETWEEN p_date - interval '1 week' AND p_date + WHERE quotedate BETWEEN p_date - interval '1 week' AND p_date + interval '1 day' ORDER by index, series, a.attach, a.detach, tenor, quotedate desc) SELECT temp.security_id, temp.security_desc, temp.index, temp.series, temp.version, temp.tenor, temp.maturity, temp.notional, temp.fact, @@ -1636,20 +1636,21 @@ for t in (df.itertuples(index=False)): $$ LANGUAGE plpythonu; -CREATE TABLE tranche_marks( - date date NOT NULL, - id integer NOT NULL REFERENCES cds, - clean_nav float, - accrued float, - tranche_duration float, - spread float, - delta float, - gamma float, - theta float, - corr_attach float, - corr_detach float, - index_duration float, - PRIMARY KEY(date, id)) +CREATE OR REPLACE VIEW globeop_tranche_risk AS +SELECT date, security_desc, index, series, maturity, orig_attach, + orig_detach, CASE protection WHEN 'Buyer' THEN notional ELSE -notional END AS notional, + endqty as globeop_notional, + clean_nav as serenitas_clean_nav, + endbooknav-endbookunrealincome as globeop_clean_nav, + accrued as serenitas_accrued, endbookunrealincome, + duration, delta, gamma, theta, tranche_risk.corr_attach, tranche_risk.corr_detach, + tranche_risk.upfront, tranche_risk.running, + index_refprice, index_refspread, index_duration +FROM tranche_risk +LEFT JOIN cds ON (tranche_id=id) +LEFT JOIN valuation_reports ON (invid=globeop_id AND periodenddate=date) +LEFT JOIN index_version ON (security_id=redindexcode) +ORDER BY index, series, orig_attach; CREATE TABLE fcm_im( |
