aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/analytics/__init__.py3
-rw-r--r--python/analytics/tranche_basket.py23
-rw-r--r--python/risk/__main__.py4
-rw-r--r--python/risk/tranches.py1
4 files changed, 17 insertions, 14 deletions
diff --git a/python/analytics/__init__.py b/python/analytics/__init__.py
index 62cd168c..d32c88ec 100644
--- a/python/analytics/__init__.py
+++ b/python/analytics/__init__.py
@@ -3,6 +3,7 @@ import sys
sys.path.append("..")
# indicates whether we use local pricing
_local = True
+_include_todays_cashflow = False
from utils.db import serenitas_engine, dawn_engine, dbconn, DataError, serenitas_pool
from functools import lru_cache
from .index import CreditIndex, ForwardIndex
@@ -35,7 +36,7 @@ def on_the_run(index: str, value_date: datetime.date = datetime.date.today()) ->
f"AND issue_date {interval}<= %s",
(index, value_date),
)
- series, = r.fetchone()
+ (series,) = r.fetchone()
return series
diff --git a/python/analytics/tranche_basket.py b/python/analytics/tranche_basket.py
index 9f3cc4fc..07af20a1 100644
--- a/python/analytics/tranche_basket.py
+++ b/python/analytics/tranche_basket.py
@@ -215,10 +215,10 @@ class DualCorrTranche:
@maturity.setter
def maturity(self, m):
+ # TODO: fix case of bespokes
self._index.maturities = [m]
- start_date = pd.Timestamp(self.value_date) + Day()
self.cs = credit_schedule(
- start_date,
+ self.value_date,
1.0,
self._index.yc,
m,
@@ -289,13 +289,11 @@ class DualCorrTranche:
def value_date(self, d: pd.Timestamp):
self._index.value_date = d
start_date = pd.Timestamp(d) + Day()
- self.cs = credit_schedule(
- start_date,
- 1.0,
- self._index.yc,
- self.maturity,
- rule=OldCDS if self.index_type == "BS" else CDS2015,
- )
+ if analytics._include_todays_cashflows:
+ self.cs = self.cs[self.cs.index >= start_date]
+ else:
+ self.cs = self.cs[self.cs.index > start_date]
+ self.cs.df = self.cs.payment_dates.apply(self._index.yc.discount_factor)
self._accrued = (
(start_date - self.cs.start_dates[0]).days
/ 360
@@ -770,10 +768,13 @@ class DualCorrTranche:
kbound = find_upper_bound(k, 4)
moneyness_eq.append(brentq(aux, 0.0, kbound, (k, 4)) / el)
self.rho = skew(moneyness_eq)
- self.maturity += relativedelta(years=-1)
+ self._index.maturities = [self.maturity - relativedelta(years=1)]
+ cs = self.cs
+ self.cs = self.cs[:-4]
r = self.pv - pv_orig
self.rho = rho_orig
- self.maturity += relativedelta(years=1)
+ self._index.maturities = [self.maturity + relativedelta(years=1)]
+ self.cs = cs
return -r / self.notional + self.tranche_running * 1e-4
def expected_loss(self, discounted=True, shortened=0):
diff --git a/python/risk/__main__.py b/python/risk/__main__.py
index e609221d..dfd61eb7 100644
--- a/python/risk/__main__.py
+++ b/python/risk/__main__.py
@@ -19,13 +19,13 @@ else:
init_ontr(workdate)
-# analytics._local = False
+analytics._include_todays_cashflows = True
mysql_engine = dbengine("rmbs_model")
mysqlcrt_engine = dbengine("crt")
with dbconn("dawndb") as conn:
- portf = get_swaption_portfolio(workdate, conn, source_list=["GS"])
+ portf = get_swaption_portfolio(workdate, conn, source_list=["MS"])
insert_swaption_portfolio(portf, conn)
for fund in ("SERCGMAST", "BOWDST"):
portf = get_tranche_portfolio(workdate, conn, fund=fund)
diff --git a/python/risk/tranches.py b/python/risk/tranches.py
index 0f4292c4..6c7ea1e4 100644
--- a/python/risk/tranches.py
+++ b/python/risk/tranches.py
@@ -25,6 +25,7 @@ def get_tranche_portfolio(date, conn, by_strat=False, fund="SERCGMAST", **kwargs
detach=t.orig_detach,
corr_attach=None,
corr_detach=None,
+ value_date=t.trade_date,
)
for t in trade_ids
]