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.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/python/analytics/index.py b/python/analytics/index.py
index e7472a84..efda3cb6 100644
--- a/python/analytics/index.py
+++ b/python/analytics/index.py
@@ -1,6 +1,7 @@
-import array
+from __future__ import division
import datetime
import math
+import numpy as np
import pandas as pd
from pyisda.legs import ContingentLeg, FeeLeg
@@ -18,7 +19,7 @@ from yieldcurve import YC, ql_to_jp, roll_yc, rate_helpers
serenitasdb = dbconn('serenitasdb')
-def g(index, spread : float, exercise_date : datetime.date, forward_yc = None):
+def g(index, spread, exercise_date, forward_yc = None):
"""computes the strike clean price using the expected forward yield curve """
if forward_yc is None:
forward_yc = index._yc
@@ -26,13 +27,13 @@ def g(index, spread : float, exercise_date : datetime.date, forward_yc = None):
exercise_date_settle = (pd.Timestamp(exercise_date) + 3* BDay()).date()
sc = SpreadCurve(exercise_date, forward_yc, index.start_date,
step_in_date, exercise_date_settle,
- [index.end_date], array.array('d', [spread * 1e-4]),
+ [index.end_date], np.array([spread * 1e-4]),
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
-class Index():
+class Index(object):
""" minimal class to represent a credit index """
def __init__(self, start_date, end_date, recovery, fixed_rate,
notional = 10e6):
@@ -122,7 +123,7 @@ class Index():
def _update(self):
self._sc = SpreadCurve(self.trade_date, self._yc, self.start_date,
self._step_in_date, self._value_date,
- [self.end_date], array.array('d', [self._spread]),
+ [self.end_date], np.array([self._spread]),
self.recovery)
self._risky_annuity = self._fee_leg.pv(self.trade_date, self._step_in_date,
self._value_date, self._yc,
@@ -135,7 +136,7 @@ class Index():
self._price = 100 * (1 - self._clean_pv)
@spread.setter
- def spread(self, s: float):
+ def spread(self, s):
""" s: spread in bps """
if self.spread is None or s != self.spread:
self._spread = s * 1e-4
@@ -337,7 +338,7 @@ class Index():
return "\n".join(s)
-class ForwardIndex():
+class ForwardIndex(object):
def __init__(self, index, forward_date, ref_is_price = False):
self.index = index
self.forward_date = forward_date
@@ -366,7 +367,7 @@ class ForwardIndex():
return self.index.spread
@ref.setter
- def ref(self, val : float):
+ def ref(self, val):
if self._ref_is_price:
if self.index.price is None or \
math.fabs(self.index.price - val) > 1e-6: