Наследование: QLNet.ZeroInflationIndex
Пример #1
0
        public void testZeroIndex()
        {
            // Testing zero inflation indices...
             EUHICP euhicp = new EUHICP(true);

             if (euhicp.name() != "EU HICP"
             || euhicp.frequency() != Frequency.Monthly
             || euhicp.revised()
             || !euhicp.interpolated()
             || euhicp.availabilityLag() != new Period(1, TimeUnit.Months))
             {
            Assert.Fail("wrong EU HICP data ("
                        + euhicp.name() + ", "
                        + euhicp.frequency() + ", "
                        + euhicp.revised() + ", "
                        + euhicp.interpolated() + ", "
                        + euhicp.availabilityLag() + ")");
             }

             UKRPI ukrpi = new UKRPI(false);
             if (ukrpi.name() != "UK RPI"
             || ukrpi.frequency() != Frequency.Monthly
             || ukrpi.revised()
             || ukrpi.interpolated()
             || ukrpi.availabilityLag() != new Period(1, TimeUnit.Months))
             {
            Assert.Fail("wrong UK RPI data ("
                        + ukrpi.name() + ", "
                        + ukrpi.frequency() + ", "
                        + ukrpi.revised() + ", "
                        + ukrpi.interpolated() + ", "
                        + ukrpi.availabilityLag() + ")");
             }

             // Retrieval test.
             //----------------
             // make sure of the evaluation date
             Date evaluationDate = new Date(13, Month.August, 2007);
             evaluationDate = new UnitedKingdom().adjust(evaluationDate);
             Settings.setEvaluationDate(evaluationDate);

             // fixing data
             Date from = new Date(1, Month.January, 2005);
             Date to = new Date(13, Month.August, 2007);
             Schedule rpiSchedule = new MakeSchedule().from(from).to(to)
                                .withTenor(new Period(1, TimeUnit.Months))
                                .withCalendar(new UnitedKingdom())
                                .withConvention(BusinessDayConvention.ModifiedFollowing)
                                .value();

             double[] fixData = { 189.9, 189.9, 189.6, 190.5, 191.6, 192.0,
                              192.2, 192.2, 192.6, 193.1, 193.3, 193.6,
                              194.1, 193.4, 194.2, 195.0, 196.5, 197.7,
                              198.5, 198.5, 199.2, 200.1, 200.4, 201.1,
                              202.7, 201.6, 203.1, 204.4, 205.4, 206.2,
                              207.3, 206.1, -999.0 };

             bool interp = false;
             UKRPI iir = new UKRPI(interp);

             for (int i = 0; i < rpiSchedule.Count - 1; i++)
             {
            iir.addFixing(rpiSchedule[i], fixData[i]);
             }

             Date todayMinusLag = evaluationDate - iir.availabilityLag();
             KeyValuePair<Date, Date> lim1 = Utils.inflationPeriod(todayMinusLag, iir.frequency());
             todayMinusLag = lim1.Key;

             double eps = 1.0e-8;

             // -1 because last value not yet available,
             // (no TS so can't forecast).
             for (int i = 0; i < rpiSchedule.Count - 1; i++)
             {
            KeyValuePair<Date, Date> lim = Utils.inflationPeriod(rpiSchedule[i],
                                                   iir.frequency());
            for (Date d = lim.Key; d <= lim.Value; d++)
            {
               if (d < Utils.inflationPeriod(todayMinusLag, iir.frequency()).Key)
               {
                  if (Math.Abs(iir.fixing(d) - fixData[i]) > eps)
                     Assert.Fail("Fixings not constant within a period: "
                                 + iir.fixing(d)
                                 + ", should be " + fixData[i]);
               }
            }
             }
        }