Esempio n. 1
0
        //-------------------------------------------------------------------------
        public virtual void test_cloned()
        {
            InflationRateSensitivity @base = InflationRateSensitivity.of(GB_HICP_OBS, 3.5);
            InflationRateSensitivity test  = @base.cloned();

            assertSame(test, @base);
        }
Esempio n. 2
0
        //-------------------------------------------------------------------------
        public virtual void test_build()
        {
            InflationRateSensitivity @base = InflationRateSensitivity.of(GB_HICP_OBS, 3.5);
            PointSensitivities       test  = @base.build();

            assertEquals(test.Sensitivities, ImmutableList.of(@base));
        }
Esempio n. 3
0
        //-------------------------------------------------------------------------
        // proper end-to-end tests are elsewhere
        public virtual void test_parameterSensitivity()
        {
            SimplePriceIndexValues   test  = SimplePriceIndexValues.of(US_CPI_U, VAL_DATE, CURVE_NOFIX, USCPI_TS);
            InflationRateSensitivity point = InflationRateSensitivity.of(PriceIndexObservation.of(US_CPI_U, VAL_MONTH.plusMonths(3)), 1d);

            assertEquals(test.parameterSensitivity(point).size(), 1);
        }
Esempio n. 4
0
        //-------------------------------------------------------------------------
        public virtual void test_withSensitivity()
        {
            InflationRateSensitivity @base    = InflationRateSensitivity.of(CH_CPI_OBS, 3.5);
            InflationRateSensitivity expected = InflationRateSensitivity.of(CH_CPI_OBS, 23.4);
            InflationRateSensitivity test     = @base.withSensitivity(23.4);

            assertEquals(test, expected);
        }
Esempio n. 5
0
        //-------------------------------------------------------------------------
        public virtual void test_mapSensitivity()
        {
            InflationRateSensitivity @base    = InflationRateSensitivity.of(CH_CPI_OBS, 5.0);
            InflationRateSensitivity expected = InflationRateSensitivity.of(CH_CPI_OBS, 1.0 / 5.0);
            InflationRateSensitivity test     = @base.mapSensitivity(s => 1 / s);

            assertEquals(test, expected);
        }
Esempio n. 6
0
        //-------------------------------------------------------------------------
        public virtual void test_multipliedBy()
        {
            InflationRateSensitivity @base    = InflationRateSensitivity.of(CH_CPI_OBS, 5.0);
            InflationRateSensitivity expected = InflationRateSensitivity.of(CH_CPI_OBS, 2.6 * 5.0);
            InflationRateSensitivity test     = @base.multipliedBy(2.6d);

            assertEquals(test, expected);
        }
Esempio n. 7
0
        //-------------------------------------------------------------------------
        public virtual void test_buildInto()
        {
            InflationRateSensitivity  @base = InflationRateSensitivity.of(GB_HICP_OBS, 3.5);
            MutablePointSensitivities combo = new MutablePointSensitivities();
            MutablePointSensitivities test  = @base.buildInto(combo);

            assertEquals(test, combo);
            assertEquals(test.Sensitivities, ImmutableList.of(@base));
        }
Esempio n. 8
0
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            InflationRateSensitivity test1 = InflationRateSensitivity.of(GB_HICP_OBS, 1.0);

            coverImmutableBean(test1);
            InflationRateSensitivity test2 = InflationRateSensitivity.of(GB_HICP_OBS, GBP, 22.0);

            coverBeanEquals(test1, test2);
        }
Esempio n. 9
0
        public virtual void test_valuePointSensitivity_forward()
        {
            YearMonth month = VAL_MONTH.plusMonths(3);
            SimplePriceIndexValues   test     = SimplePriceIndexValues.of(US_CPI_U, VAL_DATE, CURVE_NOFIX, USCPI_TS);
            PriceIndexObservation    obs      = PriceIndexObservation.of(US_CPI_U, month);
            InflationRateSensitivity expected = InflationRateSensitivity.of(obs, 1d);

            assertEquals(test.valuePointSensitivity(obs), expected);
        }
Esempio n. 10
0
        public virtual void test_of_withCurrency()
        {
            InflationRateSensitivity test = InflationRateSensitivity.of(CH_CPI_OBS, GBP, 3.5);

            assertEquals(test.Index, CH_CPI);
            assertEquals(test.Currency, GBP);
            assertEquals(test.Observation, CH_CPI_OBS);
            assertEquals(test.Sensitivity, 3.5);
        }
Esempio n. 11
0
        public virtual void test_of_withoutCurrency()
        {
            InflationRateSensitivity test = InflationRateSensitivity.of(GB_HICP_OBS, 1.0);

            assertEquals(test.Index, GB_HICP);
            assertEquals(test.Currency, GB_HICP.Currency);
            assertEquals(test.Observation, GB_HICP_OBS);
            assertEquals(test.Sensitivity, 1.0);
        }
Esempio n. 12
0
        //-------------------------------------------------------------------------
        public virtual void test_withCurrency()
        {
            InflationRateSensitivity @base = InflationRateSensitivity.of(CH_CPI_OBS, 3.5);

            assertEquals(@base.withCurrency(CHF), @base);
            InflationRateSensitivity expected = InflationRateSensitivity.of(CH_CPI_OBS, USD, 3.5);
            InflationRateSensitivity test     = @base.withCurrency(USD);

            assertEquals(test, expected);
        }
Esempio n. 13
0
        public virtual void test_combinedWith_mutable()
        {
            InflationRateSensitivity  @base    = InflationRateSensitivity.of(CH_CPI_OBS, 5.0);
            MutablePointSensitivities expected = new MutablePointSensitivities();

            expected.add(@base);
            PointSensitivityBuilder test = @base.combinedWith(new MutablePointSensitivities());

            assertEquals(test, expected);
        }
Esempio n. 14
0
        //-------------------------------------------------------------------------
        public virtual void test_combinedWith()
        {
            InflationRateSensitivity  base1    = InflationRateSensitivity.of(CH_CPI_OBS, 5.0);
            InflationRateSensitivity  base2    = InflationRateSensitivity.of(CH_CPI_OBS, 7.0);
            MutablePointSensitivities expected = new MutablePointSensitivities();

            expected.add(base1).add(base2);
            PointSensitivityBuilder test = base1.combinedWith(base2);

            assertEquals(test, expected);
        }
        //-------------------------------------------------------------------------
        public PointSensitivityBuilder valuePointSensitivity(PriceIndexObservation observation)
        {
            YearMonth fixingMonth = observation.FixingMonth;

            // If fixing in the past, check time series and returns the historic month price index if present
            if (fixingMonth.isBefore(YearMonth.from(valuationDate)))
            {
                if (fixings.get(fixingMonth.atEndOfMonth()).HasValue)
                {
                    return(PointSensitivityBuilder.none());
                }
            }
            return(InflationRateSensitivity.of(observation, 1d));
        }
Esempio n. 16
0
        //-------------------------------------------------------------------------
        public virtual void test_convertedTo()
        {
            double sensi = 32d;
            InflationRateSensitivity @base = InflationRateSensitivity.of(GB_HICP_OBS, sensi);
            double   rate   = 1.5d;
            FxMatrix matrix = FxMatrix.of(CurrencyPair.of(GBP, USD), rate);
            InflationRateSensitivity test1    = (InflationRateSensitivity)@base.convertedTo(USD, matrix);
            InflationRateSensitivity expected = InflationRateSensitivity.of(GB_HICP_OBS, USD, sensi * rate);

            assertEquals(test1, expected);
            InflationRateSensitivity test2 = (InflationRateSensitivity)@base.convertedTo(GBP, matrix);

            assertEquals(test2, @base);
        }
Esempio n. 17
0
 public virtual void test_value_pts_sensitivity_futfixing()
 {
     for (int i = 0; i < TEST_MONTHS.Length; i++)
     {
         PointSensitivityBuilder ptsComputed = INSTANCE_WITH_FUTFIXING.valuePointSensitivity(TEST_OBS[i]);
         YearMonth fixingMonth = TEST_OBS[i].FixingMonth;
         PointSensitivityBuilder ptsExpected;
         if (fixingMonth.isBefore(YearMonth.from(VAL_DATE_2)) && USCPI_TS.containsDate(fixingMonth.atEndOfMonth()))
         {
             ptsExpected = PointSensitivityBuilder.none();
         }
         else
         {
             ptsExpected = InflationRateSensitivity.of(TEST_OBS[i], 1d);
         }
         assertTrue(ptsComputed.build().equalWithTolerance(ptsExpected.build(), TOLERANCE_VALUE), "test " + i);
     }
 }
Esempio n. 18
0
        //-------------------------------------------------------------------------
        public virtual void test_compareKey()
        {
            InflationRateSensitivity a1    = InflationRateSensitivity.of(GB_HICP_OBS, 32d);
            InflationRateSensitivity a2    = InflationRateSensitivity.of(GB_HICP_OBS, 32d);
            InflationRateSensitivity b     = InflationRateSensitivity.of(CH_CPI_OBS, 32d);
            InflationRateSensitivity c     = InflationRateSensitivity.of(GB_HICP_OBS, USD, 32d);
            InflationRateSensitivity d     = InflationRateSensitivity.of(PriceIndexObservation.of(GB_HICP, YearMonth.of(2015, 10)), 32d);
            ZeroRateSensitivity      other = ZeroRateSensitivity.of(GBP, 2d, 32d);

            assertEquals(a1.compareKey(a2), 0);
            assertEquals(a1.compareKey(b) > 0, true);
            assertEquals(b.compareKey(a1) < 0, true);
            assertEquals(a1.compareKey(c) < 0, true);
            assertEquals(c.compareKey(a1) > 0, true);
            assertEquals(a1.compareKey(d) < 0, true);
            assertEquals(d.compareKey(a1) > 0, true);
            assertEquals(a1.compareKey(other) < 0, true);
            assertEquals(other.compareKey(a1) > 0, true);
        }
        public virtual void pointAndParameterPriceIndex()
        {
            double                 eps           = 1.0e-13;
            LocalDate              valuationDate = LocalDate.of(2014, 1, 22);
            DoubleArray            x             = DoubleArray.of(0.5, 1.0, 2.0);
            DoubleArray            y             = DoubleArray.of(224.2, 262.6, 277.5);
            CurveInterpolator      interp        = CurveInterpolators.NATURAL_CUBIC_SPLINE;
            string                 curveName     = "GB_RPI_CURVE";
            InterpolatedNodalCurve interpCurve   = InterpolatedNodalCurve.of(Curves.prices(curveName), x, y, interp);
            ImmutableRatesProvider provider      = ImmutableRatesProvider.builder(VAL_DATE).priceIndexCurve(GB_RPI, interpCurve).timeSeries(GB_RPI, LocalDateDoubleTimeSeries.of(date(2013, 11, 30), 200)).build();

            double    pointSensiValue = 2.5;
            YearMonth refMonth        = YearMonth.from(valuationDate.plusMonths(9));
            InflationRateSensitivity       pointSensi = InflationRateSensitivity.of(PriceIndexObservation.of(GB_RPI, refMonth), pointSensiValue);
            CurrencyParameterSensitivities computed   = provider.parameterSensitivity(pointSensi.build());
            DoubleArray sensiComputed = computed.Sensitivities.get(0).Sensitivity;

            InflationRateSensitivity pointSensi1 = InflationRateSensitivity.of(PriceIndexObservation.of(GB_RPI, refMonth), 1);
            DoubleArray sensiExpectedUnit        = provider.priceIndexValues(GB_RPI).parameterSensitivity(pointSensi1).Sensitivities.get(0).Sensitivity;

            assertTrue(sensiComputed.equalWithTolerance(sensiExpectedUnit.multipliedBy(pointSensiValue), eps));
        }
Esempio n. 20
0
 public virtual void test_value_parameter_sensitivity_futfixing()
 {
     for (int i = 0; i < TEST_MONTHS.Length; i++)
     {
         YearMonth fixingMonth = TEST_OBS[i].FixingMonth;
         if (!fixingMonth.isBefore(YearMonth.from(VAL_DATE_2)) && !USCPI_TS.containsDate(fixingMonth.atEndOfMonth()))
         {
             InflationRateSensitivity       ptsExpected = (InflationRateSensitivity)InflationRateSensitivity.of(TEST_OBS[i], 1d);
             CurrencyParameterSensitivities psComputed  = INSTANCE_WITH_FUTFIXING.parameterSensitivity(ptsExpected);
             double x = YearMonth.from(VAL_DATE_2).until(fixingMonth, MONTHS);
             UnitParameterSensitivities     sens1      = UnitParameterSensitivities.of(CURVE_INFL2.yValueParameterSensitivity(x));
             CurrencyParameterSensitivities psExpected = sens1.multipliedBy(ptsExpected.Currency, ptsExpected.Sensitivity);
             assertTrue(psComputed.equalWithTolerance(psExpected, TOLERANCE_DELTA), "test " + i);
         }
     }
 }
Esempio n. 21
0
        public virtual void test_serialization()
        {
            InflationRateSensitivity test = InflationRateSensitivity.of(GB_HICP_OBS, 1.0);

            assertSerialization(test);
        }