aboutsummaryrefslogtreecommitdiffstats
path: root/python/analytics/portfolio.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/analytics/portfolio.py')
-rw-r--r--python/analytics/portfolio.py21
1 files changed, 12 insertions, 9 deletions
diff --git a/python/analytics/portfolio.py b/python/analytics/portfolio.py
index b13d8dda..2f98053f 100644
--- a/python/analytics/portfolio.py
+++ b/python/analytics/portfolio.py
@@ -39,13 +39,7 @@ class Portfolio:
def __init__(self, trades, trade_ids=None):
self.trades = trades
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:
- self._keys.add((swaption.index.index_type, swaption.index.series, swaption.index.tenor))
self._value_date = value_dates.pop()
if len(value_dates) >= 1:
warn(f"not all instruments have the same trade date, picking {self._value_date}")
@@ -53,14 +47,23 @@ class Portfolio:
def add_trade(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
+ @property
+ def indices(self):
+ return [t for t in self.trades if isinstance(t, CreditIndex)]
+
+ @property
+ def swaptions(self):
+ return [t for t in self.trades if isinstance(t, BlackSwaption)]
+
+ @property
+ def tranches(self):
+ return [t for t in self.trades if isinstance(t, DualCorrTranche)]
+
def items(self):
for trade_id, trade in zip(self.trade_ids, self.trades):
yield (trade_id, trade)