aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--python/analytics/index.py29
1 files changed, 16 insertions, 13 deletions
diff --git a/python/analytics/index.py b/python/analytics/index.py
index 262e41bd..d5f9e835 100644
--- a/python/analytics/index.py
+++ b/python/analytics/index.py
@@ -39,7 +39,7 @@ def g(index, spread, exercise_date, forward_yc=None, pv=0.):
class Index(object):
""" minimal class to represent a credit index """
def __init__(self, start_date, end_date, recovery, fixed_rate,
- notional = 10e6, quote_is_price=False):
+ notional = 10e6, quote_is_price=False, issue_date=None):
"""
start_date : :class:`datetime.date`
index start_date (Could be issue date, or last imm date)
@@ -66,6 +66,7 @@ class Index(object):
self._spread = None
self._price = None
self.name = None
+ self.issue_date = issue_date
self._quote_is_price = quote_is_price
@property
@@ -147,7 +148,7 @@ class Index(object):
def pv(self, val):
self._pv = val / (self.notional * self.factor)
self._clean_pv = self._pv + self._accrued * self.fixed_rate * 1e-4
- self.price = 100 * (1- self._clean_pv)
+ self.price = 100 * (1 - self._clean_pv)
@property
def accrued(self):
@@ -294,19 +295,20 @@ class Index(object):
def from_name(cls, index=None, series=None, tenor=None, trade_date=datetime.date.today(),
notional=10_000_000, redcode=None, maturity=None):
if all([index, series, tenor]):
- sql_str = "SELECT indexfactor, lastdate, maturity, coupon " \
+ sql_str = "SELECT indexfactor, lastdate, maturity, coupon, issue_date " \
"FROM index_desc WHERE index=%s AND series=%s AND tenor = %s " \
"ORDER BY lastdate ASC"
params = (index.upper(), series, tenor)
elif all([redcode, maturity]):
- sql_str = "SELECT index, series, indexfactor, lastdate, maturity, coupon " \
+ sql_str = "SELECT index, series, indexfactor, lastdate, maturity, " \
+ "coupon, issue_date " \
"FROM index_desc WHERE redindexcode=%s AND maturity=%s"
params = (redcode, maturity)
else:
raise ValueError("Not enough information to load the index.")
try:
df = pd.read_sql_query(sql_str,
- engine, parse_dates=['lastdate'],
+ engine, parse_dates=['lastdate', 'issue_date'],
params=params)
maturity = df.maturity[0]
coupon = df.coupon[0]
@@ -321,7 +323,7 @@ class Index(object):
else:
recovery = 0.4 if index_type == "IG" else 0.3
instance = cls(trade_date, maturity, recovery, coupon, notional,
- index_type=="HY")
+ index_type=="HY", df.issue_date[0])
instance.factor = factor
instance.direction = "Buyer"
instance.name = "MARKIT CDX.NA.{}.{} {:%m/%y} ".format(
@@ -364,13 +366,14 @@ class Index(object):
"{:<20}\t{:>15}".format("Trade Date", ('{:%m/%d/%y}'.
format(self.trade_date))),
"{:<20}\t{:>15.2f}\t\t{:<20}\t{:>10,.2f}".format("Trd Sprd (bp)",
- self.spread,
- "Coupon (bp)",
- self.fixed_rate),
- "{:<20}\t{:>15.2f}\t\t{:<20}\t{:>10}".format("1st Accr Start",
- self.spread,
- "Payment Freq",
- "Quarterly"),
+ self.spread,
+ "Coupon (bp)",
+ self.fixed_rate),
+ "{:<20}\t{:>15}\t\t{:<20}\t{:>10}".format("1st Accr Start",
+ '{:%m/%d/%y}'.
+ format(self.issue_date),
+ "Payment Freq",
+ "Quarterly"),
"{:<20}\t{:>15}\t\t{:<20}\t{:>10.2f}".format("Maturity Date",
('{:%m/%d/%y}'.
format(self.end_date)),