/* $DOC$
   $NAME$
      FV()
   $CATEGORY$
      CT3 math functions
   $ONELINER$
      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
   $STATUS$
      Ready
   $COMPLIANCE$
      FV() is compatible with CT3's FV().
   $PLATFORMS$
      All
   $FILES$
      Library is hbct.
   $SEEALSO$
      PV(), Payment(), Periods(), Rate()
   $END$
 */

/* $DOC$
   $NAME$
      PV()
   $CATEGORY$
      CT3 math functions
   $ONELINER$
      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
   $STATUS$
      Ready
   $COMPLIANCE$
      PV() is compatible with CT3's PV().
   $PLATFORMS$
      All
   $FILES$
      Library is hbct.
   $SEEALSO$
      FV(), Payment(), Periods(), Rate()
   $END$
 */

/* $DOC$
   $NAME$
      Payment()
   $CATEGORY$
      CT3 math functions
   $ONELINER$
      Payments for a loan
   $SYNTAX$
      Payment( nLoan, nInterest, nPeriods ) --> nPayment
   $ARGUMENTS$
      <nLoan>        amount of money you get from the bank
      <nInterest>    rate of interest per period, 1 == 100%
      <nPeriods>     period count
   $RETURNS$
      <nPayment>     Periodical payment one has to make to pay the
                     loan <nLoan> back
   $DESCRIPTION$
      Payment() calculates the payment one has to make periodically
      to pay back a loan <nLoan> within <nPeriods> periods 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
      <nPayment> = <nLoan>*(<nInterest>/100)/(1-(1+<nInterest>/100)^(-n))
   $EXAMPLES$
      // You get a loan of 5172.56 at a interest rate of 0.5% per
      // month (6% per year).
      // For 5 years, you have to pay back every month

      ? Payment( 5172.56, 0.005, 60 ) // --> 100.00
   $STATUS$
      Ready
   $COMPLIANCE$
      Payment() is compatible with CT3's Payment().
   $PLATFORMS$
      All
   $FILES$
      Library is hbct.
   $SEEALSO$
      PV(), FV(), Periods(), Rate()
   $END$
 */

/* $DOC$
   $NAME$
      Periods()
   $CATEGORY$
      CT3 math functions
   $ONELINER$
      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.
   $STATUS$
      Ready
   $COMPLIANCE$
      Periods() is compatible with CT3's Periods().
   $PLATFORMS$
      All
   $FILES$
      Library is hbct.
   $SEEALSO$
      PV(), FV(), Payment(), Rate()
   $END$
 */

/* $DOC$
   $NAME$
      Rate()
   $CATEGORY$
      CT3 math functions
   $ONELINER$
      Estimate rate of interest for a loan
   $SYNTAX$
      Rate( nLoan, nPayment, nPeriods ) --> nRate
   $ARGUMENTS$
      <nLoan>          amount of money you get from the bank
      <nPayment>       amount of money you pay back per period
      <nPeriods>       number of periods you pay the loan back
   $RETURNS$
      <nInterest>    estimated rate of interest per period, 1 == 100%
   $DESCRIPTION$
      Rate() calculates the rate of interest per period for the given
      loan, payment per periods and number of periods. This is done with
      the same equation used in the Payment() or Periods() function:

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

      However, this equation can not be solved for <nInterest> in a "closed"
      manner, i.e. <nInterest> = ..., so that the result can only be estimated.
   $EXAMPLES$
      // You get a loan of 5172.56, pay 100 back every month for
      // 5 years (60 months). The effective interest rate per
      // period (=month) is

      ? Rate( 5172.56, 100, 60 ) // --> 0.005
   $STATUS$
      Ready
   $COMPLIANCE$
      Rate() is compatible with CT3's Rate().
   $PLATFORMS$
      All
   $FILES$
      Library is hbct.
   $SEEALSO$
      PV(), FV(), Payment(), Periods()
   $END$
 */
