Quick Search:

Snippet Name: Financial management functions

Description: A suite of financial management functions, including present and future value of an annuity and a loan payment calculation function.

Comment: (none)

Language: PHP
Highlight Mode: PHP

```<?PHP

/*

VARIABLES:

\$m  =  number  of  periods  per  year.    For  instance,  if  you  are  For
instance,  if  you  are  making  payments  monthly  then  this  number  is  12.
\$n  =  total  number  of  periods.    For  instance,  if  you  are
compounding  monthly  for  5  years,  this  number  would  be  60  (12  months
x  5  years).
\$R  =  annual  interest  rate  (represented  as  a  decimal,  8%  =  .08)
\$pmt  =  first  or  re-occuring  payment  or  receipt  (this  number  cannot
vary  for  differing  cash  flows)
\$principal  =  present  value  of  an  annuity,  or  current  principal  of  a
loan  used  in  the  PaymentCalc  function

*/

//  present  value  of  an  Annuity
//  uses  include  defining  Remaining  Principal  of  a  loan/mortgage

FUNCTION  PVannuity  (\$m,\$n,\$R,\$pmt)  {

\$Z  =  1  /  (1  +  (\$R/\$m));
RETURN  (\$pmt  *  \$Z  *  (1  -  POW(\$Z,\$n)))/(1  -  \$Z);

}

//  Given  the  compounding,  principal,  interest  rate,  you  can  calculate
the  monthly  payment

FUNCTION  PaymentCalc  (\$m,\$n,\$R,\$principal)  {

\$Z  =  1  /  (1  +  (\$R/\$m));
RETURN  ((1  -  \$Z)  *  \$principal)  /  (\$Z  *  (1  -  POW(\$Z,\$n)));

}

//  future  value  of  an  Annuity

FUNCTION  FVannuity  (\$m,\$n,\$R,\$pmt)  {

RETURN  \$pmt  *  ((POW((1  +  \$R/\$n),\$m)  -  1)/(\$R/\$n));

}

//  present  value  of  a  single  payment

FUNCTION  PVsingle  (\$m,\$n,\$R,\$pmt)  {

RETURN  \$pmt  *  POW((1  +  \$R/\$m),-\$n);

}

//  future  value  of  a  single  payment

FUNCTION  FVsingle  (\$m,\$n,\$R,\$pmt)  {

RETURN  \$pmt  *  POW((1  +  \$R/\$m),\$n);

}

//  future  value  of  a  single  payment  with  continuous  compounding

FUNCTION  FVperp  (\$m,\$n,\$R,\$pmt)  {

RETURN  \$pmt  *  EXP(\$R  *  (\$n/\$m));

}

?>
```