Esempio n. 1
0
        public void testYYIndex()
        {
            // Testing year-on-year inflation indices

            SavedSettings backup = new SavedSettings();
            //IndexHistoryCleaner cleaner = new IndexHistoryCleaner();

            YYEUHICP yyeuhicp = new YYEUHICP(true);

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

            YYEUHICPr yyeuhicpr = new YYEUHICPr(true);

            if (yyeuhicpr.name() != "EU YYR_HICP" ||
                yyeuhicpr.frequency() != Frequency.Monthly ||
                yyeuhicpr.revised() ||
                !yyeuhicpr.interpolated() ||
                !yyeuhicpr.ratio() ||
                yyeuhicpr.availabilityLag() != new Period(1, TimeUnit.Months))
            {
                Assert.Fail("wrong year-on-year EU HICPr data ("
                            + yyeuhicpr.name() + ", "
                            + yyeuhicpr.frequency() + ", "
                            + yyeuhicpr.revised() + ", "
                            + yyeuhicpr.interpolated() + ", "
                            + yyeuhicpr.ratio() + ", "
                            + yyeuhicpr.availabilityLag() + ")");
            }

            YYUKRPI yyukrpi = new YYUKRPI(false);

            if (yyukrpi.name() != "UK YY_RPI" ||
                yyukrpi.frequency() != Frequency.Monthly ||
                yyukrpi.revised() ||
                yyukrpi.interpolated() ||
                yyukrpi.ratio() ||
                yyukrpi.availabilityLag() != new Period(1, TimeUnit.Months))
            {
                Assert.Fail("wrong year-on-year UK RPI data ("
                            + yyukrpi.name() + ", "
                            + yyukrpi.frequency() + ", "
                            + yyukrpi.revised() + ", "
                            + yyukrpi.interpolated() + ", "
                            + yyukrpi.ratio() + ", "
                            + yyukrpi.availabilityLag() + ")");
            }

            YYUKRPIr yyukrpir = new YYUKRPIr(false);

            if (yyukrpir.name() != "UK YYR_RPI" ||
                yyukrpir.frequency() != Frequency.Monthly ||
                yyukrpir.revised() ||
                yyukrpir.interpolated() ||
                !yyukrpir.ratio() ||
                yyukrpir.availabilityLag() != new Period(1, TimeUnit.Months))
            {
                Assert.Fail("wrong year-on-year UK RPIr data ("
                            + yyukrpir.name() + ", "
                            + yyukrpir.frequency() + ", "
                            + yyukrpir.revised() + ", "
                            + yyukrpir.interpolated() + ", "
                            + yyukrpir.ratio() + ", "
                            + yyukrpir.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 };

            bool     interp = false;
            YYUKRPIr iir    = new YYUKRPIr(interp);
            YYUKRPIr iirYES = new YYUKRPIr(true);

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

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

            todayMinusLag = lim0.Value + 1 - 2 * new Period(iir.frequency());

            double eps = 1.0e-8;

            // Interpolation tests
            //--------------------
            // (no TS so can't forecast).
            for (int i = 13; i < rpiSchedule.Count; i++)
            {
                KeyValuePair <Date, Date> lim    = Utils.inflationPeriod(rpiSchedule[i], iir.frequency());
                KeyValuePair <Date, Date> limBef = Utils.inflationPeriod(rpiSchedule[i - 12], iir.frequency());
                for (Date d = lim.Key; d <= lim.Value; d++)
                {
                    if (d < todayMinusLag)
                    {
                        double expected   = fixData[i] / fixData[i - 12] - 1.0;
                        double calculated = iir.fixing(d);
                        Assert.IsTrue(Math.Abs(calculated - expected) < eps,
                                      "Non-interpolated fixings not constant within a period: "
                                      + calculated
                                      + ", should be "
                                      + expected);

                        double dp    = lim.Value + 1 - lim.Key;
                        double dpBef = limBef.Value + 1 - limBef.Key;
                        double dl    = d - lim.Key;
                        // potentially does not work on 29th Feb
                        double dlBef = new NullCalendar().advance(d, -new Period(1, TimeUnit.Years),
                                                                  BusinessDayConvention.ModifiedFollowing) - limBef.Key;

                        double linearNow     = fixData[i] + (fixData[i + 1] - fixData[i]) * dl / dp;
                        double linearBef     = fixData[i - 12] + (fixData[i + 1 - 12] - fixData[i - 12]) * dlBef / dpBef;
                        double expectedYES   = linearNow / linearBef - 1.0;
                        double calculatedYES = iirYES.fixing(d);
                        Assert.IsTrue(Math.Abs(expectedYES - calculatedYES) < eps,
                                      "Error in interpolated fixings: expect " + expectedYES
                                      + " see " + calculatedYES
                                      + " flat " + calculated
                                      + ", data: " + fixData[i - 12] + ", " + fixData[i + 1 - 12]
                                      + ", " + fixData[i] + ", " + fixData[i + 1]
                                      + ", fac: " + dp + ", " + dl
                                      + ", " + dpBef + ", " + dlBef
                                      + ", to: " + linearNow + ", " + linearBef
                                      );
                    }
                }
            }
        }
Esempio n. 2
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(YYEUHICP obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
Esempio n. 3
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(YYEUHICP obj) {
   return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
 }