コード例 #1
0
    public static void Example4()
    {
        DateTime startDate = new Date(2009, 8, 3).DateValue;
        DateTime endDate   = new Date(2014, 10, 3).DateValue;

        // Now test with bool as well
        bool         adjusted       = true;
        int          paymentPerYear = 2;
        bool         arrears        = false;
        int          fixingDays     = -2;
        bool         shortPeriod    = true;
        DateSchedule myDL_1         = new DateSchedule(startDate, endDate, paymentPerYear, shortPeriod, adjusted, arrears, fixingDays);

        Console.WriteLine("Marix<Date> GetLongScheduleDate()");
        myDL_1.PrintDateMatrix(myDL_1.GetLongScheduleDate());
        Console.WriteLine();
        Console.WriteLine("Matrix<double> GetLongScheduleSerial()");
        myDL_1.GetLongScheduleSerial().extendedPrint();
        Console.WriteLine();
        Console.WriteLine("Marix<Date> GetShortScheduleDate()");
        myDL_1.PrintDateMatrix(myDL_1.GetShortScheduleDate());
        Console.WriteLine();
        Console.WriteLine("Array<Date>PaymentDateArray()");
        myDL_1.PrintDateArray(myDL_1.PaymentDateArray());
        Console.WriteLine();
        Console.WriteLine("count numbers of rows: public int Length " + myDL_1.Length);
    }
コード例 #2
0
    public static void Example10()
    {
        // I will pay 5% quarterly 30/360 for 5y starting from 5 Oct 09 on a nominal of 1.000.000 USD. I want to see
        // interest rates cash flows
        // input data
        Date   startDate        = new Date(2009, 10, 5);
        Date   endDate          = startDate.AddYears(5);
        int    paymentPerYear   = 4; // Quarterly
        bool   firstShortPeriod = true;
        double rate             = 0.05;

        // I use standard constructor
        DateSchedule myDS = new DateSchedule(startDate, endDate, paymentPerYear, firstShortPeriod);

        // I get start and end date schedule
        NumericMatrix <Date> myShortSchedule = myDS.GetShortScheduleDate();

        // my nominals
        Array <double> nominals = new Array <double>(myShortSchedule.Rows, 0, 1000000);

        // year fraction from/to according 30/360
        Array <double> yearFractions = new Array <double>(myShortSchedule.Rows, 0);

        // days from/to according 30/360
        Array <double> days = new Array <double>(myShortSchedule.Rows, 0);

        // interest to pay
        Array <double> interest = new Array <double>(myShortSchedule.Rows, 0);

        Console.WriteLine("{0},\t{1},\t{2},\t{3},\t{4}", "days", "yearFrac", "rate",
                          "nominals", "interest");

        // running sum
        double totalInterest = 0.0;

        // iterate interest calculation using schedule
        for (int i = 0; i < myShortSchedule.Rows; i++)
        {
            yearFractions[i] = myShortSchedule[i, 0].YF_30_360(myShortSchedule[i, 1]);
            days[i]          = myShortSchedule[i, 0].D_30_360(myShortSchedule[i, 1]);
            interest[i]      = yearFractions[i] * rate * nominals[i];

            Console.WriteLine("{0},\t{1:F5},\t{2:P},\t{3:C},\t{4:C}", days[i], yearFractions[i], rate,
                              nominals[i], interest[i]);
            totalInterest += interest[i];
        }

        Console.WriteLine("{0},\t{1:F2}", "Total interests: ", totalInterest);
    }