I am doing a TVM project and not quite understand how the compound interest translates into code. I am using BA II Plus financial calculator as a reference.
Example: Find the future value of $100 payments made at the beginning of every month for 10 years if interest is 5% compounded quarterly.
In the financial calculator:
N: 120 (10y x 12m)
I/Y: 5% (annually interest rate)
P/Y: 12 (12 times per year)
C/Y: 4 (4 times per year)
PV: 0
PMT: 100
BGN: TRUE
FV: [CPT] [FV] => -15575.41334
Here is the future value method.
static public double fv(double r, int n, double pmt, double pv, int bgn) {
return -(pv * Math.pow(1 + r, n) + pmt * (1 + r * bgn) * (Math.pow(1 + r, n) - 1) / r);
}
Call the method using numbers from the example
// rate n pmt pv bgn
double fv = fv(0.05/12, 120, 100, 0, 1); // -15592.928894335751 which is wrong