aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/analytics/tranche_basket.py15
-rw-r--r--python/calibrate_tranches_BC.py2
2 files changed, 12 insertions, 5 deletions
diff --git a/python/analytics/tranche_basket.py b/python/analytics/tranche_basket.py
index 0bdf9354..8b9d6e5f 100644
--- a/python/analytics/tranche_basket.py
+++ b/python/analytics/tranche_basket.py
@@ -353,7 +353,7 @@ class DualCorrTranche:
bp = 1 + cl * self.tranche_running * 1e-4 + pl
return self._Legs(cl, pl, bp)
- def index_pv(self, epsilon=0.0, discounted=True):
+ def index_pv(self, epsilon=0.0, discounted=True, clean=False):
DP = self._default_prob(epsilon)
df = self.cs.df.values
coupons = self.cs.coupons
@@ -367,6 +367,10 @@ class DualCorrTranche:
pl = -np.diff(np.hstack((0.0, ELvec))) @ df
cl = coupons @ (sizeadj * df)
bp = 1 + cl * self._index.coupon(self.maturity) + pl
+ if clean:
+ accrued = self._index.accrued(self.maturity)
+ bp -= accrued
+ cl -= accrued / self._index.coupon(self.maturity)
return self._Legs(cl, pl, bp)
@property
@@ -864,8 +868,7 @@ class TrancheBasket(BasketIndex):
):
super().__init__(index_type, series, [tenor], value_date=value_date)
self.tenor = tenor
- index_desc = self.index_desc.reset_index("maturity").set_index("tenor")
- self.maturity = index_desc.loc[tenor, "maturity"].date()
+ self.maturity = self.index_desc[0].maturity
try:
self._set_tranche_quotes(value_date)
except ValueError as e:
@@ -1095,7 +1098,7 @@ class TrancheBasket(BasketIndex):
bp = 1 + pl + cl - self._accrued
return self._Legs(cl, pl, bp)
- def index_pv(self, discounted=True, shortened=0, zero_recovery=False):
+ def index_pv(self, discounted=True, shortened=0, zero_recovery=False, clean=False):
cs, DP = self._default_prob(shortened)
df = cs.df.values
coupons = cs.coupons.values
@@ -1112,6 +1115,10 @@ class TrancheBasket(BasketIndex):
pl = -np.diff(np.hstack((0.0, ELvec))) @ df
cl = coupons @ (sizeadj * df)
bp = 1 + cl * self.coupon(self.maturity) + pl
+ if clean:
+ accrued = self.accrued()
+ cl -= accrued / self.coupon(self.maturity)
+ bp -= self.accrued(self.maturity)
return self._Legs(cl, pl, bp)
def expected_loss(self, discounted=True, shortened=0):
diff --git a/python/calibrate_tranches_BC.py b/python/calibrate_tranches_BC.py
index 47b08e49..6e405e9d 100644
--- a/python/calibrate_tranches_BC.py
+++ b/python/calibrate_tranches_BC.py
@@ -199,7 +199,7 @@ if __name__ == "__main__":
df["index_duration"],
df["index_expected_loss"],
df["index_price"],
- ) = tranche_index.index_pv()
+ ) = tranche_index.index_pv(clean=True)
df["index_expected_loss"] *= -1
df["index_duration"] -= tranche_index.accrued()
df["index_basis"] = tranche_index.tweaks[0]