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.py34
1 files changed, 24 insertions, 10 deletions
diff --git a/python/analytics/tranche_basket.py b/python/analytics/tranche_basket.py
index 65451e57..73e222a6 100644
--- a/python/analytics/tranche_basket.py
+++ b/python/analytics/tranche_basket.py
@@ -44,7 +44,6 @@ class DualCorrTranche():
self._index = BasketIndex(index_type, series, [tenor],
value_date=value_date)
- self.maturity = self._index.maturities[0]
self.index_type = index_type
self.series = series
self.tenor = tenor
@@ -64,6 +63,16 @@ class DualCorrTranche():
self._tranche_id = None
self._ignore_hash = set(['_Z', '_w', 'cs', '_cache', '_Legs', '_ignore_hash'])
+ @property
+ def maturity(self):
+ return self._index.maturities[0]
+
+ @maturity.setter
+ def maturity(self, m):
+ self._index.maturities = [m]
+ self.cs = credit_schedule(self.value_date, None,
+ 1., self._index.yc, m)
+
def _default_prob(self, epsilon=0.):
return 1 - self._index.survival_matrix(
self.cs.index.to_numpy("M8[D]").view("int") + 134774, epsilon)[0]
@@ -304,7 +313,10 @@ class DualCorrTranche():
self.tenor, args.get("source", "MKIT")))
params = (self.value_date, self.index_type, self.series,
self.tenor, args.get("source", "MKIT"))
- spread, = c.fetchone()
+ try:
+ spread, = c.fetchone()
+ except TypeError:
+ raise ValueError("No quote for that date")
self._index.tweak([spread])
if 'skew' in args:
@@ -390,14 +402,16 @@ class DualCorrTranche():
return (calc['bp'][1] - calc['bp'][2]) / \
(calc['indexbp'][1] - calc['indexbp'][2]) * factor
- def tranche_thetas(self, complement=False, shortened=4, method='ATM'):
- 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).bond_price
- self.rho = rho_saved
- thetas = bpshort - bp + self.tranche_running
- return pd.Series(thetas, index=self._row_names, name='theta')
+ def theta(self, skew, method='ATM'):
+ pv_orig = self.pv
+ rho_orig = self.rho
+ y, m, d = self.maturity.year, self.maturity.month, self.maturity.day
+ self.maturity = datetime.date(y - 1, m, d)
+ self.mark(skew=skew)
+ r = self.pv - pv_orig
+ self.rho = rho_orig
+ self.maturity = datetime.date(y, m, d)
+ return r/abs(self.notional)
@property
def gamma(self):