Beispiel #1
0
        //! returns whether or not the given date is an ASX date
        public static bool isASXdate(Date date, bool mainCycle = true)
        {
            if (date.weekday() != (int)DayOfWeek.Friday + 1)
            {
                return(false);
            }

            int d = date.Day;

            if (d < 8 || d > 14)
            {
                return(false);
            }

            if (!mainCycle)
            {
                return(true);
            }

            switch ((Month)date.month())
            {
            case Month.March:
            case Month.June:
            case Month.September:
            case Month.December:
                return(true);

            default:
                return(false);
            }
        }
Beispiel #2
0
        public static Date previousWednesday(Date date)
        {
            int w = date.weekday();

            if (w >= 4) // roll back w-4 days
            {
                return(date - new Period((w - 4), TimeUnit.Days));
            }
            else // roll forward 4-w days and back one week
            {
                return(date + new Period((4 - w - 7), TimeUnit.Days));
            }
        }
Beispiel #3
0
        protected override void initializeDates()
        {
            earliestDate_ = calendar_.advance(evaluationDate_, new Period(settlementDays_, TimeUnit.Days),
                                              BusinessDayConvention.Following);

            Date maturity = earliestDate_ + tenor_;

            // dummy BMA index with curve/swap arguments
            BMAIndex clonedIndex = new BMAIndex(termStructureHandle_);

            Schedule bmaSchedule = new MakeSchedule().from(earliestDate_).to(maturity)
                                   .withTenor(bmaPeriod_)
                                   .withCalendar(bmaIndex_.fixingCalendar())
                                   .withConvention(bmaConvention_)
                                   .backwards()
                                   .value();

            Schedule liborSchedule = new MakeSchedule().from(earliestDate_).to(maturity)
                                     .withTenor(iborIndex_.tenor())
                                     .withCalendar(iborIndex_.fixingCalendar())
                                     .withConvention(iborIndex_.businessDayConvention())
                                     .endOfMonth(iborIndex_.endOfMonth())
                                     .backwards()
                                     .value();

            swap_ = new BMASwap(BMASwap.Type.Payer, 100.0, liborSchedule, 0.75,             // arbitrary
                                0.0, iborIndex_, iborIndex_.dayCounter(), bmaSchedule, clonedIndex, bmaDayCount_);
            swap_.setPricingEngine(new DiscountingSwapEngine(iborIndex_.forwardingTermStructure()));

            Date d             = calendar_.adjust(swap_.maturityDate(), BusinessDayConvention.Following);
            int  w             = d.weekday();
            Date nextWednesday = (w >= 4) ? d + new Period((11 - w), TimeUnit.Days) :
                                 d + new Period((4 - w), TimeUnit.Days);

            latestDate_ = clonedIndex.valueDate(clonedIndex.fixingCalendar().adjust(nextWednesday));
        }
Beispiel #4
0
        public void testConsistency()
        {
            //("Testing dates...");

             int minDate = Date.minDate().serialNumber() + 1,
                    maxDate = Date.maxDate().serialNumber();

             int dyold = new Date(minDate - 1).DayOfYear,
             dold = new Date(minDate - 1).Day,
             mold = new Date(minDate - 1).Month,
             yold = new Date(minDate - 1).Year,
             wdold = new Date(minDate - 1).weekday();

             for (int i = minDate; i <= maxDate; i++)
             {
            Date t = new Date(i);
            int serial = t.serialNumber();

            // check serial number consistency
            if (serial != i)
               Assert.Fail("inconsistent serial number:\n"
                          + "    original:      " + i + "\n"
                          + "    date:          " + t + "\n"
                          + "    serial number: " + serial);

            int dy = t.DayOfYear,
                d = t.Day,
                m = t.Month,
                y = t.Year,
                wd = t.weekday();

            // check if skipping any date
            if (!((dy == dyold + 1) ||
                  (dy == 1 && dyold == 365 && !Date.IsLeapYear(yold)) ||
                  (dy == 1 && dyold == 366 && Date.IsLeapYear(yold))))
               Assert.Fail("wrong day of year increment: \n"
                          + "    date: " + t + "\n"
                          + "    day of year: " + dy + "\n"
                          + "    previous:    " + dyold);
            dyold = dy;

            if (!((d == dold + 1 && m == mold && y == yold) ||
                  (d == 1 && m == mold + 1 && y == yold) ||
                  (d == 1 && m == 1 && y == yold + 1)))
               Assert.Fail("wrong day,month,year increment: \n"
                          + "    date: " + t + "\n"
                          + "    day,month,year: "
                          + d + "," + m + "," + y + "\n"
                          + "    previous:       "
                          + dold + "," + mold + "," + yold);
            dold = d; mold = m; yold = y;

            // check month definition
            if (m < 1 || m > 12)
               Assert.Fail("invalid month: \n"
                          + "    date:  " + t + "\n"
                          + "    month: " + m);

            // check day definition
            if (d < 1)
               Assert.Fail("invalid day of month: \n"
                          + "    date:  " + t + "\n"
                          + "    day: " + d);
            if (!((m == 1 && d <= 31) ||
                  (m == 2 && d <= 28) ||
                  (m == 2 && d == 29 && Date.IsLeapYear(y)) ||
                  (m == 3 && d <= 31) ||
                  (m == 4 && d <= 30) ||
                  (m == 5 && d <= 31) ||
                  (m == 6 && d <= 30) ||
                  (m == 7 && d <= 31) ||
                  (m == 8 && d <= 31) ||
                  (m == 9 && d <= 30) ||
                  (m == 10 && d <= 31) ||
                  (m == 11 && d <= 30) ||
                  (m == 12 && d <= 31)))
               Assert.Fail("invalid day of month: \n"
                          + "    date:  " + t + "\n"
                          + "    day: " + d);

            // check weekday definition
            if (!((wd == wdold + 1) ||
                  (wd == 1 && wdold == 7)))
               Assert.Fail("invalid weekday: \n"
                          + "    date:  " + t + "\n"
                          + "    weekday:  " + wd + "\n"
                          + "    previous: " + wdold);
            wdold = wd;

            // create the same date with a different constructor
            Date s = new Date(d, m, y);
            // check serial number consistency
            serial = s.serialNumber();
            if (serial != i)
               Assert.Fail("inconsistent serial number:\n"
                          + "    date:          " + t + "\n"
                          + "    serial number: " + i + "\n"
                          + "    cloned date:   " + s + "\n"
                          + "    serial number: " + serial);
             }
        }
Beispiel #5
0
 public static Date previousWednesday(Date date) {
     int w = date.weekday();
     if (w >= 4) // roll back w-4 days
         return date - new Period((w - 4), TimeUnit.Days);
     else // roll forward 4-w days and back one week
         return date + new Period((4 - w - 7), TimeUnit.Days);
 }