Skip to content

Add early settlement calculations and early repayment charges in Quotes.fs#58

Draft
Copilot wants to merge 4 commits into
mainfrom
copilot/extend-quotes-early-settlement-calculations
Draft

Add early settlement calculations and early repayment charges in Quotes.fs#58
Copilot wants to merge 4 commits into
mainfrom
copilot/extend-quotes-early-settlement-calculations

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 28, 2026

Extends Quotes.fs with early settlement calculations required in UK consumer credit.

Changes Made

src/Quotes.fs

  • EarlySettlementMethod – discriminated union with three methods: Actuarial, RuleOf78, FCA
  • EarlyRepaymentChargeType – discriminated union with two charge types: TieredPercentage of (int * Percent) array and FixedMonthsInterest of int
  • EarlySettlementResult – record bundling OutstandingPrincipal, InterestRebate, SettlementFigure, EarlyRepaymentCharge, and NetSettlementFigure
  • ruleOf78Settlement (private) – sum-of-digits rebate computed from the original basic schedule
  • fcaSettlement (private) – statutory rebate via the existing Interest.calculateRebate function (Consumer Credit Act s.94 / Consumer Credit (Early Settlement) Regulations 2004)
  • calculateEarlyRepaymentCharge (public) – computes the ERC for either a tiered-percentage or a fixed-months-interest charge type
  • getEarlySettlementQuote (public) – top-level function combining all three settlement methods with an optional ERC, returning an EarlySettlementResult

tests/EarlySettlementTests.fs

New test file (12 tests) covering:

  • Actuarial method matches getQuote output
  • Rule of 78: rebate ≥ 0, settlement figure ≤ remaining payments total
  • FCA: rebate ≥ 0, settlement figure ≤ remaining payments total
  • Tiered-percentage ERC (year-1 tier and beyond-last-tier fallback)
  • Fixed-months-interest ERC
  • Net settlement = settlement figure + ERC
  • Standalone calculateEarlyRepaymentCharge for both charge types
  • All three methods return positive settlement figures

Testing

  • ✅ Build succeeds with 0 errors
  • ✅ All 12 new tests pass
  • ✅ 219 pre-existing test failures (unrelated Interest.Rate.ToString() HTML generation bug) are unaffected

Copilot AI and others added 2 commits April 28, 2026 23:28
Copilot AI requested a review from simontreanor April 28, 2026 23:31
Copy link
Copy Markdown
Owner

@simontreanor simontreanor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot continue

Copy link
Copy Markdown
Author

Copilot AI commented Apr 29, 2026

@copilot continue

Continued and completed the implementation. Commit f1a286a adds EarlySettlementTests.fs to the test project and fixes the base parameters' evaluation date so all 12 new tests pass. The full checklist is now done:

  • EarlySettlementMethod (Actuarial / RuleOf78 / FCA), EarlyRepaymentChargeType (TieredPercentage / FixedMonthsInterest), and EarlySettlementResult types in Quotes.fs
  • ruleOf78Settlement and fcaSettlement private helpers
  • Public calculateEarlyRepaymentCharge and getEarlySettlementQuote functions
  • 12 tests in EarlySettlementTests.fs covering all code paths (all pass; 219 pre-existing failures unchanged)

Copilot AI changed the title [WIP] Add early settlement calculations and early repayment charges in Quotes.fs Add early settlement calculations and early repayment charges in Quotes.fs Apr 29, 2026
Copilot AI requested a review from simontreanor April 29, 2026 22:41
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.

Quotes.fs: early settlement figure and Early Repayment Charges

2 participants