diff options
Diffstat (limited to 'python/analytics/portfolio.py')
| -rw-r--r-- | python/analytics/portfolio.py | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/python/analytics/portfolio.py b/python/analytics/portfolio.py index 3b9e1a9a..eb932034 100644 --- a/python/analytics/portfolio.py +++ b/python/analytics/portfolio.py @@ -1,5 +1,6 @@ from .index import CreditIndex from .option import BlackSwaption +from .tranche_basket import DualCorrTranche from warnings import warn import pandas as pd import numpy as np @@ -23,7 +24,9 @@ def portf_repr(method): 'Theta': thousands, 'Vega': thousands, 'Vol': percent, - 'Ref': thousands}, + 'Ref': thousands, + 'Attach Rho': percent, + 'Detach Rho': percent}, 'index': False} if method == 'string': kwargs['line_width'] = 100 @@ -38,6 +41,7 @@ class Portfolio: self.trade_ids = trade_ids self.indices = [t for t in trades if isinstance(t, CreditIndex)] self.swaptions = [t for t in trades if isinstance(t, BlackSwaption)] + self.tranches = [t for t in trades if isinstance(t, DualCorrTranche)] value_dates = set(t.value_date for t in self.trades) self._keys = set([(index.index_type, index.series, index.tenor) for index in self.indices]) for swaption in self.swaptions: @@ -46,6 +50,13 @@ class Portfolio: if len(value_dates) >= 1: warn(f"not all instruments have the same trade date, picking {self._value_date}") + def add_trades(self, trades, trade_ids): + self.trades.append(trades) + self.trade_ids.append(trade_ids) + self.indices = [t for t in self.trades if isinstance(t, CreditIndex)] + self.swaptions = [t for t in self.trades if isinstance(t, BlackSwaption)] + self.tranches = [t for t in self.trades if isinstance(t, DualCorrTranche)] + def __iter__(self): for t in self.trades: yield t @@ -155,18 +166,27 @@ class Portfolio: def _todf(self): headers = ["Product", "Index", "Notional", "Ref", "Strike", "Direction", "Type", "Expiry", "Vol", "PV", "Delta", "Gamma", "Theta", - "Vega"] + "Vega", "attach", "detach", "Attach Rho", "Detach Rho"] rec = [] for t in self.trades: if isinstance(t, CreditIndex): name = f"{t.index_type}{t.series} {t.tenor}" - r = ("Index", name, - t.notional, t.ref, "N/A", t.direction, "N/A", "N/A", None, t.pv, 1., 0., t.theta, 0.) + r = ("Index", name, t.notional, t.ref, "N/A", + t.direction, "N/A", "N/A", None, t.pv, + 1., 0., t.theta, 0., + None, None, None, None) elif isinstance(t, BlackSwaption): name = f"{t.index.index_type}{t.index.series} {t.index.tenor}" - r = ("Swaption", name, - t.notional, t.ref, t.strike, t.direction, t.option_type, t.forward_date, t.sigma, t.pv, - t.delta, t.gamma, t.theta, t.vega) + r = ("Swaption", name, t.notional, t.ref, t.strike, + t.direction, t.option_type, t.forward_date, t.sigma, t.pv, + t.delta, t.gamma, t.theta, t.vega, + None, None, None, None) + elif isinstance(t, DualCorrTranche): + name = f"{t.index_type}{t.series} {t.tenor}" + r = ("Tranche", name, t.notional, None, None, + t.direction, None, None, None, t.upfront, + None, None, None, None, + t.attach, t.detach, t.rho[0], t.rho[1]) else: raise TypeError rec.append(r) |
