FUNCTIONS CORE

Periods()

Calculate the duration for paying back a loan at fixed interest rate and payments

Syntax

Signature
Periods( nLoan, nPayBack, nInterestRate ) --> nDuration

Arguments

nLoan

nPayBack

nInterestRate

Example

Periods.prg
PROCEDURE Main()

   LOCAL nMonthlyRate := 0.095 / 12

   Check( 'Round( Periods( 4000, 200, nMonthlyRate ), 2 ) ', Round( Periods( 4000, 200, nMonthlyRate ), 2 ), 21.86 )
   Check( 'Periods( 1200, 100, 0 )                        ', Periods( 1200, 100, 0 ), 12 )
   Check( 'Periods( 4000, 20, nMonthlyRate )              ', Periods( 4000, 20, nMonthlyRate ), -1 )

RETURN

STATIC PROCEDURE Check( cTitle, xResult, xExpected )

   QOut( cTitle + IIF( xResult == xExpected, "OK", "ERROR" ) )

RETURN

Output

Round( Periods( 4000, 200, nMonthlyRate ), 2 ) OK
Periods( 1200, 100, 0 )                        OK
Periods( 4000, 20, nMonthlyRate )              OK