Example: Present Value of a Schedule of Cash Flows

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.
using System;
using Imsl.Finance;

public class xnpvEx1
{
    public static void  Main(String[] args)
    {
        double rate = 0.05;
        double[] value_Renamed = new double[]{1000.0, 2000.0, 1000.0};
        System.DateTime[] dates = 
            new System.DateTime[]{DateTime.Parse("1/3/1997"), 
                                     DateTime.Parse("1/3/1999"), 
                                     DateTime.Parse("1/3/2000")};
        
        double pv = Finance.Xnpv(rate, value_Renamed, dates);
        Console.Out.WriteLine("The present value of the schedule of " +
                              "cash flows is " + pv.ToString("C"));
    }
}

Output

The present value of the schedule of cash flows is $3,677.90

Link to C# source.