package com.imsl.test.example.finance; import com.imsl.finance.*; import java.text.*; import java.util.*; /** *

* Computes the net present value for a schedule of payments.

* * In this example, the present value of 3 payments, $1,000, $2,000, and $1,000, * with an interest rate of 5% made on January 3, 1997, January 3, 1999, and * January 3, 2000 is computed. * * * * @see Code * @see Output */ public class FinanceXnpvEx1 { static final DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, Locale.US); private static Date parse(String s) throws ParseException { return dateFormat.parse(s); } public static void main(String args[]) throws ParseException { double rate = 0.05; double value[] = {1000., 2000., 1000.}; Date dates[] = {parse("1/3/1997"), parse("1/3/1999"), parse("1/3/2000")}; double pv = Finance.xnpv(rate, value, dates); System.out.println("The present value of the schedule of cash " + "flows is " + NumberFormat.getCurrencyInstance().format(pv)); } }