aboutsummaryrefslogtreecommitdiffstats
path: root/python/analytics
diff options
context:
space:
mode:
Diffstat (limited to 'python/analytics')
-rw-r--r--python/analytics/basket_index.py3
-rw-r--r--python/analytics/tranche_basket.py16
2 files changed, 12 insertions, 7 deletions
diff --git a/python/analytics/basket_index.py b/python/analytics/basket_index.py
index fd245a2a..7ea2c053 100644
--- a/python/analytics/basket_index.py
+++ b/python/analytics/basket_index.py
@@ -211,9 +211,6 @@ class BasketIndex(CreditIndex):
def coupon_leg(self, maturity=None):
return self.index_desc.coupon.values * self.duration()
- def protection_leg(self, maturity=None):
- return self.pv() + self.coupon_leg()
-
def spread(self, maturity=None):
return self.protection_leg(maturity) / self.duration(maturity) * 1e4
diff --git a/python/analytics/tranche_basket.py b/python/analytics/tranche_basket.py
index 7742b5d5..c0145ecc 100644
--- a/python/analytics/tranche_basket.py
+++ b/python/analytics/tranche_basket.py
@@ -833,7 +833,7 @@ class TrancheBasket(BasketIndex):
)
return pd.DataFrame(1 - sm, index=tickers, columns=self.cs.index)
- def tranche_legs(self, K, rho, complement=False, shortened=0):
+ def tranche_legs(self, K, rho, complement=False, shortened=0, zero_recovery=False):
if (K == 0.0 and not complement) or (K == 1.0 and complement):
return 0.0, 0.0
elif (K == 1.0 and not complement) or (K == 0.0 and complement):
@@ -847,10 +847,14 @@ class TrancheBasket(BasketIndex):
else:
default_prob = self.default_prob.values
cs = self.cs
+ if zero_recovery:
+ recovery_rates = np.zeros(self.weights.size)
+ else:
+ recovery_rates = self.recovery_rates
L, R = BCloss_recov_dist(
default_prob,
self.weights,
- self.recovery_rates,
+ recovery_rates,
rho,
self._Z,
self._w,
@@ -895,7 +899,9 @@ class TrancheBasket(BasketIndex):
r = r - orig_upfs
return pd.DataFrame(r, index=tickers, columns=self._row_names)
- def tranche_pvs(self, protection=False, complement=False, shortened=0):
+ def tranche_pvs(
+ self, protection=False, complement=False, shortened=0, zero_recovery=False
+ ):
""" computes coupon leg, protection leg and bond price.
coupon leg is *dirty*.
@@ -904,7 +910,9 @@ class TrancheBasket(BasketIndex):
pl = np.zeros(self.rho.size)
i = 0
for rho, k in zip(self.rho, self.K):
- cl[i], pl[i] = self.tranche_legs(k, rho, complement, shortened)
+ cl[i], pl[i] = self.tranche_legs(
+ k, rho, complement, shortened, zero_recovery
+ )
i += 1
dK = np.diff(self.K)
pl = np.diff(pl) / dK