diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/analytics/basket_index.py | 11 | ||||
| -rw-r--r-- | python/risk/tranches.py | 17 |
2 files changed, 19 insertions, 9 deletions
diff --git a/python/analytics/basket_index.py b/python/analytics/basket_index.py index 8a2a7766..ef3df15d 100644 --- a/python/analytics/basket_index.py +++ b/python/analytics/basket_index.py @@ -2,6 +2,7 @@ from .index_data import get_index_quotes, get_singlenames_curves from .db import serenitas_engine from .utils import tenor_t from functools import partial +from pyisda.cdsone import upfront_charge, spread_from_upfront from pyisda.credit_index import CreditIndex from pyisda.date import previous_twentieth from typing import List @@ -12,7 +13,7 @@ import pandas as pd from math import exp from scipy.optimize import brentq from pandas.tseries.offsets import Day, BDay -from pyisda.cdsone import upfront_charge + def make_index(t, d, args): @@ -272,6 +273,14 @@ class BasketIndex(CreditIndex): self.step_in_date, self.start_date, maturity, coupon, self.yc, spread, recov) + def _snacspread(self, coupon, recov, maturity): + return spread_from_upfront(self.value_date, self.cash_settle_date, + self.start_date, self.step_in_date, + self.start_date, maturity, + coupon, self.yc, + self.pv(maturity), recov) + + class MarkitBasketIndex(BasketIndex): def __init__(self, index_type: str, series: int, tenors: List[str], *, diff --git a/python/risk/tranches.py b/python/risk/tranches.py index 76284a36..125dc72b 100644 --- a/python/risk/tranches.py +++ b/python/risk/tranches.py @@ -43,23 +43,24 @@ def insert_tranche_marks(portf, conn): "upfront", "running", "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({['%s'] * 12}) " + sql_str = (f"INSERT INTO tranche_risk VALUES({','.join(['%s'] * 12)}) " " ON CONFLICT (date, tranche_id) DO UPDATE " f"SET {update_str}") - print(sql_str) with conn.cursor() as c: for trade_id, trade in portf.items(): - c.execute(sql_str, (d, + c.execute(sql_str, (trade.value_date, trade_id, trade.clean_pv, - trace._accrued, + -trade._accrued * trade.notional, None, trade.duration, + trade.delta, trade.upfront, - trade.tranche_upfront, trade.tranche_running, - trade._indexpv().bond_price * 100, - trade._index.spread(), - trade._index.duration()) + 100 - float(trade._index.pv()) * 100, + trade._index._snacspread(trade._index.coupon(), + trade._index.recovery, + trade._index.maturities[0]) * 10000, + float(trade._index.duration())) ) conn.commit() |
