aboutsummaryrefslogtreecommitdiffstats
path: root/python/analytics
diff options
context:
space:
mode:
Diffstat (limited to 'python/analytics')
-rw-r--r--python/analytics/tranche_basket.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/python/analytics/tranche_basket.py b/python/analytics/tranche_basket.py
index da1b85d8..9049505e 100644
--- a/python/analytics/tranche_basket.py
+++ b/python/analytics/tranche_basket.py
@@ -129,7 +129,8 @@ class TrancheBasket(BasketIndex):
bp = -pl -cl
else:
bp = 1 + pl + cl
- return cl, pl, bp
+ Pvs = namedtuple('TranchePvs', 'coupon_leg, protection_leg, bond_price')
+ return Pvs(cl, pl, bp)
def index_pv(self, discounted=True, shortened=0):
if shortened > 0:
@@ -150,7 +151,8 @@ class TrancheBasket(BasketIndex):
pl = - np.diff(np.hstack((0., ELvec))) @ df
cl = coupons @ (sizeadj * df)
bp = 1 + cl * self.coupon(self.maturity) + pl
- return cl, pl, bp
+ Pvs = namedtuple('IndexPvs', 'coupon_leg, protection_leg, bond_price')
+ return Pvs(cl, pl, bp)
def expected_loss(self, discounted=True, shortened=0):
if shortened > 0:
@@ -201,7 +203,7 @@ class TrancheBasket(BasketIndex):
return np.array([c.recovery_rates[0] for c in self.curves])
def tranche_durations(self, complement=False):
- cl, _, _ = self.tranche_pvs(complement=complement)
+ cl = self.tranche_pvs(complement=complement).coupon_leg
durations = (cl - cds_accrued(self.trade_date, self.tranche_quotes.running)) / \
self.tranche_quotes.running
durations.index = self._row_names
@@ -215,10 +217,10 @@ class TrancheBasket(BasketIndex):
return [f"{a}-{d}" for a, d in zip(ad, ad[1:])]
def tranche_thetas(self, complement=False, shortened=4, method='ATM'):
- _, _, bp = self.tranche_pvs(complement=complement)
+ bp = self.tranche_pvs(complement=complement).bond_price
rho_saved = self.rho
self.rho = self.map_skew(self, method, shortened)
- _, _, bpshort = self.tranche_pvs(complement=complement, shortened=shortened)
+ bpshort = self.tranche_pvs(complement=complement, shortened=shortened).bond_price
self.rho = rho_saved
thetas = bpshort - bp + self.tranche_quotes.running.values
return pd.Series(thetas, index=self._row_names, name='theta')
@@ -246,8 +248,8 @@ class TrancheBasket(BasketIndex):
indexbp = np.empty(len(index_list))
for i, index in enumerate(index_list):
- indexbp[i] = index.index_pv()[2]
- bp[i] = index.tranche_pvs()[2]
+ indexbp[i] = index.index_pv().bond_price
+ bp[i] = index.tranche_pvs().bond_price
factor = self.tranche_factors() / self.factor
deltas = (bp[1] - bp[2]) / (indexbp[1] - indexbp[2]) * factor