aboutsummaryrefslogtreecommitdiffstats
path: root/python/analytics/tranche_basket.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/analytics/tranche_basket.py')
-rw-r--r--python/analytics/tranche_basket.py24
1 files changed, 20 insertions, 4 deletions
diff --git a/python/analytics/tranche_basket.py b/python/analytics/tranche_basket.py
index dab528c6..1af4d4eb 100644
--- a/python/analytics/tranche_basket.py
+++ b/python/analytics/tranche_basket.py
@@ -13,9 +13,11 @@ from pyisda.date import cds_accrued
from scipy.optimize import brentq
from scipy.interpolate import CubicSpline, PchipInterpolator
from scipy.special import logit, expit
+
import datetime
import pandas as pd
import numpy as np
+import analytics
class DualCorrTranche():
@@ -175,7 +177,8 @@ class DualCorrTranche():
@property
def pv(self):
- return self._pv()
+ pl, cl = self._pv()
+ return float(-pl - cl + self._accrued)
def _pv(self, epsilon=0.):
""" computes coupon leg, protection leg and bond price.
@@ -192,7 +195,7 @@ class DualCorrTranche():
dK = np.diff(self.K)
pl = np.diff(pl) / dK
cl = np.diff(cl) / dK * self.tranche_running * 1e-4
- return float(-pl - cl + self._accrued)
+ return pl, cl
@property
def upfront(self):
@@ -246,7 +249,7 @@ class DualCorrTranche():
self._index.tweak_portfolio(ss, self.maturity, False)
for corrs in corr_shock:
#also need to map skew
- self.rho = np.fmin(1, orig_rho * (1 + corrs))
+ self.rho = orig_rho * (1 + corrs)
r.append([getattr(self, p) for p in actual_params])
self._index.curves = orig_curves
self.rho = orig_rho
@@ -283,6 +286,18 @@ class DualCorrTranche():
self._index.factor
@property
+ def duration(self):
+ return self._pv()[1] - self._accrued
+
+ @property
+ def hy_equiv(self):
+ risk = self.notional * self.delta * float(self._index.duration()) / \
+ analytics._ontr.risky_annuity
+ if self.index_type != 'HY':
+ risk *= analytics._beta[self.index_type]
+ return risk
+
+ @property
def delta(self):
calc = self._greek_calc()
factor = self.tranche_factor / self._index.factor
@@ -306,7 +321,8 @@ class DualCorrTranche():
bp = [self.pv]
for tweak in [eps, -eps, 2*eps]:
indexbp.append(self.tranche_legs(1., None, tweak).bond_price)
- bp.append(self._pv(tweak))
+ pl, cl = self._pv(tweak)
+ bp.append(float(-pl - cl + self._accrued))
return {'indexbp': indexbp, 'bp': bp}
class TrancheBasket(BasketIndex):