Skip to content

Commit

Permalink
FINERACT-2162: Chargeback implementation for progressive interest rec…
Browse files Browse the repository at this point in the history
…alculation enabled loan when no payment allocation set.

Emi Calculator Tests for Principal only after maturity day scenario.
  • Loading branch information
somasorosdpc committed Jan 31, 2025
1 parent 9abbbee commit c74f1c4
Showing 1 changed file with 93 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1709,6 +1709,97 @@ public void test_S4_full_chargeback_in_middle_of_instalment_before_maturity_date
checkPeriod(interestSchedule, 4, 0, 17.01, 0.005833333333, 0.2, 16.81, 16.96);
checkPeriod(interestSchedule, 5, 0, 17.06, 0.005833333333, 0.1, 16.96, 0.0);
}

@Test
public void test_S5_and_S6_full_chargeback_s_on_different_dates_and_after_maturity_date() {
final List<LoanScheduleModelRepaymentPeriod> expectedRepaymentPeriods = List.of(
repayment(1, LocalDate.of(2024, 1, 1), LocalDate.of(2024, 2, 1)),
repayment(2, LocalDate.of(2024, 2, 1), LocalDate.of(2024, 3, 1)),
repayment(3, LocalDate.of(2024, 3, 1), LocalDate.of(2024, 4, 1)),
repayment(4, LocalDate.of(2024, 4, 1), LocalDate.of(2024, 5, 1)),
repayment(5, LocalDate.of(2024, 5, 1), LocalDate.of(2024, 6, 1)),
repayment(6, LocalDate.of(2024, 6, 1), LocalDate.of(2024, 7, 1)));

final BigDecimal interestRate = BigDecimal.valueOf(7.0);
final Integer installmentAmountInMultiplesOf = null;

Mockito.when(loanProductRelatedDetail.getAnnualNominalInterestRate()).thenReturn(interestRate);
Mockito.when(loanProductRelatedDetail.getDaysInYearType()).thenReturn(DaysInYearType.DAYS_360.getValue());
Mockito.when(loanProductRelatedDetail.getDaysInMonthType()).thenReturn(DaysInMonthType.DAYS_30.getValue());
Mockito.when(loanProductRelatedDetail.getRepaymentPeriodFrequencyType()).thenReturn(PeriodFrequencyType.MONTHS);
Mockito.when(loanProductRelatedDetail.getRepayEvery()).thenReturn(1);
Mockito.when(loanProductRelatedDetail.getCurrencyData()).thenReturn(currency);

final ProgressiveLoanInterestScheduleModel interestSchedule = emiCalculator.generatePeriodInterestScheduleModel(
expectedRepaymentPeriods, loanProductRelatedDetail, loanTermVariations, installmentAmountInMultiplesOf, mc);

final Money disbursedAmount = toMoney(100.0);
emiCalculator.addDisbursement(interestSchedule, LocalDate.of(2024, 1, 1), disbursedAmount);

checkPeriod(interestSchedule, 0, 0, 17.01, 0.0, 0.0, 0.58, 16.43, 83.57);
checkPeriod(interestSchedule, 0, 1, 17.01, 0.005833333333, 0.58, 16.43, 83.57);
checkPeriod(interestSchedule, 1, 0, 17.01, 0.005833333333, 0.49, 16.52, 67.05);
checkPeriod(interestSchedule, 2, 0, 17.01, 0.005833333333, 0.39, 16.62, 50.43);
checkPeriod(interestSchedule, 3, 0, 17.01, 0.005833333333, 0.29, 16.72, 33.71);
checkPeriod(interestSchedule, 4, 0, 17.01, 0.005833333333, 0.2, 16.81, 16.90);
checkPeriod(interestSchedule, 5, 0, 17.00, 0.005833333333, 0.1, 16.9, 0.0);

// repay 1st period
emiCalculator.payPrincipal(interestSchedule, LocalDate.of(2024,2,1), LocalDate.of(2024,2,1), toMoney(16.43));
emiCalculator.payInterest(interestSchedule, LocalDate.of(2024,2,1), LocalDate.of(2024,2,1), toMoney(0.58));
// repay 2nd period
emiCalculator.payPrincipal(interestSchedule, LocalDate.of(2024,3,1), LocalDate.of(2024,3,1), toMoney(16.52));
emiCalculator.payInterest(interestSchedule, LocalDate.of(2024,3,1), LocalDate.of(2024,3,1), toMoney(0.49));
// repay 3rd period
emiCalculator.payPrincipal(interestSchedule, LocalDate.of(2024,4,1), LocalDate.of(2024,4,1), toMoney(16.62));
emiCalculator.payInterest(interestSchedule, LocalDate.of(2024,4,1), LocalDate.of(2024,4,1), toMoney(0.39));
// repay 4th period
emiCalculator.payPrincipal(interestSchedule, LocalDate.of(2024,5,1), LocalDate.of(2024,5,1), toMoney(16.72));
emiCalculator.payInterest(interestSchedule, LocalDate.of(2024,5,1), LocalDate.of(2024,5,1), toMoney(0.29));
// repay 5th period
emiCalculator.payPrincipal(interestSchedule, LocalDate.of(2024,6,1), LocalDate.of(2024,6,1), toMoney(16.81));
emiCalculator.payInterest(interestSchedule, LocalDate.of(2024,6,1), LocalDate.of(2024,6,1), toMoney(0.20));
// repay 6th period
emiCalculator.payPrincipal(interestSchedule, LocalDate.of(2024,7,1), LocalDate.of(2024,7,1), toMoney(16.90));
emiCalculator.payInterest(interestSchedule, LocalDate.of(2024,7,1), LocalDate.of(2024,7,1), toMoney(0.10));

checkPeriod(interestSchedule, 0, 0, 17.01, 0.0, 0.0, 0.58, 16.43, 83.57);
checkPeriod(interestSchedule, 0, 1, 17.01, 0.005833333333, 0.58, 16.43, 83.57);
checkPeriod(interestSchedule, 1, 0, 17.01, 0.005833333333, 0.49, 16.52, 67.05);
checkPeriod(interestSchedule, 2, 0, 17.01, 0.005833333333, 0.39, 16.62, 50.43);
checkPeriod(interestSchedule, 3, 0, 17.01, 0.005833333333, 0.29, 16.72, 33.71);
checkPeriod(interestSchedule, 4, 0, 17.01, 0.005833333333, 0.2, 16.81, 16.90);
checkPeriod(interestSchedule, 5, 0, 17.00, 0.005833333333, 0.1, 16.9, 0.0);

// full chargeback after maturity date
emiCalculator.chargebackPrincipal(interestSchedule, LocalDate.of(2024, 7, 15), toMoney(17.01));

checkPeriod(interestSchedule, 0, 0, 17.01, 0.0, 0.0, 0.58, 16.43, 83.57);
checkPeriod(interestSchedule, 0, 1, 17.01, 0.005833333333, 0.58, 16.43, 83.57);
checkPeriod(interestSchedule, 1, 0, 17.01, 0.005833333333, 0.49, 16.52, 67.05);
checkPeriod(interestSchedule, 2, 0, 17.01, 0.005833333333, 0.39, 16.62, 50.43);
checkPeriod(interestSchedule, 3, 0, 17.01, 0.005833333333, 0.29, 16.72, 33.71);
checkPeriod(interestSchedule, 4, 0, 17.01, 0.005833333333, 0.2, 16.81, 16.90);
checkPeriod(interestSchedule, 5, 0, 17.00, 0.005833333333, 0.1, 16.9, 0.0);
// TODO verify expectaitons and check duedate 15-7-2024
checkPeriod(interestSchedule, 5, 1, 17.01, 0.0, 0, 17.01, 0.0);


// full chargeback after maturity date
emiCalculator.chargebackPrincipal(interestSchedule, LocalDate.of(2024, 7, 30), toMoney(17.00));

checkPeriod(interestSchedule, 0, 0, 17.01, 0.0, 0.0, 0.58, 16.43, 83.57);
checkPeriod(interestSchedule, 0, 1, 17.01, 0.005833333333, 0.58, 16.43, 83.57);
checkPeriod(interestSchedule, 1, 0, 17.01, 0.005833333333, 0.49, 16.52, 67.05);
checkPeriod(interestSchedule, 2, 0, 17.01, 0.005833333333, 0.39, 16.62, 50.43);
checkPeriod(interestSchedule, 3, 0, 17.01, 0.005833333333, 0.29, 16.72, 33.71);
checkPeriod(interestSchedule, 4, 0, 17.01, 0.005833333333, 0.2, 16.81, 16.90);
checkPeriod(interestSchedule, 5, 0, 17.00, 0.005833333333, 0.1, 16.9, 0.0);

// TODO VERIFY EXPECTATION
checkPeriod(interestSchedule, 5, 1, 17.01, 0.0, 0, 17.01, 0.0);
checkPeriod(interestSchedule, 5, 2, 34.01, 0.0, 0, 34.01, 0.0);
}
}

@Test
Expand Down Expand Up @@ -1844,7 +1935,9 @@ private static void checkPeriod(final ProgressiveLoanInterestScheduleModel inter
private static void checkPeriod(final ProgressiveLoanInterestScheduleModel interestScheduleModel, final int repaymentIdx,
final int interestIdx, final double emiValue, final double rateFactor, final double interestDue,
final double interestDueCumulated, final double principalDue, final double remaingBalance) {
Assertions.assertTrue(repaymentIdx < interestScheduleModel.repaymentPeriods().size(), repaymentIdx+"th repaymentPeriod is not found.");
final RepaymentPeriod repaymentPeriod = interestScheduleModel.repaymentPeriods().get(repaymentIdx);
Assertions.assertTrue(interestIdx < repaymentPeriod.getInterestPeriods().size(), repaymentIdx+"th repaymentPeriod's "+interestIdx+"th interest period is not found.");
final InterestPeriod interestPeriod = repaymentPeriod.getInterestPeriods().get(interestIdx);

Assertions.assertEquals(emiValue, toDouble(repaymentPeriod.getEmi()));
Expand Down

0 comments on commit c74f1c4

Please sign in to comment.