Example: Number of Periods for an Investment
Someone obtains a $20,000 loan at 7.25% to buy a car. They want to make $350 a month payments. Here, the number of payments necessary to pay off the loan is computed.
import com.imsl.finance.*;
import java.text.NumberFormat;
public class nperEx1 {
public static void main(String args[]) {
double rate = 0.0725/12;
double pmt = -350.;
double pv = 20000;
double fv = 0.;
int when = Finance.AT_BEGINNING_OF_PERIOD;
double nperiods;
nperiods = Finance.nper(rate, pmt, pv, fv, when);
System.out.println("Number of payment periods = " +nperiods);
}
}
Output
Number of payment periods = 69.78051136628257
Link to Java source.