aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/analytics/index.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/python/analytics/index.py b/python/analytics/index.py
index 794b29b1..bc4f9299 100644
--- a/python/analytics/index.py
+++ b/python/analytics/index.py
@@ -1,4 +1,5 @@
from __future__ import division
+import array
import datetime
import math
import numpy as np
@@ -18,19 +19,23 @@ from yieldcurve import YC, ql_to_jp, roll_yc, rate_helpers
engine = dbengine('serenitasdb')
-def g(index, spread, exercise_date, forward_yc = None):
- """computes the strike clean price using the expected forward yield curve """
+def g(index, spread, exercise_date, forward_yc=None, pv=0.):
+ """computes the strike clean price using the expected forward yield curve. """
if forward_yc is None:
forward_yc = index._yc
step_in_date = exercise_date + datetime.timedelta(days=1)
exercise_date_settle = (pd.Timestamp(exercise_date) + 3* BDay()).date()
+ rates = array.array('d', [spread * 1e-4])
sc = SpreadCurve(exercise_date, forward_yc, index.start_date,
step_in_date, exercise_date_settle,
- [index.end_date], np.array([spread * 1e-4]),
- np.zeros(1), np.array([index.recovery]))
+ [index.end_date], rates, array.array('d',[pv]),
+ array.array('d', [index.recovery]))
a = index._fee_leg.pv(exercise_date, step_in_date, exercise_date_settle,
- forward_yc, sc, True)
- return (spread - index.fixed_rate) * a *1e-4
+ forward_yc, sc, True)
+ if pv != 0.:
+ return 1e4 * pv / a + spread
+ else:
+ return (spread - index.fixed_rate) * a *1e-4
class Index(object):
""" minimal class to represent a credit index """