aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/analytics/basket_index.py9
-rw-r--r--python/analytics/utils.py7
-rw-r--r--python/tests/test_tranche_basket.py9
3 files changed, 23 insertions, 2 deletions
diff --git a/python/analytics/basket_index.py b/python/analytics/basket_index.py
index a7d70d60..3b2122c5 100644
--- a/python/analytics/basket_index.py
+++ b/python/analytics/basket_index.py
@@ -1,6 +1,6 @@
from .index_data import get_index_quotes, get_singlenames_curves_prebuilt
from . import serenitas_pool
-from .utils import get_fx
+from .utils import get_fx, adjust_next_business_day
from functools import partial
from pyisda.cdsone import upfront_charge, spread_from_upfront
from pyisda.credit_index import CreditIndex
@@ -122,7 +122,12 @@ class BasketIndex(CreditIndex):
"_ignore_hash",
]
)
- super().__init__(self.issue_date, maturities, curves, value_date=value_date)
+ super().__init__(
+ adjust_next_business_day(self.issue_date),
+ maturities,
+ curves,
+ value_date=value_date,
+ )
self._cache[k] = self
def __reduce__(self):
diff --git a/python/analytics/utils.py b/python/analytics/utils.py
index 0e014cff..c8e5901b 100644
--- a/python/analytics/utils.py
+++ b/python/analytics/utils.py
@@ -89,6 +89,13 @@ def adjust_prev_business_day(d: datetime.date):
return d
+def adjust_next_business_day(d: datetime.date):
+ if (offset := 7 - d.weekday()) >= 3:
+ return d
+ else:
+ return d + datetime.timedelta(days=offset)
+
+
def next_business_day(d: datetime.date):
if (offset := 7 - d.weekday()) > 3:
return d + datetime.timedelta(days=1)
diff --git a/python/tests/test_tranche_basket.py b/python/tests/test_tranche_basket.py
index a7506955..34be0af2 100644
--- a/python/tests/test_tranche_basket.py
+++ b/python/tests/test_tranche_basket.py
@@ -20,6 +20,15 @@ class TestTopDown(unittest.TestCase):
eu30 = TrancheBasket("EU", 30, "5yr", value_date=datetime.date(2019, 8, 15))
market_quotes = eu30._accrued + eu30.tranche_quotes.quotes
+ def test_invariant(self):
+ hy35 = TrancheBasket("HY", 35, "5yr", value_date=datetime.date(2020, 10, 5))
+ hy35.tweak()
+ hy35.build_skew()
+ self.assertAlmostEqual(
+ hy35.index_pv(clean=True).bond_price,
+ (hy35.tranche_pvs().bond_price * np.diff(hy35.K)).sum(),
+ )
+
def test_bottomup(self):
self.eu30.build_skew()
upfronts = 1 - self.eu30.tranche_pvs().bond_price