承接 phelix/loan-amortization 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

phelix/loan-amortization

Composer 安装命令:

composer require phelix/loan-amortization

包简介

Comprehensive Loan amortization computation package for amortization schedules and interest rates

README 文档

README

This is a PHP SDK for calculating loan amortization Calculates the total interest, repayment amount as well as the repayment schedule

Types of Interests Included

  • Flat Rate Interest
    • This is interest type where the interest rate for each period is computed as a percentage of the loan principal amount
    • The loan interest is constant over the entire repayment period
  • Interest on Reducing Balance
    • In this case, instead of computing interest on the principal amount, the interest for each period is calculated as a percentage of the balance on principal repayments at at that time
    • The user thus pays less interest in later periods when their loan balance reduces as compared in the amount they'd pay at the start of the loan repayment schedle

Types of Amortization Included

  • Loan amortization basically describes the repayment schedule spread over a given duration
  • The following types are supported:
    • Even Principal Repayment: This is a repayment plan where the principal repayment remains constant over the entire repayment duration
    • Even Installment Repayment: This is a repayment plan where the total repayment remains constant over the entire repayment duration
  • Loan amortization types depend on the interest type:
    • Flat Rate Interest: Amortization type doesn't really matter. The repayments will have both equal installment and principal and interest repayments for the entire repayment duration
    • Interest on Reducing Balance: Supports both types. Either of them can be used at a time

Grace on Repayments

The package supports three types of grace on repayments

  • Grace on Principal Repayments: When applied, the principal repayments for the set period are deferred to a later period. For instance, if grace on principal repayments is set to 2, then the first two installments will have principal repayments of 0 and the principal amounts recouped through the remaining installments
  • Grace on Interest Repayments: When applied, the interest repayments for the set period are deferred to a later period. For instance, if grace on interest repayments is set to 2, then the first two installments will have the interest repayments of 0 and the interests will be collected in the last two installments.
  • Grace on Interest: This is a conditional grace applied to interest collected. If set, the interest for the specified period is zero-rated ie no interest is paid for that period. For instance, one can set if a loan is repaid within a year, then the first two months interests will be zero-rated hence the user only pays the principal amounts for those first two months.

Installation

composer require phelix/loan-amortization

How To test

The test is more of a visualization tool than an actual test.

vendor/bin/phpunit test

Documentation

As you go through the sample code samples, please note that anywhere with periods, the period types can take any of the values: days, weeks, months and years . Everything in lower case and plural.

1. Flat Interest Rate

Loan Details:

  • Loan Principal = 50,000.00
  • Interest Rate = 12% per year
  • Loan duration = 1 week
  • Repayment Schedule = 1 repayment every 2 days
<?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. Reducing Balance - Equal Principal Repayments

Loan Details:

  • Loan Principal = 50,000.00
  • Interest Rate = 12% per year
  • Loan duration = 1 week
  • Repayment Schedule = 1 repayment every 2 days
<?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. Reducing Balance - Equal Installment Repayments

Loan Details:

  • Loan Principal = 50,000.00
  • Interest Rate = 12% per year
  • Loan duration = 1 week
  • Repayment Schedule = 1 repayment every 2 days
<?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. Grace on Principal Payments

Loan Details:

  • Loan Principal = 50,000.00
  • Interest Rate = 12% per year
  • Loan duration = 1 week
  • Repayment Schedule = 1 repayment every 2 days
<?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);

Credits

phelix/loan-amortization 适用场景与选型建议

phelix/loan-amortization 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.75k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2021 年 03 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「amortization」 「phelix」 「loan-calculator」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 phelix/loan-amortization 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 phelix/loan-amortization 我们能提供哪些服务?
定制开发 / 二次开发

基于 phelix/loan-amortization 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 5.75k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 17
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2021-03-10