Mega Code Archive

 
Categories / Php / Algorithms
 

A suite of financial management functions including present and future

value of an annuity and a loan payment calculation function <?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)); } ?>