Skip to content
Open
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
6 changes: 3 additions & 3 deletions financepy/utils/day_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ def year_frac(
frequency = annual_frequency(freq_type)

if dt3 is None:
y3 = y2
else:
y3 = dt3.y
dt3 = dt2

y3 = dt3.y

num = dt2 - dt1
den = 365
Expand Down
46 changes: 46 additions & 0 deletions unit_tests/test_FinDayCount.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,52 @@ def test_year_frace_act_365_l():
########################################################################################


def test_act_365_l_without_reference_end_date():

day_count = DayCount(DayCountTypes.ACT_365L)
period_start = Date(1, 12, 2023)
period_end = Date(1, 3, 2024)

implicit_period_end = day_count.year_frac(
period_start,
period_end,
freq_type=FrequencyTypes.ANNUAL,
)
explicit_period_end = day_count.year_frac(
period_start,
period_end,
period_end,
FrequencyTypes.ANNUAL,
)

assert implicit_period_end == explicit_period_end
assert implicit_period_end == (91.0 / 366.0, 91.0, 366)

# A separately supplied coupon-period end must still control the
# denominator for an accrued fraction.
accrued_start = Date(1, 3, 2023)
accrued_end = Date(1, 12, 2023)
next_coupon = Date(1, 3, 2024)

full_period_mode = day_count.year_frac(
accrued_start,
accrued_end,
freq_type=FrequencyTypes.ANNUAL,
)
accrued_mode = day_count.year_frac(
accrued_start,
accrued_end,
next_coupon,
FrequencyTypes.ANNUAL,
)

assert full_period_mode == (275.0 / 365.0, 275.0, 365)
assert accrued_mode == (275.0 / 366.0, 275.0, 366)


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


def test_year_frace_simple():

dc_type = DayCountTypes.JULIAN
Expand Down
Loading