https://github.com/nyholm/effective-interest-rate
Calculate effective interest, XIRR or effective APR.
https://github.com/nyholm/effective-interest-rate
finance interest interest-rates mathematics
Last synced: 3 months ago
JSON representation
Calculate effective interest, XIRR or effective APR.
- Host: GitHub
- URL: https://github.com/nyholm/effective-interest-rate
- Owner: Nyholm
- License: mit
- Created: 2017-04-02T17:59:50.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2021-03-07T10:30:51.000Z (over 4 years ago)
- Last Synced: 2025-03-28T21:02:05.828Z (3 months ago)
- Topics: finance, interest, interest-rates, mathematics
- Language: PHP
- Homepage:
- Size: 21.5 KB
- Stars: 23
- Watchers: 3
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: Readme.md
- Changelog: Changelog.md
- License: LICENSE
Awesome Lists containing this project
README
# Effective interest rate
[](https://github.com/nyholm/effective-interest-rate/releases)
[](LICENSE)
[](https://travis-ci.org/Nyholm/effective-interest-rate)
[](https://scrutinizer-ci.com/g/nyholm/effective-interest-rate)
[](https://scrutinizer-ci.com/g/nyholm/effective-interest-rate)
[](https://packagist.org/packages/nyholm/effective-interest-rate)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](https://github.com/Nyholm/effective-interest-rate-js).## 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%.
```php
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.```php
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.