Пример #1
0
        private ImmutableRatesProvider createProvider(double rateStart, double rateStartInterp, double rateEnd, double rateEndInterp)
        {
            LocalDateDoubleTimeSeries timeSeries = LocalDateDoubleTimeSeries.of(VAL_DATE.with(lastDayOfMonth()), 300);
            InterpolatedNodalCurve    curve      = InterpolatedNodalCurve.of(Curves.prices("GB-RPIX"), DoubleArray.of(4, 5, 16, 17), DoubleArray.of(rateStart, rateStartInterp, rateEnd, rateEndInterp), INTERPOLATOR);

            return(ImmutableRatesProvider.builder(VAL_DATE).priceIndexCurve(GB_RPIX, curve).timeSeries(GB_RPIX, timeSeries).build());
        }
Пример #2
0
        public virtual void test_rate()
        {
            SimpleRatesProvider       prov       = new SimpleRatesProvider();
            LocalDateDoubleTimeSeries timeSeries = LocalDateDoubleTimeSeries.of(FIXING_DATE, RATE);
            IborIndexRates            mockIbor   = new TestingIborIndexRates(GBP_LIBOR_3M, FIXING_DATE, LocalDateDoubleTimeSeries.empty(), timeSeries);

            prov.IborRates = mockIbor;

            ForwardIborRateComputationFn obsFn = ForwardIborRateComputationFn.DEFAULT;

            assertEquals(obsFn.rate(GBP_LIBOR_3M_COMP, ACCRUAL_START_DATE, ACCRUAL_END_DATE, prov), RATE);

            // explain
            ExplainMapBuilder builder = ExplainMap.builder();

            assertEquals(obsFn.explainRate(GBP_LIBOR_3M_COMP, ACCRUAL_START_DATE, ACCRUAL_END_DATE, prov, builder), RATE);

            ExplainMap built = builder.build();

            assertEquals(built.get(ExplainKey.OBSERVATIONS).Present, true);
            assertEquals(built.get(ExplainKey.OBSERVATIONS).get().size(), 1);
            assertEquals(built.get(ExplainKey.OBSERVATIONS).get().get(0).get(ExplainKey.FIXING_DATE), FIXING_DATE);
            assertEquals(built.get(ExplainKey.OBSERVATIONS).get().get(0).get(ExplainKey.INDEX), GBP_LIBOR_3M);
            assertEquals(built.get(ExplainKey.OBSERVATIONS).get().get(0).get(ExplainKey.INDEX_VALUE), RATE);
            assertEquals(built.get(ExplainKey.OBSERVATIONS).get().get(0).get(ExplainKey.FROM_FIXING_SERIES), true);
            assertEquals(built.get(ExplainKey.OBSERVATIONS).get().get(0).get(ExplainKey.FORWARD_RATE_START_DATE), FORWARD_START_DATE);
            assertEquals(built.get(ExplainKey.OBSERVATIONS).get().get(0).get(ExplainKey.FORWARD_RATE_END_DATE), FORWARD_END_DATE);
            assertEquals(built.get(ExplainKey.COMBINED_RATE), RATE);
        }
 public TestingIborIndexRates(IborIndex index, LocalDate valuationDate, LocalDateDoubleTimeSeries rates, LocalDateDoubleTimeSeries fixings, IborRateSensitivity sens)
 {
     this.index         = index;
     this.valuationDate = valuationDate;
     this.rates         = rates;
     this.fixings       = fixings;
     this.sens          = sens;
 }
        //-------------------------------------------------------------------------
        public virtual void test_fxIndexRates()
        {
            LocalDateDoubleTimeSeries ts   = LocalDateDoubleTimeSeries.of(VAL_DATE, 0.62d);
            ImmutableRatesProvider    test = ImmutableRatesProvider.builder(VAL_DATE).fxRateProvider(FX_MATRIX).discountCurve(GBP, DISCOUNT_CURVE_GBP).discountCurve(USD, DISCOUNT_CURVE_USD).timeSeries(GBP_USD_WM, ts).build();

            assertEquals(test.fxIndexRates(GBP_USD_WM).Index, GBP_USD_WM);
            assertEquals(test.fxIndexRates(GBP_USD_WM).Fixings, ts);
            assertEquals(test.TimeSeriesIndices, ImmutableSet.of(GBP_USD_WM));
        }
        //-------------------------------------------------------------------------
        public virtual void test_builder()
        {
            LocalDateDoubleTimeSeries ts   = LocalDateDoubleTimeSeries.of(PREV_DATE, 0.62d);
            ImmutableRatesProvider    test = ImmutableRatesProvider.builder(VAL_DATE).timeSeries(GBP_USD_WM, ts).build();

            assertEquals(test.ValuationDate, VAL_DATE);
            assertEquals(ImmutableRatesProvider.meta().timeSeries().get(test), ImmutableMap.of(GBP_USD_WM, ts));
            assertSame(test.toImmutableRatesProvider(), test);
        }
        //-------------------------------------------------------------------------
        public virtual void test_overnightIndexRates()
        {
            LocalDateDoubleTimeSeries ts   = LocalDateDoubleTimeSeries.of(VAL_DATE, 0.62d);
            ImmutableRatesProvider    test = ImmutableRatesProvider.builder(VAL_DATE).overnightIndexCurve(USD_FED_FUND, FED_FUND_CURVE).timeSeries(USD_FED_FUND, ts).build();

            assertEquals(test.overnightIndexRates(USD_FED_FUND).Index, USD_FED_FUND);
            assertEquals(test.overnightIndexRates(USD_FED_FUND).Fixings, ts);
            assertEquals(test.OvernightIndices, ImmutableSet.of(USD_FED_FUND));
            assertEquals(test.TimeSeriesIndices, ImmutableSet.of(USD_FED_FUND));
        }
        //-------------------------------------------------------------------------
        public virtual void test_iborIndexRates()
        {
            LocalDateDoubleTimeSeries ts   = LocalDateDoubleTimeSeries.of(VAL_DATE, 0.62d);
            ImmutableRatesProvider    test = ImmutableRatesProvider.builder(VAL_DATE).iborIndexCurve(USD_LIBOR_3M, USD_LIBOR_CURVE).timeSeries(USD_LIBOR_3M, ts).build();

            assertEquals(test.iborIndexRates(USD_LIBOR_3M).Index, USD_LIBOR_3M);
            assertEquals(test.iborIndexRates(USD_LIBOR_3M).Fixings, ts);
            assertEquals(test.IborIndices, ImmutableSet.of(USD_LIBOR_3M));
            assertEquals(test.TimeSeriesIndices, ImmutableSet.of(USD_LIBOR_3M));
        }
        static ForwardOvernightAveragedDailyRateComputationFnTest()
        {
            LocalDateDoubleTimeSeriesBuilder builder = LocalDateDoubleTimeSeries.builder();

            for (int i = 0; i < FIXING_DATES.Length; ++i)
            {
                builder.put(FIXING_DATES[i], FIXING_RATES[i]);
            }
            TIME_SERIES = builder.build();
        }
        //-------------------------------------------------------------------------
        public virtual void test_priceIndexValues()
        {
            LocalDateDoubleTimeSeries ts   = LocalDateDoubleTimeSeries.of(VAL_DATE, 0.62d);
            ImmutableRatesProvider    test = ImmutableRatesProvider.builder(VAL_DATE).priceIndexCurve(GB_RPI, GBPRI_CURVE).timeSeries(GB_RPI, ts).build();

            assertEquals(test.priceIndexValues(GB_RPI).Index, GB_RPI);
            assertEquals(test.priceIndexValues(GB_RPI).Fixings, ts);
            assertEquals(test.PriceIndices, ImmutableSet.of(GB_RPI));
            assertEquals(test.TimeSeriesIndices, ImmutableSet.of(GB_RPI));
        }
Пример #10
0
        static SimplePriceIndexValuesTest()
        {
            LocalDateDoubleTimeSeriesBuilder builder = LocalDateDoubleTimeSeries.builder();

            for (int i = 0; i < USCPI_VALUES.Length; i++)
            {
                builder.put(USCPI_START_DATE.plusMonths(i), USCPI_VALUES[i]);
            }
            USCPI_TS = builder.build();
            for (int i = 0; i < TEST_MONTHS.Length; i++)
            {
                TEST_OBS[i] = PriceIndexObservation.of(US_CPI_U, TEST_MONTHS[i]);
            }
        }
        public virtual void test_periodRatePointSensitivity_onholidaybeforepublication()
        {
            LocalDate lastFixingDate             = LocalDate.of(2017, 6, 30);
            LocalDate gbdBeforeValDate           = LocalDate.of(2017, 7, 3);
            LocalDate gbdAfterValDate            = LocalDate.of(2017, 7, 5);
            double    fixingValue                = 0.0010;
            InterpolatedNodalCurve      curve    = InterpolatedNodalCurve.of(METADATA, DoubleArray.of(-1.0d, 10.0d), DoubleArray.of(0.01, 0.02), INTERPOLATOR);
            ZeroRateDiscountFactors     df       = ZeroRateDiscountFactors.of(USD, LocalDate.of(2017, 7, 4), curve);
            LocalDateDoubleTimeSeries   series   = LocalDateDoubleTimeSeries.builder().put(lastFixingDate, fixingValue).build();
            DiscountOvernightIndexRates test     = DiscountOvernightIndexRates.of(USD_FED_FUND, df, series);
            OvernightIndexObservation   obs      = OvernightIndexObservation.of(USD_FED_FUND, gbdBeforeValDate, REF_DATA);
            OvernightRateSensitivity    expected = OvernightRateSensitivity.ofPeriod(obs, gbdAfterValDate, USD, 1d);

            assertEquals(test.periodRatePointSensitivity(obs, gbdAfterValDate), expected);
        }
Пример #12
0
        static ImmutableRatesProviderSimpleData()
        {
            CurveInterpolator      interp     = CurveInterpolators.DOUBLE_QUADRATIC;
            DoubleArray            time_eur   = DoubleArray.of(0.0, 0.1, 0.25, 0.5, 0.75, 1.0, 2.0);
            DoubleArray            rate_eur   = DoubleArray.of(0.0160, 0.0165, 0.0155, 0.0155, 0.0155, 0.0150, 0.0140);
            InterpolatedNodalCurve dscCurve   = InterpolatedNodalCurve.of(Curves.zeroRates("EUR-Discount", ACT_365F), time_eur, rate_eur, interp);
            DoubleArray            time_index = DoubleArray.of(0.0, 0.25, 0.5, 1.0);
            DoubleArray            rate_index = DoubleArray.of(0.0180, 0.0180, 0.0175, 0.0165);
            InterpolatedNodalCurve indexCurve = InterpolatedNodalCurve.of(Curves.zeroRates("EUR-EURIBOR6M", ACT_365F), time_index, rate_index, interp);

            IMM_PROV_EUR_NOFIX = ImmutableRatesProvider.builder(VAL_DATE).discountCurve(EUR, dscCurve).iborIndexCurve(EUR_EURIBOR_6M, indexCurve).build();
            LocalDateDoubleTimeSeries tsE6 = LocalDateDoubleTimeSeries.builder().put(VAL_DATE, 0.012345).build();

            IMM_PROV_EUR_FIX = ImmutableRatesProvider.builder(VAL_DATE).discountCurve(EUR, dscCurve).iborIndexCurve(EUR_EURIBOR_6M, indexCurve, tsE6).build();
        }
        /// <summary>
        /// Obtains time series of price index up to valuation date.
        /// </summary>
        /// <param name="valuationDate">  the valuation date </param>
        /// <returns> the time series </returns>
        public static LocalDateDoubleTimeSeries getTimeSeries(LocalDate valuationDate)
        {
            LocalDate[] dates  = new LocalDate[] { LocalDate.of(2005, 1, 31), LocalDate.of(2005, 2, 28), LocalDate.of(2005, 3, 31), LocalDate.of(2005, 4, 30), LocalDate.of(2005, 5, 31), LocalDate.of(2005, 6, 30), LocalDate.of(2005, 7, 31), LocalDate.of(2005, 8, 31), LocalDate.of(2005, 9, 30), LocalDate.of(2005, 10, 31), LocalDate.of(2005, 11, 30), LocalDate.of(2005, 12, 31), LocalDate.of(2006, 1, 31), LocalDate.of(2006, 2, 28), LocalDate.of(2006, 3, 31), LocalDate.of(2006, 4, 30), LocalDate.of(2006, 5, 31), LocalDate.of(2006, 6, 30), LocalDate.of(2006, 7, 31), LocalDate.of(2006, 8, 31), LocalDate.of(2006, 9, 30), LocalDate.of(2006, 10, 31), LocalDate.of(2006, 11, 30), LocalDate.of(2006, 12, 31), LocalDate.of(2007, 1, 31), LocalDate.of(2007, 2, 28), LocalDate.of(2007, 3, 31), LocalDate.of(2007, 4, 30), LocalDate.of(2007, 5, 31), LocalDate.of(2007, 6, 30), LocalDate.of(2007, 7, 31), LocalDate.of(2007, 8, 31), LocalDate.of(2007, 9, 30), LocalDate.of(2007, 10, 31), LocalDate.of(2007, 11, 30), LocalDate.of(2007, 12, 31), LocalDate.of(2008, 1, 31), LocalDate.of(2008, 2, 29), LocalDate.of(2008, 3, 31), LocalDate.of(2008, 4, 30), LocalDate.of(2008, 5, 31), LocalDate.of(2008, 6, 30), LocalDate.of(2008, 7, 31), LocalDate.of(2008, 8, 31), LocalDate.of(2008, 9, 30), LocalDate.of(2008, 10, 31), LocalDate.of(2008, 11, 30), LocalDate.of(2008, 12, 31), LocalDate.of(2009, 1, 31), LocalDate.of(2009, 2, 28), LocalDate.of(2009, 3, 31), LocalDate.of(2009, 4, 30), LocalDate.of(2009, 5, 31), LocalDate.of(2009, 6, 30), LocalDate.of(2009, 7, 31), LocalDate.of(2009, 8, 31), LocalDate.of(2009, 9, 30), LocalDate.of(2009, 10, 31), LocalDate.of(2009, 11, 30), LocalDate.of(2009, 12, 31), LocalDate.of(2010, 1, 31), LocalDate.of(2010, 2, 28), LocalDate.of(2010, 3, 31), LocalDate.of(2010, 4, 30), LocalDate.of(2010, 5, 31), LocalDate.of(2010, 6, 30), LocalDate.of(2010, 7, 31), LocalDate.of(2010, 8, 31), LocalDate.of(2010, 9, 30), LocalDate.of(2010, 10, 31), LocalDate.of(2010, 11, 30), LocalDate.of(2010, 12, 31), LocalDate.of(2011, 1, 31), LocalDate.of(2011, 2, 28), LocalDate.of(2011, 3, 31), LocalDate.of(2011, 4, 30), LocalDate.of(2011, 5, 31), LocalDate.of(2011, 6, 30), LocalDate.of(2011, 7, 31), LocalDate.of(2011, 8, 31), LocalDate.of(2011, 9, 30), LocalDate.of(2011, 10, 31), LocalDate.of(2011, 11, 30), LocalDate.of(2011, 12, 31), LocalDate.of(2012, 1, 31), LocalDate.of(2012, 2, 29), LocalDate.of(2012, 3, 31), LocalDate.of(2012, 4, 30), LocalDate.of(2012, 5, 31), LocalDate.of(2012, 6, 30), LocalDate.of(2012, 7, 31), LocalDate.of(2012, 8, 31), LocalDate.of(2012, 9, 30), LocalDate.of(2012, 10, 31), LocalDate.of(2012, 11, 30), LocalDate.of(2012, 12, 31), LocalDate.of(2013, 1, 31), LocalDate.of(2013, 2, 28), LocalDate.of(2013, 3, 31), LocalDate.of(2013, 4, 30), LocalDate.of(2013, 5, 31), LocalDate.of(2013, 6, 30), LocalDate.of(2013, 7, 31), LocalDate.of(2013, 8, 31), LocalDate.of(2013, 9, 30), LocalDate.of(2013, 10, 31), LocalDate.of(2013, 11, 30), LocalDate.of(2013, 12, 31), LocalDate.of(2014, 1, 31), LocalDate.of(2014, 2, 28), LocalDate.of(2014, 3, 31), LocalDate.of(2014, 4, 30), LocalDate.of(2014, 5, 31), LocalDate.of(2014, 6, 30), LocalDate.of(2014, 7, 31), LocalDate.of(2014, 8, 31), LocalDate.of(2014, 9, 30), LocalDate.of(2014, 10, 31), LocalDate.of(2014, 11, 30), LocalDate.of(2014, 12, 31), LocalDate.of(2015, 1, 31), LocalDate.of(2015, 2, 28), LocalDate.of(2015, 3, 31), LocalDate.of(2015, 4, 30), LocalDate.of(2015, 5, 31), LocalDate.of(2015, 6, 30), LocalDate.of(2015, 7, 31), LocalDate.of(2015, 8, 31), LocalDate.of(2015, 9, 30), LocalDate.of(2015, 10, 31), LocalDate.of(2015, 11, 30), LocalDate.of(2015, 12, 31), LocalDate.of(2016, 1, 31) };
            double[]    values = new double[] { 211.143, 212.193, 212.709, 213.24, 213.856, 215.693, 215.351, 215.834, 215.969, 216.177, 216.33, 215.949, 211.143, 212.193, 212.709, 213.24, 213.856, 215.693, 215.351, 215.834, 215.969, 216.177, 216.33, 215.949, 211.143, 212.193, 212.709, 213.24, 213.856, 215.693, 215.351, 215.834, 215.969, 216.177, 216.33, 215.949, 211.143, 212.193, 212.709, 213.24, 213.856, 215.693, 215.351, 215.834, 215.969, 216.177, 216.33, 215.949, 211.143, 212.193, 212.709, 213.24, 213.856, 215.693, 215.351, 215.834, 215.969, 216.177, 216.33, 215.949, 216.687, 216.741, 217.631, 218.009, 218.178, 217.965, 218.011, 218.312, 218.439, 218.711, 218.803, 219.179, 220.223, 221.309, 223.467, 224.906, 225.964, 225.722, 225.922, 226.545, 226.889, 226.421, 226.23, 225.672, 226.655, 227.663, 229.392, 230.085, 229.815, 229.478, 229.104, 230.379, 231.407, 231.317, 230.221, 229.601, 230.28, 232.166, 232.773, 232.531, 232.945, 233.504, 233.596, 233.877, 234.149, 233.546, 233.069, 233.049, 233.916, 234.781, 236.293, 237.072, 237.9, 238.343, 238.25, 237.852, 238.031, 237.433, 236.151, 234.812, 233.707, 234.722, 236.119, 236.599, 237.805, 238.638, 238.654, 238.316, 237.945, 237.838, 237.336, 236.525, 236.916 };
            LocalDateDoubleTimeSeriesBuilder builder = LocalDateDoubleTimeSeries.builder();

            for (int i = 0; i < values.Length; ++i)
            {
                if (dates[i].isBefore(valuationDate))
                {
                    builder.put(dates[i], values[i]);
                }
            }
            return(builder.build());
        }
        /// <summary>
        /// Obtains time series of price index up to valuation date.
        /// </summary>
        /// <param name="valuationDate">  the valuation date </param>
        /// <returns> the time series </returns>
        public static LocalDateDoubleTimeSeries getTimeSeriesJp(LocalDate valuationDate)
        {
            LocalDate[] dates  = new LocalDate[] { LocalDate.of(2013, 1, 31), LocalDate.of(2013, 2, 28), LocalDate.of(2013, 3, 31), LocalDate.of(2013, 4, 30), LocalDate.of(2013, 5, 31), LocalDate.of(2013, 6, 30), LocalDate.of(2013, 7, 31), LocalDate.of(2013, 8, 31), LocalDate.of(2013, 9, 30), LocalDate.of(2013, 10, 31), LocalDate.of(2013, 11, 30), LocalDate.of(2013, 12, 31), LocalDate.of(2014, 1, 31), LocalDate.of(2014, 2, 28), LocalDate.of(2014, 3, 31), LocalDate.of(2014, 4, 30), LocalDate.of(2014, 5, 31), LocalDate.of(2014, 6, 30), LocalDate.of(2014, 7, 31), LocalDate.of(2014, 8, 31), LocalDate.of(2014, 9, 30), LocalDate.of(2014, 10, 31), LocalDate.of(2014, 11, 30), LocalDate.of(2014, 12, 31), LocalDate.of(2015, 1, 31), LocalDate.of(2015, 2, 28), LocalDate.of(2015, 3, 31), LocalDate.of(2015, 4, 30), LocalDate.of(2015, 5, 31), LocalDate.of(2015, 6, 30), LocalDate.of(2015, 7, 31), LocalDate.of(2015, 8, 31), LocalDate.of(2015, 9, 30), LocalDate.of(2015, 10, 31), LocalDate.of(2015, 11, 30), LocalDate.of(2015, 12, 31), LocalDate.of(2016, 1, 31) };
            double[]    values = new double[] { 99.1, 99.2, 99.5, 99.8, 100, 100, 100.1, 100.4, 100.5, 100.7, 100.7, 100.6, 100.4, 100.5, 100.8, 103, 103.4, 103.4, 103.5, 103.5, 103.5, 103.6, 103.4, 103.2, 102.6, 102.5, 103, 103.3, 103.4, 103.4, 103.4, 103.4, 103.4, 103.5, 103.4, 103.3 };

            LocalDateDoubleTimeSeriesBuilder builder = LocalDateDoubleTimeSeries.builder();

            for (int i = 0; i < values.Length; ++i)
            {
                if (dates[i].isBefore(valuationDate))
                {
                    builder.put(dates[i], values[i]);
                }
            }
            return(builder.build());
        }
        /// <summary>
        /// Obtains time series of price index up to valuation date.
        /// </summary>
        /// <param name="valuationDate">  the valuation date </param>
        /// <returns> the time series </returns>
        public static LocalDateDoubleTimeSeries getTimeSeriesGb(LocalDate valuationDate)
        {
            LocalDate[] dates  = new LocalDate[] { LocalDate.of(2015, 1, 31), LocalDate.of(2015, 2, 28), LocalDate.of(2015, 3, 31), LocalDate.of(2015, 4, 30), LocalDate.of(2015, 5, 31), LocalDate.of(2015, 6, 30), LocalDate.of(2015, 7, 31), LocalDate.of(2015, 8, 31), LocalDate.of(2015, 9, 30), LocalDate.of(2015, 10, 31), LocalDate.of(2015, 11, 30), LocalDate.of(2015, 12, 31), LocalDate.of(2016, 1, 31) };
            double[]    values = new double[] { 255.4, 256.7, 257.1, 258.0, 258.5, 258.9, 258.6, 259.8, 259.6, 259.5, 259.8, 260.6, 258.8 };

            LocalDateDoubleTimeSeriesBuilder builder = LocalDateDoubleTimeSeries.builder();

            for (int i = 0; i < values.Length; ++i)
            {
                if (dates[i].isBefore(valuationDate))
                {
                    builder.put(dates[i], values[i]);
                }
            }
            return(builder.build());
        }
        public virtual void test_rate()
        {
            RatesProvider             mockProv    = mock(typeof(RatesProvider));
            LocalDateDoubleTimeSeries timeSeries  = LocalDateDoubleTimeSeries.of(FIXING_DATE, RATE3TS);
            IborIndexRates            mockRates3M = new TestingIborIndexRates(GBP_LIBOR_3M, FIXING_DATE, LocalDateDoubleTimeSeries.empty(), timeSeries);
            IborIndexRates            mockRates6M = new TestingIborIndexRates(GBP_LIBOR_6M, FIXING_DATE, LocalDateDoubleTimeSeries.of(FIXING_DATE, RATE6), LocalDateDoubleTimeSeries.empty());

            when(mockProv.iborIndexRates(GBP_LIBOR_3M)).thenReturn(mockRates3M);
            when(mockProv.iborIndexRates(GBP_LIBOR_6M)).thenReturn(mockRates6M);

            IborInterpolatedRateComputation          ro  = IborInterpolatedRateComputation.of(GBP_LIBOR_3M, GBP_LIBOR_6M, FIXING_DATE, REF_DATA);
            ForwardIborInterpolatedRateComputationFn obs = ForwardIborInterpolatedRateComputationFn.DEFAULT;
            LocalDate fixingEndDate3M = GBP_LIBOR_3M_OBS.MaturityDate;
            LocalDate fixingEndDate6M = GBP_LIBOR_6M_OBS.MaturityDate;
            double    days3M          = fixingEndDate3M.toEpochDay() - FIXING_DATE.toEpochDay(); //nb days in 3M fixing period
            double    days6M          = fixingEndDate6M.toEpochDay() - FIXING_DATE.toEpochDay(); //nb days in 6M fixing period
            double    daysCpn         = ACCRUAL_END_DATE.toEpochDay() - FIXING_DATE.toEpochDay();
            double    weight3M        = (days6M - daysCpn) / (days6M - days3M);
            double    weight6M        = (daysCpn - days3M) / (days6M - days3M);
            double    rateExpected    = (weight3M * RATE3TS + weight6M * RATE6);
            double    rateComputed    = obs.rate(ro, ACCRUAL_START_DATE, ACCRUAL_END_DATE, mockProv);

            assertEquals(rateComputed, rateExpected, TOLERANCE_RATE);

            // explain
            ExplainMapBuilder builder = ExplainMap.builder();

            assertEquals(obs.explainRate(ro, ACCRUAL_START_DATE, ACCRUAL_END_DATE, mockProv, builder), rateExpected, TOLERANCE_RATE);

            ExplainMap built = builder.build();

            assertEquals(built.get(ExplainKey.OBSERVATIONS).Present, true);
            assertEquals(built.get(ExplainKey.OBSERVATIONS).get().size(), 2);
            assertEquals(built.get(ExplainKey.OBSERVATIONS).get().get(0).get(ExplainKey.FIXING_DATE), FIXING_DATE);
            assertEquals(built.get(ExplainKey.OBSERVATIONS).get().get(0).get(ExplainKey.INDEX), GBP_LIBOR_3M);
            assertEquals(built.get(ExplainKey.OBSERVATIONS).get().get(0).get(ExplainKey.INDEX_VALUE), RATE3TS);
            assertEquals(built.get(ExplainKey.OBSERVATIONS).get().get(0).get(ExplainKey.WEIGHT), weight3M);
            assertEquals(built.get(ExplainKey.OBSERVATIONS).get().get(0).get(ExplainKey.FROM_FIXING_SERIES), true);
            assertEquals(built.get(ExplainKey.OBSERVATIONS).get().get(1).get(ExplainKey.FIXING_DATE), FIXING_DATE);
            assertEquals(built.get(ExplainKey.OBSERVATIONS).get().get(1).get(ExplainKey.INDEX), GBP_LIBOR_6M);
            assertEquals(built.get(ExplainKey.OBSERVATIONS).get().get(1).get(ExplainKey.INDEX_VALUE), RATE6);
            assertEquals(built.get(ExplainKey.OBSERVATIONS).get().get(1).get(ExplainKey.WEIGHT), weight6M);
            assertEquals(built.get(ExplainKey.OBSERVATIONS).get().get(1).get(ExplainKey.FROM_FIXING_SERIES), null);
            assertEquals(built.get(ExplainKey.COMBINED_RATE), rateExpected);
        }
        public virtual void test_combinedWith()
        {
            LocalDateDoubleTimeSeries timeSeries1 = LocalDateDoubleTimeSeries.builder().put(date(2011, 3, 8), 1).put(date(2011, 3, 9), 2).put(date(2011, 3, 10), 3).build();

            LocalDateDoubleTimeSeries timeSeries2 = LocalDateDoubleTimeSeries.builder().put(date(2011, 3, 8), 10).put(date(2011, 3, 9), 20).put(date(2011, 3, 10), 30).build();

            LocalDateDoubleTimeSeries timeSeries2a = LocalDateDoubleTimeSeries.builder().put(date(2011, 3, 8), 1000).put(date(2011, 3, 9), 2000).put(date(2011, 3, 10), 3000).build();

            LocalDateDoubleTimeSeries timeSeries3 = LocalDateDoubleTimeSeries.builder().put(date(2011, 3, 8), 100).put(date(2011, 3, 9), 200).put(date(2011, 3, 10), 300).build();

            ImmutableScenarioMarketData marketData1 = ImmutableScenarioMarketData.builder(LocalDate.of(2011, 3, 8)).addTimeSeries(TEST_ID1, timeSeries1).addTimeSeries(TEST_ID2, timeSeries2).addBox(TEST_ID1, MarketDataBox.ofScenarioValues(1.0, 1.1, 1.2)).addBox(TEST_ID2, MarketDataBox.ofScenarioValues(2.0, 2.1, 2.2)).build();

            ImmutableScenarioMarketData marketData2 = ImmutableScenarioMarketData.builder(LocalDate.of(2011, 3, 10)).addTimeSeries(TEST_ID2, timeSeries2a).addTimeSeries(TEST_ID3, timeSeries3).addBox(TEST_ID2, MarketDataBox.ofScenarioValues(21.0, 21.1, 21.2)).addBox(TEST_ID3, MarketDataBox.ofScenarioValues(3.0, 3.1, 3.2)).build();

            // marketData1 values should be in the combined data when the same ID is present in both
            ImmutableScenarioMarketData expected = ImmutableScenarioMarketData.builder(LocalDate.of(2011, 3, 8)).addTimeSeries(TEST_ID1, timeSeries1).addTimeSeries(TEST_ID2, timeSeries2).addTimeSeries(TEST_ID3, timeSeries3).addBox(TEST_ID1, MarketDataBox.ofScenarioValues(1.0, 1.1, 1.2)).addBox(TEST_ID2, MarketDataBox.ofScenarioValues(2.0, 2.1, 2.2)).addBox(TEST_ID3, MarketDataBox.ofScenarioValues(3.0, 3.1, 3.2)).build();

            ScenarioMarketData combined = marketData1.combinedWith(marketData2);

            assertThat(combined).isEqualTo(expected);
            assertThat(combined.Ids).isEqualTo(ImmutableSet.of(TEST_ID1, TEST_ID2, TEST_ID3));
        }
        public virtual void test_currentCash_onPaymentDate()
        {
            LocalDate              paymentDate   = RFRA.PaymentDate;
            double                 publishedRate = 0.025;
            ResolvedFraTrade       trade         = FraTrade.builder().info(TradeInfo.builder().tradeDate(paymentDate).build()).product(FRA).build().resolve(REF_DATA);
            ImmutableRatesProvider ratesProvider = RatesProviderDataSets.multiGbp(paymentDate).toBuilder().timeSeries(GBP_LIBOR_3M, LocalDateDoubleTimeSeries.of(paymentDate, publishedRate)).build();

            assertEquals(PRICER_TRADE.currentCash(trade, ratesProvider), CurrencyAmount.of(FRA.Currency, (publishedRate - FRA.FixedRate) / (1d + publishedRate * RFRA.YearFraction) * RFRA.YearFraction * RFRA.Notional));
        }
 /// <summary>
 /// Create a yield curve bundle with three curves.
 /// One called "Discounting EUR" with a constant rate of 2.50%, one called "Discounting USD"
 /// with a constant rate of 1.00% and one called "Discounting GBP" with a constant rate of 2.00%;
 /// "Discounting KRW" with a constant rate of 3.21%;
 /// </summary>
 /// <param name="valuationDate">  the valuation date </param>
 /// <param name="fxIndex">  the FX index </param>
 /// <param name="spotRate">  the spot rate for the index </param>
 /// <returns> the provider </returns>
 public static RatesProvider createProvider(LocalDate valuationDate, FxIndex fxIndex, double spotRate)
 {
     return(ImmutableRatesProvider.builder(valuationDate).discountCurve(EUR, EUR_DSC).discountCurve(USD, USD_DSC).discountCurve(GBP, GBP_DSC).discountCurve(KRW, KRW_DSC).fxRateProvider(FX_MATRIX).timeSeries(fxIndex, LocalDateDoubleTimeSeries.of(fxIndex.calculateFixingFromMaturity(valuationDate, REF_DATA), spotRate)).build());
 }
 /// <summary>
 /// Creates rates provider with specified valuation date and time series of the index.
 /// </summary>
 /// <param name="valuationDate">  the valuation date </param>
 /// <param name="index">  the index </param>
 /// <param name="timeSeries">  the time series </param>
 /// <returns>  the rates provider </returns>
 public static ImmutableRatesProvider createRatesProvider(LocalDate valuationDate, IborIndex index, LocalDateDoubleTimeSeries timeSeries)
 {
     return(ImmutableRatesProvider.builder(valuationDate).discountCurves(ImmutableMap.of(EUR, DSC_CURVE)).indexCurves(ImmutableMap.of(EUR_EURIBOR_3M, FWD3_CURVE, EUR_EURIBOR_6M, FWD6_CURVE)).fxRateProvider(FxMatrix.empty()).timeSeries(index, timeSeries).build());
 }
 /// <summary>
 /// Obtains an immutable rates providers with valuation date and time series.
 /// <para>
 /// The time series must contain historical data for the price index.
 ///
 /// </para>
 /// </summary>
 /// <param name="valuationDate">  the valuation date </param>
 /// <param name="timeSeries">  the time series </param>
 /// <returns> the rates provider </returns>
 public static ImmutableRatesProvider getRatesProvider(LocalDate valuationDate, LocalDateDoubleTimeSeries timeSeries)
 {
     return(ImmutableRatesProvider.builder(valuationDate).fxRateProvider(FxMatrix.empty()).priceIndexCurve(US_CPI_U, CPI_CURVE).timeSeries(US_CPI_U, timeSeries).build());
 }
Пример #22
0
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            SimplePriceIndexValues instance1 = SimplePriceIndexValues.of(US_CPI_U, VAL_DATE, CURVE_NOFIX, USCPI_TS);

            coverImmutableBean(instance1);
            SimplePriceIndexValues test2 = SimplePriceIndexValues.of(GB_HICP, VAL_DATE.plusMonths(1), CURVE_NOFIX, LocalDateDoubleTimeSeries.of(VAL_MONTH.minusMonths(2).atEndOfMonth(), 100d));

            coverBeanEquals(instance1, test2);
        }
 public virtual Result <LocalDateDoubleTimeSeries> provideTimeSeries(ObservableId id)
 {
     return(Result.success(LocalDateDoubleTimeSeries.empty()));
 }