Repository navigation
fix(curves): align CDSCurve df and survival_prob vectorization and day count (#191) - #408
Merged
domokane merged 1 commit intoOct 19, 2026
Conversation
…y count (domokane#191) - Delegate CDSCurve.df directly to libor_curve.df (or df_t for float/array) to respect libor_curve.curve_dc_type and fix vectorization when passing a list of Dates. - Update survival_prob to convert Date or list[Date] using times_from_dates with self.dc_type, preventing crashes on list of Dates. - Update build_curve to use times_from_dates with self.dc_type for maturity date conversion. - Re-enable test_fin_cds_curve in tests/unit/test_FinCDSCurve.py with updated API and add tests verifying scalar and vectorized df and survival_prob evaluations across different day-count conventions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary & Context
Fixes #191
In issue #191, an inconsistency was identified regarding how day count conventions are handled when computing discount factors from curves. While the core
DiscountCurve.df(self, dt)was refactored in commit310bab06to consistently useself.curve_dc_type,CDSCurveinfinancepy/market/curves/cds_curve.pyretained several day-count inconsistencies and broken vectorization:CDSCurve.df(self, dt):When passed a
Date,CDSCurve.dfmanually calculatedt = (dt - self.anchor_dt) / G_DAYS_IN_YEAR(hardcoded ACT/365), completely bypassingself.libor_curve.curve_dc_type.Both
CDSCurve.df(self, dt)andCDSCurve.survival_prob(self, dt)advertise vectorization support in their docstrings. However, when passed alist[Date]:CDSCurve.dfrant = np.array(dt), creating an object array ofDateinstances and passing it tolibor_curve.df_t(t), which crashed withTypeError: float() argument must be a string or a real number, not 'Date'.CDSCurve.survival_probsimilarly passed an object array ofDateinstances to_uinterpolate, causing anAttributeError/TypeError.Changes
CDSCurve.df(self, dt):self.libor_curve.df(dt)whendtis aDateorlist[Date]. This ensures the underlying discount curve'scurve_dc_typeis respected and returns vectorized results (np.ndarray) seamlessly.self.libor_curve.df_twhendtis numeric (float,int, or numericnp.ndarray).CDSCurve.survival_prob(self, dt):Dateorlist[Date]viatimes_from_dates(self.anchor_dt, dt, self.dc_type)into year fractions before calling_uinterpolate.CDSCurve.build_curve:times_from_dates(self.anchor_dt, maturity_dt, self.dc_type)for maturity conversion, ensuring consistency withsurvival_prob.tests/unit/test_FinCDSCurve.py:test_fin_cds_curve()updated for the modern API (removed deprecateduse_cache, updatedcds.valuereturn tuple).Dateevaluations fordfandsurvival_prob.list[Date]evaluations matching scalar calls.ACT_360).Validation
pytest tests/unit/test_FinCDSCurve.py(passed).pytest tests/unit/): 1366 passed, 0 failures, 0 errors.