aboutsummaryrefslogtreecommitdiffstats
path: root/python/analytics
diff options
context:
space:
mode:
Diffstat (limited to 'python/analytics')
-rw-r--r--python/analytics/basket_index.py41
1 files changed, 23 insertions, 18 deletions
diff --git a/python/analytics/basket_index.py b/python/analytics/basket_index.py
index 138090a4..e6651f5c 100644
--- a/python/analytics/basket_index.py
+++ b/python/analytics/basket_index.py
@@ -4,12 +4,13 @@ from dateutil.relativedelta import relativedelta
from functools import partial
from pyisda.credit_index import CreditIndex
from typing import List
+from yieldcurve import get_curve
import numpy as np
import pandas as pd
from math import exp
import datetime
from scipy.optimize import brentq
-from pandas.tseries.offsets import BDay
+from pandas.tseries.offsets import Day, BDay
def make_index(t, d, args):
instance = t.__new__(t)
@@ -49,14 +50,13 @@ class BasketIndex(CreditIndex):
self.issue_date = self.index_desc.issue_date[0]
maturities = self.index_desc.maturity[tenors].sort_values().dt.to_pydatetime()
self.index_desc = self.index_desc.reset_index().set_index('maturity')
- curves, args = get_singlenames_curves(index_type, series, trade_date)
- _, jp_yc, _, step_in_date, value_date, _ = args
- self.yc = jp_yc
- self.step_in_date = step_in_date
- self.value_date = value_date
- self._trade_date = trade_date
+ curves = get_singlenames_curves(index_type, series, trade_date)
+ self.currency = "EUR" if index_type in ["XO", "EU"] else "USD"
+ self.yc = get_curve(trade_date, self.currency)
+ self.step_in_date = trade_date + Day()
+ self.value_date = trade_date + 3 * BDay()
self.tweaks = []
- super().__init__(self.issue_date, maturities, curves)
+ super().__init__(self.issue_date, maturities, curves, trade_date=trade_date)
def __reduce__(self):
_, args = CreditIndex.__reduce__(self)
@@ -94,24 +94,29 @@ class BasketIndex(CreditIndex):
def _get_quotes(self):
pass
- @property
- def trade_date(self):
- return self._trade_date
+ trade_date = property(CreditIndex.trade_date.__get__)
@trade_date.setter
def trade_date(self, d: pd.Timestamp):
- curves, args = get_singlenames_curves(self.index_type, self.series, d)
- _, jp_yc, _, step_in_date, value_date, _ = args
- self.yc = jp_yc
- self.step_in_date = step_in_date
- self.value_date = value_date
- self._trade_date = d
- self.curves = curves
+ self.curves = get_singlenames_curves(self.index_type, self.series, d)
+ self.yc = get_curve(d, self.currency)
+ self.step_in_date = d + Day()
+ self.value_date = d + 3 * BDay()
+ CreditIndex.trade_date.__set__(self, d)
def pv(self, maturity: pd.Timestamp, epsilon=0.):
return super().pv(self.step_in_date, self.value_date, maturity, self.yc,
self.recovery, self.coupon(maturity), epsilon)
+ def coupon_leg(self, maturity):
+ return self.coupon(maturity) * self.duration(maturity)
+
+ def protection_leg(self, maturity):
+ return self.pv(maturity) + self.coupon_leg(maturity)
+
+ def spread(self, maturity):
+ return (self.coupon(maturity) + self.pv(maturity) / self.duration(maturity)) * 1e4
+
def duration(self, maturity):
return super().duration(self.step_in_date, self.value_date, maturity, self.yc)