aboutsummaryrefslogtreecommitdiffstats
path: root/python/analytics
diff options
context:
space:
mode:
Diffstat (limited to 'python/analytics')
-rw-r--r--python/analytics/index.py13
-rw-r--r--python/analytics/scenarios.py4
2 files changed, 14 insertions, 3 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):
diff --git a/python/analytics/scenarios.py b/python/analytics/scenarios.py
index 9564556b..fe921e4c 100644
--- a/python/analytics/scenarios.py
+++ b/python/analytics/scenarios.py
@@ -45,8 +45,6 @@ def run_index_scenarios(index, date_range, spread_shock):
index.trade_date = date.date()
for s in spread:
index.spread = s
- scen_pv = index.clean_pv +
- index.notional * (date.date()-starting_date).days /360 * index.fixed_rate * 1e-4 - starting_pv
- r.append([date, s, scen_pv])
+ r.append([date, s, index.pnl])
df = pd.DataFrame.from_records(r, columns=['date', 'spread', 'pnl'])
return df.set_index('date')