aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/analytics/tranche_basket.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/python/analytics/tranche_basket.py b/python/analytics/tranche_basket.py
index 4397ce31..9b63ee97 100644
--- a/python/analytics/tranche_basket.py
+++ b/python/analytics/tranche_basket.py
@@ -54,10 +54,10 @@ class DualCorrTranche():
self._accrued = cds_accrued(value_date, tranche_running * 1e-4)
self._ignore_hash = set(['_Z', '_w', 'cs', '_cache', '_ignore_hash'])
- def _default_prob(self):
+ def _default_prob(self, epsilon=0.):
return 1 - self._index.survival_matrix(
self.cs.index.values.astype('M8[D]').
- view('int') + 134774)[0]
+ view('int') + 134774, epsilon)[0]
def __hash__(self):
def aux(v):
@@ -103,7 +103,7 @@ class DualCorrTranche():
self._accrued = cds_accrued(d, self.tranche_running * 1e-4)
@memoize(hasher=lambda args: (hash(args[0]._index), *args[1:]))
- def tranche_legs(self, K, rho):
+ def tranche_legs(self, K, rho, epsilon=0.):
if K == 0.:
return 0., 0.
elif K == 1.:
@@ -111,7 +111,7 @@ class DualCorrTranche():
elif np.isnan(rho):
raise ValueError("ρ needs to be a real number between 0. and 1.")
else:
- L, R = BCloss_recov_dist(self._default_prob(),
+ L, R = BCloss_recov_dist(self._default_prob(epsilon),
self._index.weights,
self._index.recovery_rates,
rho,
@@ -137,6 +137,9 @@ class DualCorrTranche():
@property
def pv(self):
+ return self._pv()
+
+ def _pv(self, epsilon=0.):
""" computes coupon leg, protection leg and bond price.
coupon leg is *dirty*.
@@ -146,7 +149,7 @@ class DualCorrTranche():
i = 0
for rho, k in zip(self.rho, self.K):
- cl[i], pl[i] = self.tranche_legs(k, rho)
+ cl[i], pl[i] = self.tranche_legs(k, rho, epsilon)
i += 1
dK = np.diff(self.K)
pl = np.diff(pl) / dK
@@ -256,14 +259,11 @@ class DualCorrTranche():
def _greek_calc(self):
eps = 1e-4
self._Ngrid = 301
- indexbp = [self._index.pv()[0]]
+ indexbp = [self._index.pv(self.maturity)]
bp = [self.pv]
- orig_curves = self._index.curves
for tweak in [eps, -eps, 2*eps]:
- self._index.tweak_portfolio(tweak, self.maturity, False)
- indexbp.append(self._index.pv()[0])
- bp.append(self.pv)
- self._index.curves = orig_curves
+ indexbp.append(self._index.pv(self.maturity, tweak))
+ bp.append(self._pv(tweak))
return {'indexbp': indexbp, 'bp': bp}
class TrancheBasket(BasketIndex):