phelix / loan-amortization
全面的贷款摊销计算包,用于计算摊销表和利率
v1.0.18
2023-05-03 13:06 UTC
Requires (Dev)
- phpunit/phpunit: 6.*
README
这是一个PHP SDK,用于计算贷款摊销。它计算总利息、还款金额以及还款计划。
包含的利率类型
- 固定利率利息
- 这是利息类型,其中每个期间的利率都是按贷款本金金额的百分比计算的
- 整个还款期间,贷款利息保持不变
- 减少余额的利息
- 在这种情况下,不是计算本金金额的利息,而是计算每个期间的利息为本金还款余额的百分比
- 因此,当用户的贷款余额减少时,他们将在后期支付更少的利息,这与他们在贷款还款计划开始时支付的金额相比
包含的摊销类型
- 贷款摊销基本上描述了在给定时间段内分散的还款计划
- 支持以下类型
- 等额本金还款:这是一种还款计划,其中本金还款在整个还款期间保持不变
- 等额本息还款:这是一种还款计划,其中总还款在整个还款期间保持不变
- 贷款摊销类型取决于利率类型
- 固定利率:摊销类型并不重要。在整个还款期间,还款将包含等额分期付款和本金及利息还款
- 减少余额的利息:支持这两种类型。任何时候都可以使用其中之一
还款宽限期
该包支持三种还款宽限期类型
- 本金还款宽限期:当应用时,设定期间的本金还款将被推迟到以后。例如,如果本金还款宽限期设置为2,那么前两个分期付款将没有本金还款,本金将通过剩余的分期付款收回
- 利息还款宽限期:当应用时,设定期间的利息还款将被推迟到以后。例如,如果利息还款宽限期设置为2,那么前两个分期付款将没有利息还款,利息将在最后两个分期付款中收取。
- 利息宽限期:这是对收取的利息应用的条件宽限期。如果设置,指定期间的利息为零利率,即该期间不支付利息。例如,如果贷款在一年内偿还,则前两个月利息为零利率,因此用户只需支付前两个月的本金金额。
安装
composer require phelix/loan-amortization
如何测试
这个测试更多的是一个可视化工具,而不是真正的测试。
vendor/bin/phpunit test
文档
在您查看示例代码时,请注意,任何带有期间的区域,期间类型可以取以下任何值: days(天),weeks(周),months(月)和 years(年)。所有内容均为小写且为复数。
1. 固定利率
贷款详情
- 贷款本金 = 50,000.00
- 年利率 = 12%
- 贷款期限 = 1周
- 还款计划 = 每2天还款一次
<?php use Phelix\LoanAmortization\ScheduleGenerator; $interestCalculator = new ScheduleGenerator(); $interestCalculator ->setPrincipal(50000) ->setInterestRate(12, "yearly", ScheduleGenerator::FLAT_INTEREST) // note the interest type ->setLoanDuration(1, "weeks") // could be "years" to have it in years or "months" to have it in months ->setRepayment(1,2, "days") ->generate(); print "\nTotal Interest = {$interestCalculator->interest} \n"; print "Effective Interest Rate = {$interestCalculator->effective_interest_rate} \n"; print "Total Repayable amount = {$interestCalculator->amount} \n"; print "Number of Installments = {$interestCalculator->no_installments} \n"; print "Repayment Frequency = {$interestCalculator->repayment_frequency} \n"; print "Amortization Schedule: \n"; print_r($this->interestCalculator->amortization_schedule); // Sample Schedule Response: Array ( [0] => Array ( [principal_repayment] => 14285.71, [interest_repayment] => 32.88, [total_amount_repayment] => 14318.59, [principal_repayment_balance] => 35714.29 ), [1] => Array ( [principal_repayment] => 14285.71, [interest_repayment] => 32.88, [total_amount_repayment] => 14318.59, [principal_repayment_balance] => 21428.58, ), [2] => Array ( [principal_repayment] => 14285.71, [interest_repayment] => 32.88, [total_amount_repayment] => 14318.59, [principal_repayment_balance] => 7142.87, ), [3] => Array ( [principal_repayment] => 7142.87, [interest_repayment] => 16.43, [total_amount_repayment] => 7159.3, [principal_repayment_balance] => 0 ) );
2. 余额递减 - 等额本金还款
贷款详情
- 贷款本金 = 50,000.00
- 年利率 = 12%
- 贷款期限 = 1周
- 还款计划 = 每2天还款一次
<?php use Phelix\LoanAmortization\ScheduleGenerator; $interestCalculator = new ScheduleGenerator(); $interestCalculator ->setPrincipal(50000) ->setInterestRate(12, "yearly", ScheduleGenerator::INTEREST_ON_REDUCING_BALANCE) // note the interest type ->setLoanDuration(1, "weeks") ->setRepayment(1,2, "days") ->setAmortization(ScheduleGenerator::EVEN_PRINCIPAL_REPAYMENT) // note the amortization type ->generate(); print "\nTotal Interest = {$interestCalculator->interest} \n"; print "Effective Interest Rate = {$interestCalculator->effective_interest_rate} \n"; print "Total Repayable amount = {$interestCalculator->amount} \n"; print "Number of Installments = {$interestCalculator->no_installments} \n"; print "Repayment Frequency = {$interestCalculator->repayment_frequency} \n"; print "Amortization Schedule: \n"; print_r($this->interestCalculator->amortization_schedule); // Sample Response Array ( [0] => Array ( [principal_repayment] => 21428.57, [interest_repayment] => 49.32, [total_amount_repayment] => 21477.89, [principal_repayment_balance] => 28571.43 ), [1] => Array ( [principal_repayment] => 21428.57, [interest_repayment] => 28.18, [total_amount_repayment] => 21456.75, [principal_repayment_balance] => 7142.86 ), [2] => Array ( [principal_repayment] => 7142.86, [interest_repayment] => 7.05, [total_amount_repayment] => 7149.91, [principal_repayment_balance] => 0 ) );
3. 余额递减 - 等额本息还款
贷款详情
- 贷款本金 = 50,000.00
- 年利率 = 12%
- 贷款期限 = 1周
- 还款计划 = 每2天还款一次
<?php use Phelix\LoanAmortization\ScheduleGenerator; $interestCalculator = new ScheduleGenerator(); $interestCalculator ->setPrincipal(50000) ->setInterestRate(12, "yearly", ScheduleGenerator::INTEREST_ON_REDUCING_BALANCE) // note the interest type ->setLoanDuration(1, "weeks") ->setRepayment(1,2, "days") ->setAmortization(ScheduleGenerator::EVEN_INSTALLMENT_REPAYMENT) // note the amortization type ->generate(); print "\nTotal Interest = {$interestCalculator->interest} \n"; print "Effective Interest Rate = {$interestCalculator->effective_interest_rate} \n"; print "Total Repayable amount = {$interestCalculator->amount} \n"; print "Number of Installments = {$interestCalculator->no_installments} \n"; print "Repayment Frequency = {$interestCalculator->repayment_frequency} \n"; print "Amortization Schedule: \n"; print_r($this->interestCalculator->amortization_schedule); // Sample Response Array ( [0] => Array ( [principal_repayment] => 16650.23, [interest_repayment] => 49.32, [total_amount_repayment] => 16699.55, [principal_repayment_balance] => 33349.77 ), [1] => Array ( [principal_repayment] => 16666.66, [interest_repayment] => 32.89, [total_amount_repayment] => 16699.55, [principal_repayment_balance] => 16683.11, ), [2] => Array ( [principal_repayment] => 16683.11, [interest_repayment] => 16.45, [total_amount_repayment] => 16699.55, [principal_repayment_balance] => 0 ) );
4. 本金还款宽限期
贷款详情
- 贷款本金 = 50,000.00
- 年利率 = 12%
- 贷款期限 = 1周
- 还款计划 = 每2天还款一次
<?php use Phelix\LoanAmortization\ScheduleGenerator; $interestCalculator = new ScheduleGenerator(); $interestCalculator ->setPrincipal(50000) ->setInterestRate(12, "yearly", ScheduleGenerator::INTEREST_ON_REDUCING_BALANCE) // note the interest type ->setLoanDuration(1, "weeks") ->setRepayment(1,2, "days") ->setAmortization(ScheduleGenerator::EVEN_INSTALLMENT_REPAYMENT) // note the amortization type ->setGraceOnPrincipalRepayment(2) // note the grace period. First two principals' payment deferred ->setGraceOnInterestRepayment(1) // note the grace period. First month interest payment is deferred ->setGraceOnInterest(5, "days", 2, "days") // not how this is set. It reads: If you repay entire loan within 5 days, then no interest will be charged for the first two days ->generate(); print "\nTotal Interest = {$interestCalculator->interest} \n"; print "Effective Interest Rate = {$interestCalculator->effective_interest_rate} \n"; print "Total Repayable amount = {$interestCalculator->amount} \n"; print "Number of Installments = {$interestCalculator->no_installments} \n"; print "Repayment Frequency = {$interestCalculator->repayment_frequency} \n"; print "Amortization Schedule: \n"; print_r($this->interestCalculator->amortization_schedule);
信贷
- Phelix Juma (jumaphelix@kuzalab.com)