Repository navigation
Anchored schedule boundaries with an end-of-month rule - #45
Merged
Merged
Conversation
This was referenced Oct 8, 2026
…date while respecting month-end logic
The fractional-tail tests for CashFlowStream.from_recurring and GenerationStream.from_capacity sized the tail with add_period, which steps from the previous boundary and so reproduces the month-end drift that anchored boundaries remove. A Jan 30 monthly start with 1.5 periods expected 14 tail days (Feb 28 to Mar 28) instead of 15 (Feb 28 to Mar 30). tail_days now takes the next boundary explicitly, the tests compute it with anchored_boundary, and add_period is removed. Both tests gain the Jan 30 case as an explicit example. Co-Authored-By: Claude <noreply@anthropic.com>
dylanjm
approved these changes
Oct 13, 2026
dylanjm
left a comment
Collaborator
There was a problem hiding this comment.
Changes are good, tests implemented recreating date logic directly.
j-bryan
force-pushed
the
anchored-boundaries
branch
from
October 13, 2026 21:34
947245b to
770843a
Compare
…an oracle The anchoring tests no longer reimplement add_periods or elapsed_periods. Boundary dates are checked by the month they land in and the day they keep, partial periods by their bounds and monotonicity, and exact values are worked out by hand. Co-Authored-By: Claude <noreply@anthropic.com>
j-bryan
force-pushed
the
anchored-boundaries
branch
from
October 13, 2026 22:04
ea543c9 to
45de20c
Compare
This was referenced Oct 13, 2026
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.
Related to #38 (does not close it). First PR in stack #51: #45 ← #46 ← #49 ← #52 ← #53.
Schedule boundaries are now counted from the schedule start instead of from the previous boundary, so a schedule starting late in a month no longer drifts to an earlier day.
add_periods(start, count, frequency, *, end_of_month=True)(new, exported fromdcaf.shared): boundary k of a schedule anchored atstart. Keeps the start's day of the month, clamped in shorter months. Withend_of_month=Trueand a month-end start, every month, quarter, or year boundary is the last day of its month. Daily schedules ignore the flag. Negative counts step backward under the same rule.elapsed_periods(..., *, end_of_month=True): months and quarters are measured against those boundaries, i.e. whole scheduled periods plus the elapsed share of the days in the period containing the end date, so every full scheduled period measures exactly 1.0. Years still use the day-count convention; days are unchanged. Replaces the privateelapsed_months.period_windows(..., *, end_of_month=True): windows run between anchored boundaries. A fractional final window is the requested share of the next scheduled period's days.tests/unit/test_period_anchoring.pychecks boundaries, measurement, and windows against hand-worked schedules and properties (the month a boundary lands in, the day it keeps, monotonicity, sign symmetry), not against a reimplementation.tests/unit/strategies.pygains month-end and late-month date strategies.CashFlowStream.from_recurringandGenerationStream.from_capacitysize the tail against the next anchored boundary. A Jan 30 monthly start with 1.5 periods now expects 15 tail days (Feb 28 to Mar 30), not 14. These tests and Debt, construction, depreciation, and PTC schedules use anchored dates #49's still use a temporaryanchored_boundaryhelper instrategies.py; Property tests use independent references instead of reimplemented calendar oracles #52 replaces it withadd_periodsand removes it.Behavior changes
With
end_of_month=Trueas the default, these change for every existing caller:Affected callers:
CashFlowStream.from_recurring,GenerationStream.from_capacity/with_capacity,EnergyProjectsections given an explicit period count, andConstantRateEscalationwith month or quarter periods. These callers can't passend_of_monthyet.Not in this PR (why #38 stays open)
timeline.operations_endstill step from the previous boundary.vdb_scheduledates,AmortizationBuilderand construction interest periods, and the PTC eligibility end don't useadd_periodsyet.macrs_scheduleraises for a Feb 29 placed-in-service date.end_of_monththrough stream factories, escalation, finance/tax schedules, and the builder.dateutil.Testing
uv run ruff check,uv run ruff format --check,uv run mypy dcaf/, anduv run pytestpass (925 tests), and the Hypothesis properties also pass at 3,000 examples each.🤖 Generated with Claude Code