aboutsummaryrefslogtreecommitdiffstats
path: root/python/analytics/index.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/analytics/index.py')
-rw-r--r--python/analytics/index.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/python/analytics/index.py b/python/analytics/index.py
index 1aa2ccc8..400c381f 100644
--- a/python/analytics/index.py
+++ b/python/analytics/index.py
@@ -279,6 +279,17 @@ class Index(object):
if self._spread is not None:
self._update()
+ @property
+ def pnl(self):
+ if self._original_clean_pv is None:
+ raise ValueError("original pv not set")
+ else:
+ ## TODO: handle factor change
+ days_accrued = (self.trade_date - self._original_trade_date).days / 360
+ return - self._direction * self.notional * self.factor * \
+ (self._clean_pv - self._original_clean_pv -
+ days_accrued * self.fixed_rate * 1e-4)
+
@classmethod
def from_name(cls, index, series, tenor, trade_date=datetime.date.today(),
notional=10_000_000):
@@ -327,6 +338,8 @@ class Index(object):
instance.direction = rec.protection
instance.trade_date = rec.trade_date
instance.pv = rec.upfront
+ instance._original_clean_pv = instance._clean_pv
+ instance._original_trade_date = rec.trade_date
return instance
def __repr__(self):