Its been ages since my last post, but thought I’d share a class I used in a recent job, that involved building a Annuity Calculator in Flex.
Really straight-forward…it consists of two methods, one returning PMT (installment amount), and the other PV (Present Value).
We pass the Interest Rate (IR), Present Value (PV) and Repayment Term to the calculatePMT() method and return the PMT, and the other way round…we pass the Monthly Installment (PMT), Interest Rate (IR) and Repayment-Term to the calculateBond() method, to return the Present Value(PV).
I hope this helps somebody, as I couldn’t find many recourses out there for Annuity Calculators and ActionScript….ENJOY!!!
package customclasses {
public class PmtCalc {
public function calculatePMT(PV:Number, IR:Number, YEARS:Number):Number {
var newIR:Number = IR/12;
var newNP:Number = YEARS*12;
return Math.round((PV*(newIR/100)) / (1-Math.pow(1+(newIR/100), -newNP)));
}
public function calculateBond(PMT:Number, IR:Number, YEARS:Number):Number {
var newIRb:Number = (IR/100)/12;
var newNPb:Number = YEARS*12;
var v:Number = Math.pow(1+newIRb, -newNPb);
var pv:Number = PMT*(1-v)/newIRb;
return Math.round(pv);
}
}
}
Entries (RSS)