PHP code example of uruba / financalc

1. Go to this page and download the library: Download uruba/financalc 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/ */

    

uruba / financalc example snippets


// replace the example Composer-bound path with yours



use FinanCalc\FinanCalc;

...

$annuityCalculatorFactory = FinanCalc
    ::getInstance()
    ->getFactory('DebtAmortizatorFactory')
    ->newYearlyDebtAmortization(
        40000,
        6,
        0.12);

use FinanCalc\Calculators\DebtAmortizator;
use FinanCalc\Utils\Time\TimeUtils;

...

$annuityCalculatorDirect = new DebtAmortizator(
                                       40000,
                                       6,
                                       TimeSpan::asDuration(1),
                                       0.12);

    use FinanCalc\FinanCalc;
    
    ...
    
    // Instantiation by a factory method 
    // – 
    // in our case we calculate a yearly-compounded annuity
    // with a duration of 5 periods (here years),
    // 100000 money units paid out per period
    // and a compounding interest rate of 0.15 (i.e., 15%)
    $annuityCalculatorObject = FinanCalc
                                    ::getInstance()
                                    ->getFactory('AnnuityCalculatorFactory')
                                    ->newYearlyAnnuity(
                                        100000, 
                                        5, 
                                        0.15);
    

    // get the present value of the annuity in arrears
    // (as a string)
    $PV = $annuityCalculatorObject->getPresentValue(
                        new AnnuityPaymentTypes(AnnuityPaymentTypes::IN_ARREARS)
                    );
    // get the future value of the annuity in arrears
    // (as a string)
    $FV = $annuityCalculatorObject->getFutureValue(
                        new AnnuityPaymentTypes(AnnuityPaymentTypes::IN_ARREARS)
                    );
    

    use FinanCalc\FinanCalc;
    use FinanCalc\Utils\Serializers\XMLSerializer;

    ...

    // Instantiation by a factory method
    // –
    // in our case we calculate a yearly-compounded annuity
    // with a duration of 5 periods (here years),
    // 100000 money units paid out per period
    // and a compounding interest rate of 0.15 (i.e., 15%)
    $annuityCalculatorObject = FinanCalc
                                    ::getInstance()
                                    ->getFactory('AnnuityCalculatorFactory')
                                    ->newYearlyAnnuity(
                                        100000,
                                        5,
                                        0.15);
    

    $result = $annuityCalculatorObject->getSerializedResult(new XMLSerializer());
    

    use FinanCalc\FinanCalc;

    ...

    // Instantiation by a factory method
    // –
    // in our case we calculate a yearly-compounded annuity
    // with a duration of 5 periods (here years),
    // 100000 money units paid out per period
    // and a compounding interest rate of 0.15 (i.e., 15%)
    $annuityCalculatorObject = FinanCalc
                                    ::getInstance()
                                    ->getFactory('AnnuityCalculatorFactory')
                                    ->newYearlyAnnuity(
                                        100000,
                                        5,
                                        0.15);
    

    $result = $annuityCalculatorObject->getResultAsArray();
    

    array (
      'annuitySinglePaymentAmount' => '100000',
      'annuityNoOfCompoundingPeriods' => '5',
      'annuityInterest' => '0.15',
      'annuityPeriodLength' =>
      array (
        'years' => '1.00000000',
        'months' => '12.00000000',
        'days' => '360.00000000',
      ),
      'annuityPresentValue' =>
      array (
        'in_advance' => '385497.83',
        'in_arrears' => '335215.53',
      ),
      'annuityFutureValue' =>
      array (
        'in_advance' => '775373.79',
        'in_arrears' => '674238.12',
      ),
    )