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.py42
1 files changed, 27 insertions, 15 deletions
diff --git a/python/analytics/tranche_basket.py b/python/analytics/tranche_basket.py
index 8e484a32..65451e57 100644
--- a/python/analytics/tranche_basket.py
+++ b/python/analytics/tranche_basket.py
@@ -81,22 +81,25 @@ class DualCorrTranche():
@classmethod
def from_tradeid(cls, trade_id):
- r = dawn_engine.execute("SELECT * FROM cds LEFT JOIN index_desc "
- "ON security_id = redindexcode AND "
- "cds.maturity = index_desc.maturity "
- "WHERE id=%s", (trade_id,))
+ r = dawn_engine.execute(
+ "SELECT cds.*, index_desc.index, index_desc.series, "
+ "index_desc.tenor FROM cds "
+ "LEFT JOIN index_desc "
+ "ON security_id = redindexcode AND "
+ "cds.maturity = index_desc.maturity "
+ "WHERE id=%s", (trade_id,))
rec = r.fetchone()
- instance = cls(rec['index'], rec['series'], rec['tenor'],
- attach=rec['orig_attach'],
- detach=rec['orig_detach'],
- corr_attach=rec['corr_attach'],
- corr_detach=rec['corr_detach'],
- notional=rec['notional'],
- tranche_running=rec['fixed_rate']*100,
- value_date=rec['trade_date'])
- instance.direction = rec['protection']
- if rec['index_ref'] is not None:
- instance._index.tweak([rec['index_ref']])
+ instance = cls(rec.index, rec.series, rec.tenor,
+ attach=rec.orig_attach,
+ detach=rec.orig_detach,
+ corr_attach=rec.corr_attach,
+ corr_detach=rec.corr_detach,
+ notional=rec.notional,
+ tranche_running=rec.fixed_rate*100,
+ value_date=rec.trade_date)
+ instance.direction = rec.protection
+ if rec.index_ref is not None:
+ instance._index.tweak([rec.index_ref])
instance.reset_pv()
return instance
@@ -387,6 +390,15 @@ 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')
+
@property
def gamma(self):
calc = self._greek_calc()