Skip to content

Add DayCounts extension: discount/accumulation over Date intervals (v2.6.0) - #50

Open
alecloudenback wants to merge 2 commits into
mainfrom
feat/daycounts-extension
Open

alecloudenback wants to merge 2 commits into
mainfrom
feat/daycounts-extension

Conversation

@alecloudenback

@alecloudenback alecloudenback commented Jul 6, 2026 •

Copy link
Copy Markdown
Member

Rebuilt 2026-09-24: rebased onto current main (version 2.7.0) plus one commit: Accept only constant rates in the Date-interval methods. discount(rate, from::Date, to::Date, dc) discounts over the interval's length, which is right for a constant rate but not for a yield curve anchored at a valuation date (that needs D(to)/D(from), not D(to - from)). With an untyped first argument the extension accepted curves anyway: 2% then 4% zeros gave 0.9802 instead of 0.9418 over the second year. The first argument is now Union{Real, Rate} for discount and accumulation; curves get a MethodError.


Summary

Timepoint and Cashflow accept Dates.Date, but the rate math couldn't consume dates: discount(rate, Date(...), Date(...)) fails because the Day period can't multiply a rate, and the docstrings punted to "convert with DayCounts.jl yourself."

This PR adds a package extension, FinanceCoreDayCountsExt (loaded automatically when DayCounts.jl is present), providing:

discount(rate,     from::Date, to::Date, dc::DayCounts.DayCount)
accumulation(rate, from::Date, to::Date, dc::DayCounts.DayCount)

with the interval measured via DayCounts.yearfrac(from, to, dc). rate can be a Rate or a Real (assumed Periodic(rate, 1), same as the scalar-time methods).

Design choice: no default convention. discount(rate, from::Date, to::Date) without a day count still errors naturally — silently assuming Actual/365 (or anything else) would be a hidden pricing convention.

Changes

  • ext/FinanceCoreDayCountsExt.jl (new): the two methods, with docstrings and verified examples
  • Project.toml: DayCounts weakdep + extension + compat DayCounts = \"0.1\"; version 2.5.4 → 2.6.0 (adjust per merge order)
  • src/Rates.jl: discount/accumulation docstrings note the Date methods
  • test/daycounts.jl (new, wired into runtests): exact agreement with scalar-time methods across four conventions (Actual365Fixed, Actual360, Thirty360, ActualActualISDA) for Real/Periodic/Continuous rates, discount·accumulation inversion, degenerate and reversed intervals

DayCounts was already a test dependency (used by the xirr date tests), so no test-infrastructure changes were needed.

Possible follow-ups (out of scope)

  • present_value for Cashflow{A, Date} vectors given an as-of date + convention
  • the same extension pattern in FinanceModels for yield-curve discount(curve, from::Date, to::Date, dc)

Test plan

  • Full test suite passes locally (26 new tests; Aqua validates the extension wiring)

🤖 Generated with Claude Code

alecloudenback and others added 2 commits September 24, 2026 10:52
…2.6.0)

Timepoint and Cashflow accept Dates.Date, but discount(rate, from, to)
with Dates failed (Day periods can't enter the rate math), and the
docstrings punted to converting with DayCounts.jl manually.

A new package extension (loaded when DayCounts.jl is present) provides

    discount(rate, from::Date, to::Date, dc::DayCounts.DayCount)
    accumulation(rate, from::Date, to::Date, dc::DayCounts.DayCount)

measuring the interval via DayCounts.yearfrac. Without an explicit day
count convention, Date intervals still error naturally — no silent
convention is assumed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
discount(rate, from::Date, to::Date, dc) discounted over the interval's
length, which is right for a constant rate but not for a yield curve: a
curve anchored at its valuation date has D(to)/D(from), not D(to - from).
With an untyped first argument the extension accepted curves anyway
(2% then 4% zeros: 0.9802 instead of 0.9418 over the second year).
Type the rate as Union{Real, Rate} for discount and accumulation.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant