Exemplo n.º 1
0
        public FuturesRateHelper(double price,
                                 Date iborStartDate,
                                 Date iborEndDate,
                                 DayCounter dayCounter,
                                 double convAdj    = 0,
                                 Futures.Type type = Futures.Type.IMM)
            : base(price)
        {
            convAdj_ = new Handle <Quote>(new SimpleQuote(convAdj));

            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 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_;
        }
Exemplo n.º 2
0
        public void testASXDates()
        {
            //Testing ASX dates...");

            String[] ASXcodes =
            {
                "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 asx;

            while (counter <= last)
            {
                asx = ASX.nextDate(counter, false);

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

                // check that asx is an ASX date
                if (!ASX.isASXdate(asx, false))
                {
                    QAssert.Fail(asx.weekday() + " " + asx
                                 + " is not an ASX date (calculated from "
                                 + counter.weekday() + " " + counter + ")");
                }

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


                // check that for every date ASXdate is the inverse of ASXcode
                if (ASX.date(ASX.code(asx), counter) != asx)
                {
                    QAssert.Fail(ASX.code(asx)
                                 + " at calendar day " + counter
                                 + " is not the ASX code matching " + asx);
                }

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

                counter = counter + 1;
            }
        }