예제 #1
0
        public void testIMMDates()
        {
            // ("Testing IMM dates...");

            string[] IMMcodes = new string[] {
                "F0", "G0", "H0", "J0", "K0", "M0", "N0", "Q0", "U0", "V0", "X0", "Z0",
                "F1", "G1", "H1", "J1", "K1", "M1", "N1", "Q1", "U1", "V1", "X1", "Z1",
                "F2", "G2", "H2", "J2", "K2", "M2", "N2", "Q2", "U2", "V2", "X2", "Z2",
                "F3", "G3", "H3", "J3", "K3", "M3", "N3", "Q3", "U3", "V3", "X3", "Z3",
                "F4", "G4", "H4", "J4", "K4", "M4", "N4", "Q4", "U4", "V4", "X4", "Z4",
                "F5", "G5", "H5", "J5", "K5", "M5", "N5", "Q5", "U5", "V5", "X5", "Z5",
                "F6", "G6", "H6", "J6", "K6", "M6", "N6", "Q6", "U6", "V6", "X6", "Z6",
                "F7", "G7", "H7", "J7", "K7", "M7", "N7", "Q7", "U7", "V7", "X7", "Z7",
                "F8", "G8", "H8", "J8", "K8", "M8", "N8", "Q8", "U8", "V8", "X8", "Z8",
                "F9", "G9", "H9", "J9", "K9", "M9", "N9", "Q9", "U9", "V9", "X9", "Z9"
            };

            Date counter = Date.minDate();
            // 10 years of futures must not exceed Date::maxDate
            Date last = Date.maxDate() - new Period(121, TimeUnit.Months);
            Date imm;

            while (counter <= last)
            {
                imm = IMM.nextDate(counter, false);

                // check that imm is greater than counter
                if (imm <= counter)
                {
                    QAssert.Fail(imm.DayOfWeek + " " + imm
                                 + " is not greater than "
                                 + counter.DayOfWeek + " " + counter);
                }

                // check that imm is an IMM date
                if (!IMM.isIMMdate(imm, false))
                {
                    QAssert.Fail(imm.DayOfWeek + " " + imm
                                 + " is not an IMM date (calculated from "
                                 + counter.DayOfWeek + " " + counter + ")");
                }

                // check that imm is <= to the next IMM date in the main cycle
                if (imm > IMM.nextDate(counter, true))
                {
                    QAssert.Fail(imm.DayOfWeek + " " + imm
                                 + " is not less than or equal to the next future in the main cycle "
                                 + IMM.nextDate(counter, true));
                }

                //// check that if counter is an IMM date, then imm==counter
                //if (IMM::isIMMdate(counter, false) && (imm!=counter))
                //    BOOST_FAIL("\n  "
                //               << counter.weekday() << " " << counter
                //               << " is already an IMM date, while nextIMM() returns "
                //               << imm.weekday() << " " << imm);

                // check that for every date IMMdate is the inverse of IMMcode
                if (IMM.date(IMM.code(imm), counter) != imm)
                {
                    QAssert.Fail(IMM.code(imm)
                                 + " at calendar day " + counter
                                 + " is not the IMM code matching " + imm);
                }

                // check that for every date the 120 IMM codes refer to future dates
                for (int i = 0; i < 40; ++i)
                {
                    if (IMM.date(IMMcodes[i], counter) < counter)
                    {
                        QAssert.Fail(IMM.date(IMMcodes[i], counter)
                                     + " is wrong for " + IMMcodes[i]
                                     + " at reference date " + counter);
                    }
                }

                counter = counter + 1;
            }
        }
예제 #2
0
        public FuturesRateHelper(Handle <Quote> price,
                                 Date iborStartDate,
                                 Date iborEndDate,
                                 DayCounter dayCounter,
                                 Handle <Quote> convAdj = null,
                                 Futures.Type type      = Futures.Type.IMM)
            : base(price)
        {
            convAdj_ = convAdj ?? new Handle <Quote>();

            switch (type)
            {
            case Futures.Type.IMM:
                Utils.QL_REQUIRE(IMM.isIMMdate(iborStartDate, false), () =>
                                 iborStartDate + " is not a valid IMM date");
                if (iborEndDate == null)
                {
                    // advance 3 months
                    maturityDate_ = IMM.nextDate(iborStartDate, false);
                    maturityDate_ = IMM.nextDate(maturityDate_, false);
                    maturityDate_ = IMM.nextDate(maturityDate_, false);
                }
                else
                {
                    Utils.QL_REQUIRE(iborEndDate > iborStartDate, () =>
                                     "end date (" + iborEndDate +
                                     ") must be greater than start date (" +
                                     iborStartDate + ")");
                    maturityDate_ = iborEndDate;
                }
                break;

            case QLNet.Futures.Type.ASX:
                Utils.QL_REQUIRE(ASX.isASXdate(iborStartDate, false), () =>
                                 iborStartDate + " is not a valid ASX date");
                if (iborEndDate == null)
                {
                    // advance 3 months
                    maturityDate_ = ASX.nextDate(iborStartDate, false);
                    maturityDate_ = ASX.nextDate(maturityDate_, false);
                    maturityDate_ = ASX.nextDate(maturityDate_, false);
                }
                else
                {
                    Utils.QL_REQUIRE(iborEndDate > iborStartDate, () =>
                                     "end date (" + iborEndDate +
                                     ") must be greater than start date (" +
                                     iborStartDate + ")");
                    maturityDate_ = iborEndDate;
                }
                break;

            default:
                Utils.QL_FAIL("unknown futures type (" + type + ")");
                break;
            }
            earliestDate_ = iborStartDate;
            yearFraction_ = dayCounter.yearFraction(earliestDate_, maturityDate_);
            pillarDate_   = latestDate_ = latestRelevantDate_ = maturityDate_;

            convAdj_.registerWith(update);
        }