PV()

PV()

Present value of a loan

Syntax

      PV( nPayment, nInterest, nPeriods ) --> nPresentValue

Arguments

<nPayment> amount of money paid back per period <nInterest> rate of interest per period, 1 == 100%

<nPeriods> period count

Returns

<nPresentValue> Present value of a loan when one is paying back <nDeposit> per period at a rate of interest of <nInterest> per period

Description

PV() calculates the present value of a loan that is paid back in <nPeriods> payments of <nPayment> (Dollars, Euros, Yens, …)
while the rate of interest is <nInterest> per period:
debt in period 0 = <nPresentValue>
debt in period 1 = ((debt in period 0)-<nPayment>)*(1+<nInterest>/100)
debt in period 2 = ((debt in period 1)-<nPayment>)*(1+<nInterest>/100) etc…
debt in period <nPeriod> = ((debt in period <nPeriod>-1)-<nPayment>)*(1+<nInterest>/100)

-> has to be 0, so

    <nPresentValue> = <nPayment>*(1-(1+<nInterest>/100)ˆ(-n)) / (<nInterest>/100)

Examples

      // You can afford to pay back 100 Dollars per month for 5 years
      // at a interest rate of 0.5% per month (6% per year), so instead
      // of 6000 Dollars (the amount you will pay back) the bank will pay
      // you

      ? pv( 100, 0.005, 60 ) // --> 5172.56

Tests

      pv( 100, 0.0, 60 )   == 6000.0
      pv( 100, 0.005, 60 ) == 5172.56

Compliance

PV() is compatible with CT3’s PV().

Platforms

All

Files

Source is finan.c, library is libct.

Seealso

FV(), PAYMENT(), PERIODS(), RATE()

Periods()

Periods()

Number of Periods for a loan

Syntax

      Periods( nLoan, nPayment, nInterest ) --> nPeriods

Arguments

<nLoan> amount of money you get from the bank <nPayment> amount of money you pay back per period <nInterest> rate of interest per period, 1 == 100%

Returns

<nPeriods> number of Periods you need to pay the loan back

Description

Periods() calculates the number of Periods one needs to pay back a loan of <nLoan> with periodical payments of <nPayment> and for a rate of interest <nInterest> per period.

debt in period 0 = <nLoan>
debt in period 1 = ((debt in period 0)-<nPayment>)*(1+<nInterest>/100)
debt in period 2 = ((debt in period 1)-<nPayment>)*(1+<nInterest>/100) etc…
debt in period <nPeriod> = ((debt in period <nPeriod>-1)-<nPayment>)*(1+<nInterest>/100)

-> has to be 0, so

<nPeriods> = -log(1-<nLoan>*(<nInterest>/100)/<nPayment>)/log(1+<nInterest>/100))

Note, however that in the case of nPayment <= <nLoan>*(<nInterest>/100), one would need infinite time to pay the loan back. The functions does then return -1.

Examples

      // You get a loan of 5172.56 at a interest rate of 0.5% per
      // month (6% per year).
      // You can afford to pay 100 back every month, so you need

      ? Periods( 5172.56, 100, 0.005 ) // --> 60.0

      // months to cancel the loan.

Tests

      Periods( 5172.56, 100, 0.005 ) == 60.0
      Periods( 5172.56, 100, 0.0 ) == 51.7256

Compliance

Periods() is compatible with CT3’s Periods().

Platforms

All

Files

Source is finan.c, library is libct.

Seealso

PV(), FV(), PAYMENT(), RATE()

LOG10()

LOG10()

Decadic logarithm of a number

Syntax

      LOG10( <nNumber> ) -> nLogarithm

Arguments

<nNumber> number to logarithm

Returns

<nLogarithm> decadic logarithm of <nNumber>

Description

The function LOG10() calculates the decadic logarithm of <nNumber>, i.e. 10ˆ<nLogarithm> == <nNumber>.

Examples

      ? log10( 10.0 )         // --> 1.0
      ? log10( sqrt( 10.0 ) ) // --> 0.5

Tests

      log10( 10.0 )         == 1.0
      log10( sqrt( 10.0 ) ) == 0.5

Compliance

LOG10() is compatible with CT3’s LOG10().

Platforms

All

Files

Source is math.c, library is libct.

GetPrec()

GetPrec()

Get precision of math functions

Syntax

      GetPrec() -> nDigits

Returns

nDigits digit count between 1 and 16

Description

Be aware that calls to this functions do _NOT_ affect the calculation precision of the math functions at the moment.

Compliance

GetPrec() is compatible with CT3’s GetPrec.

Platforms

All

Files

Source is ctmath.c, library is ct3.

FV()

FV()

Future value of a capital

Syntax

      FV( nDeposit, nInterest, nPeriods ) --> <nFutureValue>

Arguments

<nDeposit> amount of money invested per period <nInterest> rate of interest per period, 1 == 100% <nPeriods> period count

Returns

<nFutureValue> Total value of the capital after <nPeriods> of paying <nDeposit> and <nInterest> interest being paid every period and added to the capital (resulting in compound interest)

Description

FV() calculates the value of a capital after <nPeriods> periods. Starting with a value of 0, every period, <nDeposit> (Dollars, Euros, Yens, …) and an interest of <nInterest> for the current capital are added for the capital (<nInterest>=Percent/100).

Thus, one gets the non-linear effects of compound interests:

value in period 0 = 0

value in period 1 = ((value in period 0)*(1+<nInterest>/100)) + <nDeposit>

value in period 2 = ((value in period 1)*(1+<nInterest>/100)) + <nDeposit> etc….

value in period <nPeriod> = ((value in period <nPeriod>-1)*(1+<nInterest>/100))< + <nDeposit>

                                           = <nDeposit> * sum from i=0 to <nPeriod>-1 over (1+<nInterest>/100)ˆi

                                          = <nDeposit> * ((1+<nInterest>/100)ˆn-1) / (<nInterest>/100)

Examples

      // Payment of 1000 per year for 10 years at a interest rate
      // of 5 per cent per year

      ? fv( 1000, 0.05, 10 ) // --> 12577.893

Tests

      fv( 1000, 0.00, 10 ) == 10000.0
      fv( 1000, 0.05, 10 ) == 12577.893

Compliance

FV() is compatible with CT3’s FV().

Platforms

All

Files

Source is finan.c, library is libct.

Seealso

PV(), PAYMENT(), PERIODS(), RATE()

Floor()

Floor()

Rounds down a number to the next integer

Syntax

      Floor( <nNumber> ) -> <nDownRoundedNumber>

Arguments

<nNumber> number to round down

Returns

<nDownRoundedNumber> the rounded number

Description

The function Floor() determines the biggest integer that is smaller than <nNumber>.

Examples

      ? Floor( 1.1 )  // --> 1.0
      ? Floor( -1.1 ) // --> -2.0

Tests

      Floor( 1.1 )  == 1.0
      Floor( -1.1 ) == -2.0

Compliance

Floor() is compatible with CT3’s Floor().

Platforms

All

Files

Source is math.c, library is libct.

Seealso

CEILING()

Fahrenheit()

Fahrenheit()

Temperature conversion Celsius to Fahrenheit

Syntax

      Fahrenheit( nDegreeCelsius ) --> <nDegreeFahrenheit>

Arguments

<nDegreeCelsius> temperate in degree Celsius

Returns

<nDegreeFahrenheit> temperature in degree Fahrenheit

Description

Fahrenheit() converts temperature values measured in the Celsius scale to the Fahrenheit scale.

Examples

      // melting point of water in standard conditions
      ? Fahrenheit( 0.0 )       // --> 32.0
      // boiling point of water in standard conditions
      ? Fahrenheit( 100.0 )     // --> 212.0

Tests

      Fahrenheit( 0.0 ) == 32.0
      celsius( 100.0 ) == 212.0

Compliance

Fahrenheit() is compatible with CT3’s Fahrenheit().

Platforms

All

Files

Source is num1.c, library is libct.

Seealso

CELSIUS()

CTInit()

CTInit()

Initializes the CT3 library

Syntax

      CTINIT() -> <lInitialized>

Arguments

None

Returns

<lInitialized> .T. if the function has been correctly initialized

Description

The CTINIT() function initializes the CT3 library. Identical code is declared as INIT FUNCTION, thus should be executed automatically at the beginning of the application, but it is a good idea to call it once again explicitly somewhere at the beginning of your program to check the initialization.

Compliance

CTINIT() is a new function in Harbour’s CT3 library.

Platforms

All

Files

Source is ct.prg, library is libct.

Seealso

CTCINIT(), CTCEXIT(), CTEXIT()