nyholm/effective-interest-rate 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

nyholm/effective-interest-rate

最新稳定版本:1.0.1

Composer 安装命令:

composer require nyholm/effective-interest-rate

包简介

A library to calculate effective interest rate. Also know as XIRR or effective APR.

README 文档

README

Latest Version Software License Build Status Code Coverage Quality Score Total Downloads

This is a library that calculates the effective interest rate. The effective interest could also be called XIRR or effective APR. This is the PHP library. You will find a JavaScript version of this library here.

Examples

Equal payments

If you are do a car loan of 100 000 Money. The loan is for 48 months and you pay 2 400 Money every month. What is the effective interest?

We guess that it is somewhere around 3%.

use Nyholm\EffectiveInterest\Calculator;

$principal = 100000;
$payment = 2400;
$numberOfMonths = 48;
$guess = 0.03;
$calculator = new Calculator();

$interest = $calculator->withEqualPayments($principal, $payment, $numberOfMonths, $guess);

echo $interest; // 0.07115

Correct answer is 7.12%

Specified payments

What if the payments are not equal? The first payment has an administration fee of 400 Money and we like to pay the rest of the loan after 36 months. So the 36th payment will be 31 200 Money.

use Nyholm\EffectiveInterest\Calculator;

$principal = 100000;
$payment = 2400;
$guess = 0.03;
$startDate = '2017-04-30';
$calculator = new Calculator();

$payments = [
    '2017-04-30' => $payment + 400,
    '2017-05-31' => $payment,
    '2017-06-30' => $payment,
    '2017-07-31' => $payment,
    // More dates
    '2019-12-31' => $payment,
    '2020-01-31' => $payment,
    '2020-02-28' => $payment,
    '2020-03-31' => 31200,
];

$interest = $calculator->withSpecifiedPayments($principal, $startDate, $payments, $guess);

echo $interest; // 0.084870

Correct answer is 8.49%

The mathematics

We are using the same formula that Excel's XIRR function is using. We are also using NewtonRaphsons method to numerically find the interest we are looking for.

Effective interest formula

统计信息

  • 总下载量: 161.78k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 24
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 24
  • Watchers: 2
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-04-03