Skip to content

Commit

Permalink
add to CDS
Browse files Browse the repository at this point in the history
  • Loading branch information
attack68 committed Oct 15, 2024
1 parent b573930 commit 78fb7e8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
20 changes: 20 additions & 0 deletions python/rateslib/instruments/rates_derivatives.py
Original file line number Diff line number Diff line change
Expand Up @@ -2585,3 +2585,23 @@ def cashflows(
# Licence: Creative Commons - Attribution-NonCommercial-NoDerivatives 4.0 International
# Commercial use of this code, and/or copying and redistribution is prohibited.
# Contact rateslib at gmail.com if this code is observed outside its intended sphere.

def accrued(self, settlement: datetime):
"""
Calculate the amount of premium accrued until a specific date within the relevant *Period*.
Parameters
----------
settlement: datetime
The date against which accrued is measured.
Returns
-------
float or None
Notes
------
If the *CDS* is unpriced, i.e. there is no specified ``fixed_rate`` then None will be
returned.
"""
return self.leg1.accrued(settlement)
13 changes: 13 additions & 0 deletions python/tests/test_instruments.py
Original file line number Diff line number Diff line change
Expand Up @@ -2535,6 +2535,19 @@ def test_okane_paper(self):
npv = cds.npv(solver=solver)
assert abs(npv + 223516) < 670

def test_accrued(self):
cds = CDS(
dt(2022, 1, 1),
"6M",
"Q",
payment_lag=0,
currency="eur",
notional=1e9,
fixed_rate=2.0
)
result = cds.accrued(dt(2022, 2, 1))
assert abs(result + 0.25 * 1e9 * 0.02 * 31 / 90) < 1e-6


class TestXCS:
def test_mtmxcs_npv(self, curve, curve2) -> None:
Expand Down

0 comments on commit 78fb7e8

Please sign in to comment.