calculate amortized RATE not payment for mortgage
Posted: Sun Apr 22, 2012 2:22 pm
hi
with this code i get an amortized, principal and interest payment calculation:
amount: $100,000
term: 30 (years)
rate: 5%
payment: UNKNOWN
solve for payment ...
payment: $536.82 PI
but if i have this:
amount: $100,000
term: 30 (years)
rate: UNKNOWN
payment: $536.82 PI
how do i write the code to find the RATE?
TIA
with this code i get an amortized, principal and interest payment calculation:
amount: $100,000
term: 30 (years)
rate: 5%
payment: UNKNOWN
solve for payment ...
Code: Select all
// initialize variables
$sale_price = 0;
$annual_interest_percent = 0;
$year_term = 0;
//This function does the actual mortgage calculations by plotting a PVIFA (Present Value Interest Factor of Annuity) table...
function get_interest_factor($year_term, $monthly_interest_rate) {
global $base_rate;
$factor = 0;
$base_rate = 1 + $monthly_interest_rate;
$denominator = $base_rate;
for ($i=0; $i < ($year_term * 12); $i++) {
$factor += (1 / $denominator);
$denominator *= $base_rate;
}
return $factor;
}
// crunch the numbers
$month_term = $year_term * 12;
$annual_interest_rate = $annual_interest_percent / 100;
$monthly_interest_rate = $annual_interest_rate / 12;
$financing_price = $sale_price;
$monthly_factor = get_interest_factor($year_term, $monthly_interest_rate);
$monthly_payment = $financing_price / $monthly_factor;
but if i have this:
amount: $100,000
term: 30 (years)
rate: UNKNOWN
payment: $536.82 PI
how do i write the code to find the RATE?
TIA