src/Finance.php
public static function fv(float $rate, int $periods, float $payment, float $present_value, bool $beginning = false): float
    {
        $when = $beginning ? 1 : 0;

        if ($rate == 0) {
            $fv = -($present_value + ($payment * $periods));
            return self::checkZero($fv);
        }

        $initial  = 1 + ($rate * $when);
        $compound = pow(1 + $rate, $periods);
        $fv       = - (($present_value * $compound) + (($payment * $initial * ($compound - 1)) / $rate));

        return self::checkZero($fv);
    }
public static function fv(float $rate, int $periods, float $payment, float $present_value, bool $beginning = false): float
    {
        $when = $beginning ? 1 : 0;

        if ($rate == 0) {
            $fv = -($present_value + ($payment * $periods));
            return self::checkZero($fv);
        }

        $initial  = 1 + ($rate * $when);
        $compound = pow(1 + $rate, $periods);
        $fv       = - (($present_value * $compound) + (($payment * $initial * ($compound - 1)) / $rate));

        return self::checkZero($fv);
    }
public static function fv ( float $ rate , int $ periods , float $ payment , float $ present_value , bool $ beginning = false ) : float { $ when = $ beginning ? 1 : 0 ; if ( $ rate == 0 ) { $ fv = - ( $ present_value + ( $ payment * $ periods ) ) ; return self :: checkZero ( $ fv ) ; } $ initial = 1 + ( $ rate * $ when ) ; $ compound = pow ( 1 + $ rate , $ periods ) ; $ fv = - ( ( $ present_value * $ compound ) + ( ( $ payment * $ initial * ( $ compound - 1 ) ) / $ rate ) ) ; return self :: checkZero ( $ fv ) ; }
Future value for a loan or annuity with compound interest.

Same as the =FV() function in most spreadsheet software.

The basic future-value formula derivation:
https://en.wikipedia.org/wiki/Future_value

PMT*((1+r)ᴺ - 1)
FV = -PV*(1+r)ᴺ - ----------------
r

The (1+r*when) factor adjusts the payment to the beginning or end
of the period. In the common case of a payment at the end of a period,
the factor is 1 and reduces to the formula above. Setting when=1 computes
an "annuity due" with an immediate payment.

Examples:
The future value in 5 years on a 30-year fixed mortgage note of $265000
at 3.5% interest paid at the end of every month. This is how much loan
principle would be outstanding:
fv(0.035/12, 5*12, 1189.97, -265000, false)

The present_value is negative indicating money borrowed for the mortgage,
whereas payment is positive, indicating money that will be paid to the
mortgage.

@param  float $rate
@param  int   $periods
@param  float $payment
@param  float $present_value
@param  bool  $beginning adjust the payment to the beginning or end of the period

@return float
Future value for a loan or annuity with compound interest .