Repository navigation
Add DayCounts extension: discount/accumulation over Date intervals (v2.6.0) - #50
Open
alecloudenback wants to merge 2 commits into
Open
alecloudenback wants to merge 2 commits into
alecloudenback wants to merge 2 commits into
Conversation
…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>
alecloudenback
force-pushed
the
feat/daycounts-extension
branch
from
September 24, 2026 22:51
f3f4de1 to
b46edce
Compare
14 tasks
This branch has not been deployed
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.
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 needsD(to)/D(from), notD(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 nowUnion{Real, Rate}fordiscountandaccumulation; curves get aMethodError.Summary
TimepointandCashflowacceptDates.Date, but the rate math couldn't consume dates:discount(rate, Date(...), Date(...))fails because theDayperiod 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:
with the interval measured via
DayCounts.yearfrac(from, to, dc).ratecan be aRateor aReal(assumedPeriodic(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 examplesProject.toml: DayCounts weakdep + extension +compat DayCounts = \"0.1\"; version 2.5.4 → 2.6.0 (adjust per merge order)src/Rates.jl:discount/accumulationdocstrings note the Date methodstest/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 intervalsDayCounts 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_valueforCashflow{A, Date}vectors given an as-of date + conventiondiscount(curve, from::Date, to::Date, dc)Test plan
🤖 Generated with Claude Code