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.py35
1 files changed, 30 insertions, 5 deletions
diff --git a/python/analytics/portfolio.py b/python/analytics/portfolio.py
index f918c4c5..5fd81ae8 100644
--- a/python/analytics/portfolio.py
+++ b/python/analytics/portfolio.py
@@ -4,7 +4,7 @@ from .option import BlackSwaption
class Portfolio:
def __init__(self, trades):
self.trades = trades
- self.index = next(t for t in trades if isinstance(t, Index))
+ self.indices = [t for t in trades if isinstance(t, Index)]
self.swaptions = [t for t in trades if isinstance(t, BlackSwaption)]
@property
@@ -12,9 +12,17 @@ class Portfolio:
return sum(t.pnl for t in self.trades)
@property
+ def pnl_list(self):
+ return [t.pnl for t in self.trades]
+
+ @property
def pv(self):
return sum(t.pv for t in self.trades)
+ @property
+ def pv_list(self):
+ return [t.pv for t in self.trades]
+
def set_original_pv(self):
for t in self.trades:
t.set_original_pv()
@@ -25,19 +33,36 @@ class Portfolio:
@trade_date.setter
def trade_date(self, d):
- self.index.trade_date = d
+ for index in self.indices:
+ index.trade_date = d
@property
def ref(self):
- return self.index.ref
+ if len(self.indices) == 1:
+ return self.indices[0].ref
+ else:
+ return [index.ref for for index in self.indices]
@ref.setter
def ref(self, val):
- self.index.ref = val
+ if hasattr(self, 'index'):
+ self.index.ref = val
+ else:
+ if len(self.indices) == 0:
+ ##no index, so set the individual refs
+ for t in trades:
+ t.index.ref = val
+ else:
+ if len(val) != len(self.indices):
+ raise ValueError("The number of refs doesn't match the number of indices")
+ for index, val in zip(self.indices, val):
+ index.ref = val
@property
def delta(self):
- """returns the equivalent protection notional"""
+ """returns the equivalent protection notional
+
+ makes sense only where there is a single index."""
return sum([getattr(t, 'delta', -t._direction) * t.notional for t in self.trades])
@property