Skip to content

fix: preserve payment identity in first annuity-due period - #77

Open
kadyrbekovhamit-cyber wants to merge 1 commit into
Anexen:mainfrom
kadyrbekovhamit-cyber:codex/fix-ppmt-annuity-due-first-period
Open

fix: preserve payment identity in first annuity-due period#77
kadyrbekovhamit-cyber wants to merge 1 commit into
Anexen:mainfrom
kadyrbekovhamit-cyber:codex/fix-ppmt-annuity-due-first-period

Conversation

@kadyrbekovhamit-cyber

Copy link
Copy Markdown

Summary

  • return the full level payment as principal in the first annuity-due period
  • apply the same correction to the vectorized path
  • cover scalar pmt = ipmt + ppmt, vectorized ppmt, and full-term cumprinc

Problem

ipmt correctly returns zero interest for period 1 when payment is at the beginning, but ppmt still applies the ordinary annuity-due formula. This breaks the documented payment identity and leaves a residual principal balance.

rate = 0.005, nper = 12, pv = 1000, pmt_at_beginning = true
pmt(…)          = -85.63823851450982
ipmt(…, per=1)  =   0.0
ppmt(…, per=1)  = -80.66311413640034  (before)

The first payment happens at time zero, so it carries no interest and its entire amount is principal. The corrected ppmt is therefore pmt(...).

Validation

  • full cargo test --release: 238 passed
  • cargo test --release --features nonumpy: 227 passed, 10 ignored
  • cargo fmt --check
  • mutation check: removing the two new branches fails the regression test with -80.66311413640034 !~= -85.63823851450982

Signed-off-by: kadyrbekovhamit-cyber <288885044+kadyrbekovhamit-cyber@users.noreply.github.com>
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