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.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/python/analytics/index.py b/python/analytics/index.py
index 88c06485..58cada76 100644
--- a/python/analytics/index.py
+++ b/python/analytics/index.py
@@ -27,14 +27,27 @@ def g(index, spread, exercise_date, forward_yc=None, pv=None):
forward_yc = index._yc
step_in_date = exercise_date + datetime.timedelta(days=1)
exercise_date_settle = pd.Timestamp(exercise_date) + 3 * BDay()
+ if spread is None and index._sc is not None:
+ sc = index._sc
+ prot = index._default_leg.pv(exercise_date, step_in_date, exercise_date_settle, forward_yc,
+ index._sc, index.recovery)
+ else:
+ rates = array.array('d', [spread * 1e-4])
+ upfront = 0. if pv is None else pv
+ sc = SpreadCurve(exercise_date, forward_yc, index.start_date,
+ step_in_date, exercise_date_settle,
+ [index.end_date], rates, array.array('d', [upfront]),
+ array.array('d', [index.recovery]))
a = index._fee_leg.pv(exercise_date, step_in_date, exercise_date_settle,
- forward_yc, index._sc, True)
- prot = index._default_leg.pv(exercise_date, step_in_date, exercise_date_settle, forward_yc,
- index._sc, index.recovery)
+ forward_yc, sc, True)
+
if pv is not None:
return 1e4 * pv / a + spread
else:
- return prot - a * index.fixed_rate*1e-4
+ if spread is None:
+ return prot - a * index.fixed_rate*1e-4
+ else:
+ return (spread - index.fixed_rate) * a * 1e-4
class Index(object):
""" minimal class to represent a credit index """