vovke / loan-payments-calculator
PHP library for payment schedule calculations, using various strategies and configurations.
Installs: 5 986
Dependents: 0
Suggesters: 0
Security: 0
Stars: 14
Watchers: 4
Forks: 4
Open Issues: 2
pkg:composer/vovke/loan-payments-calculator
Requires
- php: >=5.6.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.3
- phpmd/phpmd: ^2.6
- phpunit/phpunit: ^5.7 || ^6.0
- squizlabs/php_codesniffer: ^2.8
This package is not auto-updated.
Last update: 2025-12-13 21:41:11 UTC
README
LoanPaymentsCalculator is a programmer-oriented library for PHP. It is created to provide Loan Payment Schedules for various inputs and strategies. Mainly developed for the short term loans it can be used for any other loan types as well.
Installation
You may use Composer to download and install LoanPaymentsCalculator as well as its dependencies.
$ composer require vovke/loan-payments-calculator
Standards
All the dates meet ISO 8601 standard, Y-m-d (YYYY-MM-DD)
Components
DateProvider
We use it to provide closest date that suits specific rules, for example, first day of month, not bank holiday and etc.
dateProvider = new DateProvider(DateDetermineStrategy, HolidayProvider, shiftToFuture = true)
dateProvider->calculate( startDate )
HolidayProvider
an Interface for checking if the specific date is a bank holiday. Used for period calculation in Schedule.
Period
Period class is used to provide an object representing a time frame where needed, it contains start and end date for the specific period and the amount of days between those.
We use it as a container to describe the Loan period, where startDate is the day when Loan will potentially get issued, and endDate is the date of the last repayment, we also use period for each of the Loan's payments and in that case endDate is the date of the payment's repayment.
Schedule
Schedule class is used to generate periods for the given loan period, number of payments and payment frequency.
$schedule = new Schedule($startDate, $numberOfPeriods, $dateProvider)
PaymentScheduleCalculator
PaymentScheduleCalculator interface is a contract for implementing different ways of payments calculations.
EqualPrincipalPaymentScheduleCalculator
EqualPrincipalPaymentScheduleCalculator is the simplest implementation of PaymentScheduleCalculator interface, generates payments with equal principal amount.
$startDate = new \DateTime('1984-08-08');
$principalAmount = 500;
$numberOfPeriods = 5;
$dailyInterestRate = 0.000383;
$dateProvider = new DateProvider(new ExactDayOfMonthStrategy(), new WeekendsProvider(), true);
$schedule = new Schedule($startDate, $numberOfPeriods, $dateProvider);
$schedulePeriods = $schedule->generatePeriods();
$paymentSchedule = new EqualPrincipalPaymentScheduleCalculator($schedulePeriods, $principalAmount, $dailyInterestRate);
$payments = $paymentSchedule->calculateSchedule();
AnnuityPaymentScheduleCalculator
AnnuityPaymentScheduleCalculator generates payments with equal payments amount.
...
$paymentSchedule = new AnnuityPaymentScheduleCalculator($schedulePeriods, $principalAmount, $dailyInterestRate);
$payments = $paymentSchedule->calculateSchedule();
License
Released under the terms of the MIT License.