aboutsummaryrefslogtreecommitdiffstats
path: root/python/analytics
diff options
context:
space:
mode:
Diffstat (limited to 'python/analytics')
-rw-r--r--python/analytics/tranche_basket.py28
1 files changed, 20 insertions, 8 deletions
diff --git a/python/analytics/tranche_basket.py b/python/analytics/tranche_basket.py
index 9b63ee97..e28a356c 100644
--- a/python/analytics/tranche_basket.py
+++ b/python/analytics/tranche_basket.py
@@ -1,7 +1,7 @@
from .basket_index import BasketIndex
from .tranche_functions import (
credit_schedule, adjust_attachments, GHquad, BCloss_recov_dist,
- BCloss_recov_trunc, tranche_cl, tranche_pl)
+ BCloss_recov_trunc, tranche_cl, tranche_pl, tranche_pl_trunc, tranche_cl_trunc)
from .index_data import get_tranche_quotes
from .utils import memoize, build_table
from collections import namedtuple
@@ -24,7 +24,8 @@ class DualCorrTranche():
attach: float, detach: float, corr_attach: float,
corr_detach: float, tranche_running: float,
notional: float=10_000_000,
- value_date: pd.Timestamp=pd.Timestamp.today().normalize()):
+ value_date: pd.Timestamp=pd.Timestamp.today().normalize(),
+ use_trunc=False):
self._index = BasketIndex(index_type, series, [tenor], value_date=value_date)
def get_quotes(self, spread):
@@ -52,6 +53,7 @@ class DualCorrTranche():
self.cs = credit_schedule(value_date, None,
1., self._index.yc, self._index.maturities[0])
self._accrued = cds_accrued(value_date, tranche_running * 1e-4)
+ self.use_trunc = use_trunc
self._ignore_hash = set(['_Z', '_w', 'cs', '_cache', '_ignore_hash'])
def _default_prob(self, epsilon=0.):
@@ -111,13 +113,23 @@ 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(epsilon),
- self._index.weights,
- self._index.recovery_rates,
- rho,
- self._Z, self._w, self._Ngrid)
Legs = namedtuple('TrancheLegs', 'coupon_leg, protection_leg')
- return Legs(tranche_cl(L, R, self.cs, 0., K), tranche_pl(L, self.cs, 0., K))
+ if self.use_trunc:
+ EL, ER = BCloss_recov_trunc(self._default_prob(epsilon),
+ self._index.weights,
+ self._index.recovery_rates,
+ rho, K,
+ self._Z, self._w, self._Ngrid)
+ return Legs(tranche_cl_trunc(EL, ER, self.cs, 0., K),
+ tranche_pl_trunc(EL, self.cs, 0., K))
+ else:
+ L, R = BCloss_recov_dist(self._default_prob(epsilon),
+ self._index.weights,
+ self._index.recovery_rates,
+ rho,
+ self._Z, self._w, self._Ngrid)
+ return Legs(tranche_cl(L, R, self.cs, 0., K),
+ tranche_pl(L, self.cs, 0., K))
@property
def direction(self):