aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/analytics/tranche_functions.py11
-rw-r--r--python/tests/test_dates.py14
2 files changed, 17 insertions, 8 deletions
diff --git a/python/analytics/tranche_functions.py b/python/analytics/tranche_functions.py
index ab975a55..3355a887 100644
--- a/python/analytics/tranche_functions.py
+++ b/python/analytics/tranche_functions.py
@@ -30,9 +30,7 @@ def wrapped_ndpointer(*args, **kwargs):
return type(base.__name__, (base,), {"from_param": classmethod(from_param)})
-libloss = np.ctypeslib.load_library(
- "lossdistrib", Path(__file__).parent
-)
+libloss = np.ctypeslib.load_library("lossdistrib", Path(__file__).parent)
libloss.fitprob.restype = None
libloss.fitprob.argtypes = [
@@ -455,9 +453,9 @@ def credit_schedule(tradedate, coupon, yc, enddate=None, tenor=None, rule=CDS201
DC = Actual360()
start_date = tradedate + 1
sched = Schedule.from_rule(
- start_date, enddate, Period("3M"), cal, ModifiedFollowing, Unadjusted, rule
+ tradedate, enddate, Period("3M"), cal, ModifiedFollowing, Unadjusted, rule
)
- payment_dates = [pydate_from_qldate(cal.adjust(d)) for d in sched[1:]]
+ payment_dates = [pydate_from_qldate(cal.adjust(d)) for d in sched if d > start_date]
df = [yc.discount_factor(d) for d in payment_dates]
coupons = [
DC.year_fraction(d1, d2) * coupon for d1, d2 in zip(sched[:-2], sched[1:-1])
@@ -490,9 +488,8 @@ def credit_schedule_pyisda(
stub = "f/l"
else:
stub = "f/s"
- print(stub)
if rule is CDS2015:
- start_date = previous_twentieth(start_date)
+ start_date = previous_twentieth(pydate_from_qldate(tradedate))
fl = FeeLeg(start_date, pydate_from_qldate(enddate), True, 1.0, coupon, stub=stub)
df = pd.DataFrame({"coupons": [t[1] for t in fl.cashflows], **fl.inspect()})
df["df"] = [yc.discount_factor(d) for d in df.pay_dates]
diff --git a/python/tests/test_dates.py b/python/tests/test_dates.py
index 0a4078ba..054a0ee1 100644
--- a/python/tests/test_dates.py
+++ b/python/tests/test_dates.py
@@ -6,7 +6,7 @@ import sys
sys.path.append("..")
from analytics.utils import roll_date
-from analytics.tranche_functions import cds_accrued
+from analytics.tranche_functions import cds_accrued, credit_schedule
from pyisda.date import (
roll_date as roll_date_c,
cds_accrued as cds_accrued_c,
@@ -15,6 +15,7 @@ from pyisda.date import (
TDate_to_pydate,
)
from dates import days_accrued
+from yieldcurve import get_curve
class TestStartDate(unittest.TestCase):
@@ -173,5 +174,16 @@ class TestDaysAccrued(unittest.TestCase):
self.assertEqual(days_accrued(date), days)
+class TestCdsSchedule(unittest.TestCase):
+ def setUp(self):
+ self.trade_date = datetime.date(2020, 6, 19)
+ self.yc = get_curve(self.trade_date, "USD")
+
+ def test_credit_schedule(self):
+ """ tests when IMM date falls on a week-end"""
+ df = credit_schedule(self.trade_date, 1.0, self.yc, datetime.date(2022, 12, 20))
+ self.assertEqual(df.index[0], pd.Timestamp("2020-06-22"))
+
+
if __name__ == "__main__":
unittest.main()