PHP code example of nyholm / effective-interest-rate

1. Go to this page and download the library: Download nyholm/effective-interest-rate library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nyholm / effective-interest-rate example snippets


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

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