Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion financepy/products/rates/swap_fixed_leg.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,13 @@ def generate_payments(self):

self.payment_dts.append(payment_dt)

year_frac, num, _ = day_counter.year_frac(prev_dt, next_dt)
# The final period ends on the termination date, which 30E/360
# ISDA does not move to the 30th when it is the end of February
is_termination_dt = next_dt == schedule_dts[-1]

year_frac, num, _ = day_counter.year_frac(
prev_dt, next_dt, is_termination_date=is_termination_dt
)

self.rates.append(self.cpn)

Expand Down
74 changes: 74 additions & 0 deletions tests/unit/test_swap_fixed_leg_thirty_e_360_isda.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""30E/360 (ISDA), ISDA 2006 Definitions section 4.16(h): D2 is changed to 30
when it is the last day of February, unless it is the Termination Date."""

import pytest

from financepy.products.rates.swap_fixed_leg import SwapFixedLeg
from financepy.utils.calendar import BusDayAdjustTypes, CalendarTypes
from financepy.utils.date import Date
from financepy.utils.day_count import DayCountTypes
from financepy.utils.frequency import FrequencyTypes
from financepy.utils.global_types import SwapTypes

NOTIONAL = 10_000_000
COUPON = 0.04

########################################################################################


def _fixed_leg(effective_dt, termination_dt, freq_type, end_of_month=False):
return SwapFixedLeg(
effective_dt,
termination_dt,
SwapTypes.RECEIVE,
COUPON,
freq_type,
DayCountTypes.THIRTY_E_360_ISDA,
notional=NOTIONAL,
cal_type=CalendarTypes.WEEKEND,
bd_type=BusDayAdjustTypes.MODIFIED_FOLLOWING,
end_of_month=end_of_month,
)


########################################################################################


def test_final_period_ending_28_february_is_not_rolled_to_30():

leg = _fixed_leg(Date(28, 2, 2025), Date(28, 2, 2030), FrequencyTypes.ANNUAL)

# 28 Feb 2028 to 28 Feb 2029 ends on the last day of February but not on
# the termination date, so D2 becomes 30: 360 + 30 - 28 = 362 days
assert leg.end_accrued_dts[3] == Date(28, 2, 2029)
assert leg.year_fracs[3] == pytest.approx(362 / 360, abs=1e-12)

# 28 Feb 2029 to 28 Feb 2030 ends on the termination date, so D1 becomes
# 30 but D2 stays 28: 360 + 28 - 30 = 358 days
assert leg.end_accrued_dts[-1] == Date(28, 2, 2030)
assert leg.accrued_days[-1] == 358
assert leg.year_fracs[-1] == pytest.approx(358 / 360, abs=1e-12)
assert leg.payments[-1] == pytest.approx(NOTIONAL * COUPON * 358 / 360, abs=1e-6)


########################################################################################


def test_final_period_ending_29_february_is_not_rolled_to_30():

leg = _fixed_leg(
Date(29, 2, 2024),
Date(29, 2, 2028),
FrequencyTypes.SEMI_ANNUAL,
end_of_month=True,
)

# 31 Aug 2027 to the termination date 29 Feb 2028: D1 = 30 and D2 = 29,
# so 30 * (2 - 8) + 360 + 29 - 30 = 179 days
assert leg.start_accrued_dts[-1] == Date(31, 8, 2027)
assert leg.end_accrued_dts[-1] == Date(29, 2, 2028)
assert leg.accrued_days[-1] == 179
assert leg.year_fracs[-1] == pytest.approx(179 / 360, abs=1e-12)


########################################################################################
Loading