| px | top | add code | search | signup | login | help |
<?php
/*
by William Lucking (will@ahnet.net) of Affinity Hosting, LLC, offering
low cost hosting providing UNIX accounts supporting PHP3, PHP2, and mySQL
(no telnet access).
We are always hiring PHP programmers in the Los Angeles area, full and
part-time.
This suite offers many financial management functions that can be
used (but not limited) for a web based mortgage or loan calculator.
Need some Financial Management training:
http://www.duke.edu/~charvey/Classes/ba350_1997/preassignment/preassign.htm
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));
}
?>
Comments or questions?
PX is running PHP 5.2.11
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.