This is a light-weight library that allows calculating annual loan amortization schedule with a capability of setting early (additional) payments. The calculation is implemented is in this library without using any extra heavy transitive dependencies.
It is written in Java, thus can be used in any language that have interop with Java.
If you want to try it in a serverless container there is a project that provides a native image of a service that is a wrapper for this library. It has one HTTP endpoint for calculating loan amortization. You can find it here.
Add one of the following the dependencies depending on what package manager you use.
<dependency>
<groupId>io.github.ArtyomPanfutov</groupId>
<artifactId>loan-amortization-calculator</artifactId>
<version>1.0.9</version>
</dependency>
implementation 'io.github.ArtyomPanfutov:loan-amortization-calculator:1.0.9'
implementation("io.github.ArtyomPanfutov:loan-amortization-calculator:1.0.9")
libraryDependencies += "io.github.ArtyomPanfutov" % "loan-amortization-calculator" % "1.0.9"
See the following example of source code to understand the API of the library.
A Regular loan without any additional payments
Loan loan = Loan.builder()
.amount(500000.39) // Debt amount
.rate(4.56) // Interest rate
.term(32) // Loan term in MONTHS
.build();
LoanAmortizationCalculator calculator = LoanAmortizationCalculatorFactory.create();
LoanAmortization amortization = calculator.calculate(loan);
2. A loan with different kinds of addtitional payments
```java
Loan loan = Loan.builder()
.amount(BigDecimal.valueOf(500000.32)) // Loan debt
.rate(BigDecimal.valueOf(4.56)) // Interest rate
.term(10) // Loan term in MONTHS
.earlyPayment(3, EarlyPayment.builder()
.amount(3500.00)
.strategy(EarlyPaymentStrategy.DECREASE_TERM)
.repeatingStrategy(EarlyPaymentRepeatingStrategy.TO_CERTAIN_MONTH)
.repeatTo(7)
.build())
.earlyPayment(8, EarlyPayment.builder()
.amount(50000.00)
.strategy(EarlyPaymentStrategy.DECREASE_MONTHLY_PAYMENT)
.repeatingStrategy(EarlyPaymentRepeatingStrategy.SINGLE)
.build())
.build();
LoanAmortizationCalculator calculator = LoanAmortizationCalculatorFactory.create();
LoanAmortization amortization = calculator.calculate(loan);
Note, that the loan amortization calculator object can be used as a singleton since it has no shared state.
Early payments or additional payments to a monthly payment can be passed in the map of early payments in loan object.
In that map a key is an integer that indicates the month number of that payment (numbers start with 0).
The value in the map is an early payment object.
An early payment object consists of amount, early payment type (strategy), repeating strategy, and additional parameters.
There are two strategies of early payments:
Each early payment has to have either of these strategies.
An early payment can have a repeating strategy. Basically it allows to copy an early payment to next months. The strategy is applied automatically before calculation starts. This is a required parameter and for the payments that should not be repeated a SINGLE strategy should be set.
This parameter can have the following values:
Additional parameters can be passed for an early payment. Currently, there is only one special parameter that should be passed for payments with TO_CERTAIN_MONTH repeating strategy.
If you pass firstPaymentDate
parameter then the calculatioin strategy for interests will be actual/actual. That means the actual number of days in a month and in a year will be used to get accrued interest. Therefore, you will get different interest value with provided firstPaymentDate
.
If you want to contribute - see CONTRIBUTING.md
Pull requests are welcome!