//-------------------------------------------------------------------------
        public virtual void test_fxRate_separate()
        {
            ImmutableRatesProvider test = ImmutableRatesProvider.builder(VAL_DATE).fxRateProvider(FX_MATRIX).build();

            assertEquals(test.fxRate(USD, GBP), 1 / FX_GBP_USD, 0d);
            assertEquals(test.fxRate(USD, USD), 1d, 0d);
        }
        public virtual void test_discountFactors_notKnown()
        {
            ImmutableRatesProvider test = ImmutableRatesProvider.builder(VAL_DATE).build();

            assertThrowsIllegalArg(() => test.discountFactors(GBP));
            assertThrowsIllegalArg(() => test.discountFactor(GBP, LocalDate.of(2014, 7, 30)));
        }
        //-------------------------------------------------------------------------
        public virtual void test_getCurves()
        {
            ImmutableRatesProvider test = ImmutableRatesProvider.builder(VAL_DATE).discountCurve(GBP, DISCOUNT_CURVE_GBP).discountCurve(USD, DISCOUNT_CURVE_USD).build();

            assertEquals(test.Curves.Count, 2);
            assertEquals(test.Curves[DISCOUNT_CURVE_GBP.Name], DISCOUNT_CURVE_GBP);
            assertEquals(test.Curves[DISCOUNT_CURVE_USD.Name], DISCOUNT_CURVE_USD);
        }
        public virtual void test_getCurves_withGroup()
        {
            ImmutableRatesProvider test  = ImmutableRatesProvider.builder(VAL_DATE).discountCurve(GBP, DISCOUNT_CURVE_GBP).discountCurve(USD, DISCOUNT_CURVE_USD).build();
            CurveGroupName         group = CurveGroupName.of("GRP");

            assertEquals(test.getCurves(group).Count, 2);
            assertEquals(test.getCurves(group)[CurveId.of(group, DISCOUNT_CURVE_GBP.Name)], DISCOUNT_CURVE_GBP);
            assertEquals(test.getCurves(group)[CurveId.of(group, DISCOUNT_CURVE_USD.Name)], DISCOUNT_CURVE_USD);
        }
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            ImmutableRatesProvider test = ImmutableRatesProvider.builder(VAL_DATE).build();

            coverImmutableBean(test);
            ImmutableRatesProvider test2 = ImmutableRatesProvider.builder(LocalDate.of(2014, 6, 27)).discountCurve(GBP, DISCOUNT_CURVE_GBP).build();

            coverBeanEquals(test, test2);
        }
        //-------------------------------------------------------------------------
        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_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_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_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));
        }
        //-------------------------------------------------------------------------
        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));
        }
Ejemplo n.º 11
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Combines a number of rates providers.
        /// <para>
        /// If the two providers have curves or time series for the same currency or index,
        /// an <seealso cref="IllegalAccessException"/> is thrown.
        /// The FxRateProviders is not populated with the given provider; no attempt is done on merging the embedded FX providers.
        ///
        /// </para>
        /// </summary>
        /// <param name="fx">  the FX provider for the resulting rate provider </param>
        /// <param name="providers">  the rates providers to be merged </param>
        /// <returns> the combined rates provider </returns>
        public static ImmutableRatesProvider combined(FxRateProvider fx, params ImmutableRatesProvider[] providers)
        {
            ArgChecker.isTrue(providers.Length > 0, "at least one provider requested");
            ImmutableRatesProvider merged = ImmutableRatesProvider.builder(providers[0].ValuationDate).build();

            foreach (ImmutableRatesProvider provider in providers)
            {
                merged = merged.combinedWith(provider, fx);
            }
            return(merged);
        }
        //-------------------------------------------------------------------------
        public virtual void test_fxForwardRates()
        {
            ImmutableRatesProvider test = ImmutableRatesProvider.builder(VAL_DATE).fxRateProvider(FX_MATRIX).discountCurve(GBP, DISCOUNT_CURVE_GBP).discountCurve(USD, DISCOUNT_CURVE_USD).build();
            DiscountFxForwardRates res  = (DiscountFxForwardRates)test.fxForwardRates(CurrencyPair.of(GBP, USD));

            assertEquals(res.BaseCurrencyDiscountFactors, ZeroRateDiscountFactors.of(GBP, VAL_DATE, DISCOUNT_CURVE_GBP));
            assertEquals(res.CounterCurrencyDiscountFactors, ZeroRateDiscountFactors.of(USD, VAL_DATE, DISCOUNT_CURVE_USD));
            assertEquals(res.CurrencyPair, CurrencyPair.of(GBP, USD));
            assertEquals(res.FxRateProvider, FX_MATRIX);
            assertEquals(res.ValuationDate, VAL_DATE);
        }
        public virtual void merge_illegal_arguments()
        {
            ImmutableRatesProvider test_dsc  = ImmutableRatesProvider.builder(VAL_DATE).discountCurve(GBP, DISCOUNT_CURVE_GBP).build();
            ImmutableRatesProvider test_ts   = ImmutableRatesProvider.builder(VAL_DATE).timeSeries(GBP_USD_WM, TS).build();
            ImmutableRatesProvider test_ibor = ImmutableRatesProvider.builder(VAL_DATE).iborIndexCurve(USD_LIBOR_3M, USD_LIBOR_CURVE).build();
            ImmutableRatesProvider test_on   = ImmutableRatesProvider.builder(VAL_DATE).overnightIndexCurve(USD_FED_FUND, FED_FUND_CURVE).build();
            ImmutableRatesProvider test_pi   = ImmutableRatesProvider.builder(VAL_DATE).priceIndexCurve(GB_RPI, GBPRI_CURVE).build();

            assertThrowsIllegalArg(() => ImmutableRatesProvider.combined(FX_MATRIX, test_dsc, test_dsc));
            assertThrowsIllegalArg(() => ImmutableRatesProvider.combined(FX_MATRIX, test_ts, test_ts));
            assertThrowsIllegalArg(() => ImmutableRatesProvider.combined(FX_MATRIX, test_ibor, test_ibor));
            assertThrowsIllegalArg(() => ImmutableRatesProvider.combined(FX_MATRIX, test_on, test_on));
            assertThrowsIllegalArg(() => ImmutableRatesProvider.combined(FX_MATRIX, test_pi, test_pi));
        }
        public virtual void merge_content_2()
        {
            ImmutableRatesProvider test1  = ImmutableRatesProvider.builder(VAL_DATE).discountCurve(GBP, DISCOUNT_CURVE_GBP).timeSeries(GBP_USD_WM, TS).build();
            ImmutableRatesProvider test2  = ImmutableRatesProvider.builder(VAL_DATE).discountCurve(USD, DISCOUNT_CURVE_USD).iborIndexCurve(USD_LIBOR_3M, USD_LIBOR_CURVE).overnightIndexCurve(USD_FED_FUND, FED_FUND_CURVE).priceIndexCurve(GB_RPI, GBPRI_CURVE).timeSeries(GB_RPI, TS).build();
            ImmutableRatesProvider merged = ImmutableRatesProvider.combined(FX_MATRIX, test1, test2);

            assertEquals(merged.ValuationDate, VAL_DATE);
            assertEquals(merged.discountFactors(USD), DiscountFactors.of(USD, VAL_DATE, DISCOUNT_CURVE_USD));
            assertEquals(merged.discountFactors(GBP), DiscountFactors.of(GBP, VAL_DATE, DISCOUNT_CURVE_GBP));
            assertEquals(merged.iborIndexRates(USD_LIBOR_3M), IborIndexRates.of(USD_LIBOR_3M, VAL_DATE, USD_LIBOR_CURVE));
            assertEquals(merged.overnightIndexRates(USD_FED_FUND), OvernightIndexRates.of(USD_FED_FUND, VAL_DATE, FED_FUND_CURVE));
            assertEquals(merged.priceIndexValues(GB_RPI), PriceIndexValues.of(GB_RPI, VAL_DATE, GBPRI_CURVE, TS));
            assertEquals(merged.timeSeries(GBP_USD_WM), TS);
            assertEquals(merged.FxRateProvider, FX_MATRIX);
        }
        public virtual void pointAndParameterFx()
        {
            ImmutableRatesProvider test        = ImmutableRatesProvider.builder(VAL_DATE).fxRateProvider(FX_MATRIX).discountCurve(GBP, DISCOUNT_CURVE_GBP).discountCurve(USD, DISCOUNT_CURVE_USD).build();
            ImmutableRatesProvider test_gbp_up = ImmutableRatesProvider.builder(VAL_DATE).fxRateProvider(FX_MATRIX).discountCurve(GBP, DISCOUNT_CURVE_GBP_UP).discountCurve(USD, DISCOUNT_CURVE_USD).build();
            ImmutableRatesProvider test_gbp_dw = ImmutableRatesProvider.builder(VAL_DATE).fxRateProvider(FX_MATRIX).discountCurve(GBP, DISCOUNT_CURVE_GBP_DOWN).discountCurve(USD, DISCOUNT_CURVE_USD).build();
            ImmutableRatesProvider test_usd_up = ImmutableRatesProvider.builder(VAL_DATE).fxRateProvider(FX_MATRIX).discountCurve(GBP, DISCOUNT_CURVE_GBP).discountCurve(USD, DISCOUNT_CURVE_USD_UP).build();
            ImmutableRatesProvider test_usd_dw = ImmutableRatesProvider.builder(VAL_DATE).fxRateProvider(FX_MATRIX).discountCurve(GBP, DISCOUNT_CURVE_GBP).discountCurve(USD, DISCOUNT_CURVE_USD_DOWN).build();
            LocalDate matuirtyDate             = GBP_USD_WM.calculateMaturityFromFixing(VAL_DATE, REF_DATA);
            double    maturityTime             = DAY_COUNT.relativeYearFraction(VAL_DATE, matuirtyDate);
            // GBP based
            FxIndexObservation      obs = FxIndexObservation.of(GBP_USD_WM, VAL_DATE, REF_DATA);
            PointSensitivityBuilder sensiBuildCmpGBP = test.fxIndexRates(GBP_USD_WM).ratePointSensitivity(obs, GBP);
            FxIndexSensitivity      sensiBuildExpGBP = FxIndexSensitivity.of(obs, GBP, USD, 1.0);

            assertTrue(sensiBuildCmpGBP.Equals(sensiBuildExpGBP));
            double sense_gbp1 = 0.5 * (test_gbp_up.fxIndexRates(GBP_USD_WM).rate(obs, GBP) - test_gbp_dw.fxIndexRates(GBP_USD_WM).rate(obs, GBP)) / EPS_FD * (-maturityTime * GBP_DSC);
            double sense_usd1 = 0.5 * (test_usd_up.fxIndexRates(GBP_USD_WM).rate(obs, GBP) - test_usd_dw.fxIndexRates(GBP_USD_WM).rate(obs, GBP)) / EPS_FD * (-maturityTime * USD_DSC);
            PointSensitivityBuilder sensiBuildDecGBP = ZeroRateSensitivity.of(GBP, maturityTime, USD, sense_gbp1);

            sensiBuildDecGBP = sensiBuildDecGBP.combinedWith(ZeroRateSensitivity.of(USD, maturityTime, USD, sense_usd1));
            CurrencyParameterSensitivities paramSensiCmpGBP = test.parameterSensitivity(sensiBuildCmpGBP.build().normalized());
            CurrencyParameterSensitivities paramSensiExpGBP = test.parameterSensitivity(sensiBuildDecGBP.build().normalized());

            assertTrue(paramSensiCmpGBP.equalWithTolerance(paramSensiExpGBP, EPS_FD));
            // USD based
            PointSensitivityBuilder sensiBuildCmpUSD = test.fxIndexRates(GBP_USD_WM).ratePointSensitivity(obs, USD);
            FxIndexSensitivity      sensiBuildExpUSD = FxIndexSensitivity.of(obs, USD, GBP, 1.0);

            assertTrue(sensiBuildCmpUSD.Equals(sensiBuildExpUSD));
            double sense_gbp2 = 0.5 * (test_gbp_up.fxIndexRates(GBP_USD_WM).rate(obs, USD) - test_gbp_dw.fxIndexRates(GBP_USD_WM).rate(obs, USD)) / EPS_FD * (-maturityTime * GBP_DSC);
            double sense_usd2 = 0.5 * (test_usd_up.fxIndexRates(GBP_USD_WM).rate(obs, USD) - test_usd_dw.fxIndexRates(GBP_USD_WM).rate(obs, USD)) / EPS_FD * (-maturityTime * USD_DSC);
            PointSensitivityBuilder sensiBuildDecUSD = ZeroRateSensitivity.of(GBP, maturityTime, GBP, sense_gbp2);

            sensiBuildDecUSD = sensiBuildDecUSD.combinedWith(ZeroRateSensitivity.of(USD, maturityTime, GBP, sense_usd2));
            CurrencyParameterSensitivities paramSensiCmpUSD = test.parameterSensitivity(sensiBuildCmpUSD.build().normalized());
            CurrencyParameterSensitivities paramSensiExpUSD = test.parameterSensitivity(sensiBuildDecUSD.build().normalized());

            assertTrue(paramSensiCmpUSD.equalWithTolerance(paramSensiExpUSD, EPS_FD));
        }
        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));
        }
        //-------------------------------------------------------------------------
        public virtual void test_discountFactors()
        {
            ImmutableRatesProvider test = ImmutableRatesProvider.builder(VAL_DATE).discountCurve(GBP, DISCOUNT_CURVE_GBP).discountCurve(USD, DISCOUNT_CURVE_USD).build();

            assertEquals(test.discountFactors(GBP).Currency, GBP);
        }
 public virtual void testSerializeDeserialize()
 {
     cycleBean(ImmutableRatesProvider.builder(VAL_DATE).build());
 }
        public virtual void test_fxRate_pair()
        {
            ImmutableRatesProvider test = ImmutableRatesProvider.builder(VAL_DATE).fxRateProvider(FX_MATRIX).build();

            assertEquals(test.fxRate(CurrencyPair.of(USD, GBP)), 1 / FX_GBP_USD, 0d);
        }
        public virtual void test_priceIndexValues_notKnown()
        {
            ImmutableRatesProvider test = ImmutableRatesProvider.builder(VAL_DATE).build();

            assertThrowsIllegalArg(() => test.priceIndexValues(GB_RPI));
        }