public virtual void bucketedCs01SingleNodeCurveTest()
        {
            ImmutableCreditRatesProvider ratesProviderNoCredit = ImmutableCreditRatesProvider.builder().valuationDate(VALUATION_DATE).recoveryRateCurves(ImmutableMap.of(LEGAL_ENTITY, RECOVERY_CURVE)).discountCurves(ImmutableMap.of(USD, YIELD_CURVE)).build();
            QuoteId quoteId = QuoteId.of(StandardId.of("OG", END2.ToString()));
            CdsIsdaCreditCurveNode           node          = CdsIsdaCreditCurveNode.ofParSpread(DatesCdsTemplate.of(START, END2, CDS_CONV), quoteId, LEGAL_ENTITY);
            ImmutableMarketData              marketData    = ImmutableMarketData.builder(VALUATION_DATE).addValue(quoteId, DEAL_SPREAD * ONE_BP).build();
            IsdaCreditCurveDefinition        definition    = IsdaCreditCurveDefinition.of(CREDIT_CURVE_NAME, USD, VALUATION_DATE, ACT_365F, ImmutableList.of(node), true, false);
            LegalEntitySurvivalProbabilities creditCurve   = BUILDER.calibrate(definition, marketData, ratesProviderNoCredit, REF_DATA);
            ImmutableCreditRatesProvider     ratesProvider = ImmutableCreditRatesProvider.builder().valuationDate(VALUATION_DATE).recoveryRateCurves(ImmutableMap.of(LEGAL_ENTITY, RECOVERY_CURVE)).discountCurves(ImmutableMap.of(USD, YIELD_CURVE)).creditCurves(ImmutableMap.of(Pair.of(LEGAL_ENTITY, USD), creditCurve)).build();

            double[] expectedFd = new double[] { -6.876275937539589E-4, 1.1832215762730414E-4, 0.0012340982402658796, 0.002784985575488008, 0.005287295115619095, 2429.636217554099, 3101.303324461041 };
            CurrencyParameterSensitivity analytic = CS01_AN.bucketedCs01(CDS2, ImmutableList.copyOf(MARKET_CDS), ratesProvider, REF_DATA);
            CurrencyParameterSensitivity fd       = CS01_FD.bucketedCs01(CDS2, ImmutableList.copyOf(MARKET_CDS), ratesProvider, REF_DATA);

            assertEquals(fd.Currency, USD);
            assertEquals(fd.MarketDataName, CurveName.of("impliedSpreads"));
            assertEquals(fd.ParameterCount, NUM_MARKET_CDS);
            assertEquals(fd.ParameterMetadata, CDS_METADATA);
            assertTrue(DoubleArrayMath.fuzzyEquals(fd.Sensitivity.multipliedBy(ONE_BP).toArray(), expectedFd, NOTIONAL * TOL));
            assertEquals(analytic.Currency, USD);
            assertEquals(analytic.MarketDataName, CurveName.of("impliedSpreads"));
            assertEquals(analytic.ParameterCount, NUM_MARKET_CDS);
            assertEquals(analytic.ParameterMetadata, CDS_METADATA);
            assertTrue(DoubleArrayMath.fuzzyEquals(analytic.Sensitivity.toArray(), fd.Sensitivity.toArray(), NOTIONAL * ONE_BP * 10d));
        }
Esempio n. 2
0
 //-------------------------------------------------------------------------
 public virtual void test_iborIndex_tenor()
 {
     assertEquals(FloatingRateName.of("GBP-LIBOR-BBA").DefaultTenor, Tenor.TENOR_3M);
     assertEquals(FloatingRateName.of("GBP-LIBOR-BBA").toFloatingRateIndex(), IborIndices.GBP_LIBOR_3M);
     assertEquals(FloatingRateName.of("GBP-LIBOR-BBA").toFloatingRateIndex(Tenor.TENOR_1M), IborIndices.GBP_LIBOR_1M);
     assertEquals(FloatingRateName.of("GBP-LIBOR-BBA").toIborIndex(Tenor.TENOR_6M), IborIndices.GBP_LIBOR_6M);
     assertEquals(FloatingRateName.of("GBP-LIBOR-BBA").toIborIndex(Tenor.TENOR_12M), IborIndices.GBP_LIBOR_12M);
     assertEquals(FloatingRateName.of("GBP-LIBOR-BBA").toIborIndex(Tenor.TENOR_1Y), IborIndices.GBP_LIBOR_12M);
     assertThrows(() => FloatingRateName.of("GBP-WMBA-SONIA-COMPOUND").toIborIndex(Tenor.TENOR_6M), typeof(System.InvalidOperationException));
     assertEquals(ImmutableList.copyOf(FloatingRateName.of("GBP-LIBOR-BBA").Tenors), ImmutableList.of(Tenor.TENOR_1W, Tenor.TENOR_1M, Tenor.TENOR_2M, Tenor.TENOR_3M, Tenor.TENOR_6M, Tenor.TENOR_12M));
     assertEquals(FloatingRateName.of("GBP-LIBOR-BBA").toIborIndexFixingOffset(), DaysAdjustment.ofCalendarDays(0, BusinessDayAdjustment.of(PRECEDING, GBLO)));
 }
        //-------------------------------------------------------------------------
        public virtual void test_builder_full()
        {
            BondFuture test = BondFuture.builder().securityId(SECURITY_ID).deliveryBasket(BOND_PRODUCT).conversionFactors(CONVERSION_FACTOR).firstNoticeDate(FIRST_NOTICE_DATE).firstDeliveryDate(FIRST_DELIVERY_DATE).lastNoticeDate(LAST_NOTICE_DATE).lastDeliveryDate(LAST_DELIVERY_DATE).lastTradeDate(LAST_TRADING_DATE).rounding(ROUNDING).build();

            assertEquals(test.DeliveryBasket, ImmutableList.copyOf(BOND_PRODUCT));
            assertEquals(test.ConversionFactors, ImmutableList.copyOf(CONVERSION_FACTOR));
            assertEquals(test.Currency, USD);
            assertEquals(test.Notional, NOTIONAL);
            assertEquals(test.FirstNoticeDate, FIRST_NOTICE_DATE);
            assertEquals(test.LastNoticeDate, LAST_NOTICE_DATE);
            assertEquals(test.FirstDeliveryDate, FIRST_DELIVERY_DATE);
            assertEquals(test.LastDeliveryDate, LAST_DELIVERY_DATE);
            assertEquals(test.LastTradeDate, LAST_TRADING_DATE);
            assertEquals(test.Rounding, ROUNDING);
        }
        public virtual void parellelCs01Test()
        {
            double         fromExcel = 4238.557409;
            CurrencyAmount fd        = CS01_FD.parallelCs01(CDS1, ImmutableList.copyOf(MARKET_CDS), RATES_PROVIDER, REF_DATA);
            CurrencyAmount analytic  = CS01_AN.parallelCs01(CDS1, ImmutableList.copyOf(MARKET_CDS), RATES_PROVIDER, REF_DATA);

            assertEquals(fd.Currency, USD);
            assertEquals(fd.Amount * ONE_BP, fromExcel, TOL * NOTIONAL);
            assertEquals(analytic.Currency, USD);
            assertEquals(analytic.Amount * ONE_BP, fd.Amount * ONE_BP, ONE_BP * NOTIONAL);
            // equivalence to market quote sensitivity for par spread quote
            PointSensitivities             point      = PRICER.presentValueOnSettleSensitivity(CDS1, RATES_PROVIDER, REF_DATA);
            CurrencyParameterSensitivity   paramSensi = RATES_PROVIDER.singleCreditCurveParameterSensitivity(point, LEGAL_ENTITY, USD);
            CurrencyParameterSensitivities quoteSensi = QUOTE_CAL.sensitivity(CurrencyParameterSensitivities.of(paramSensi), RATES_PROVIDER);
            double cs01FromQuoteSensi = quoteSensi.Sensitivities.get(0).Sensitivity.sum();

            assertEquals(cs01FromQuoteSensi * ONE_BP, analytic.Amount * ONE_BP, TOL * NOTIONAL);
        }
        //-------------------------------------------------------------------------
        public virtual void parellelCs01IndexTest()
        {
            CurrencyAmount fdSingle       = CS01_FD.parallelCs01(CDS2, ImmutableList.copyOf(MARKET_CDS), RATES_PROVIDER, REF_DATA);
            CurrencyAmount analyticSingle = CS01_AN.parallelCs01(CDS2, ImmutableList.copyOf(MARKET_CDS), RATES_PROVIDER, REF_DATA);
            CurrencyAmount fd             = CS01_FD.parallelCs01(CDS_INDEX, ImmutableList.copyOf(MARKET_CDS_INDEX), RATES_PROVIDER, REF_DATA);
            CurrencyAmount analytic       = CS01_AN.parallelCs01(CDS_INDEX, ImmutableList.copyOf(MARKET_CDS_INDEX), RATES_PROVIDER, REF_DATA);

            assertEquals(fd.Currency, USD);
            assertEquals(fd.Amount, fdSingle.Amount * INDEX_FACTOR, TOL * NOTIONAL);
            assertEquals(analytic.Amount, analyticSingle.Amount * INDEX_FACTOR, TOL * NOTIONAL);
            assertEquals(analytic.Currency, USD);
            // equivalence to market quote sensitivity for par spread quote
            PointSensitivities             point      = PRICER_INDEX.presentValueOnSettleSensitivity(CDS_INDEX, RATES_PROVIDER, REF_DATA);
            CurrencyParameterSensitivity   paramSensi = RATES_PROVIDER.singleCreditCurveParameterSensitivity(point, INDEX_ID, USD);
            CurrencyParameterSensitivities quoteSensi = QUOTE_CAL.sensitivity(CurrencyParameterSensitivities.of(paramSensi), RATES_PROVIDER);
            double cs01FromQuoteSensi = quoteSensi.Sensitivities.get(0).Sensitivity.sum();

            assertEquals(cs01FromQuoteSensi, analytic.Amount, TOL * NOTIONAL);
        }
Esempio n. 6
0
        public virtual void test_of_noLists()
        {
            IniFile test = IniFile.of(CharSource.wrap(INI1));
            Multimap <string, string> keyValues1 = ImmutableListMultimap.of("c", "x", "b", "y", "a", "z");
            Multimap <string, string> keyValues2 = ImmutableListMultimap.of("a", "m", "b", "n");

            assertEquals(test.asMap(), ImmutableMap.of("section", PropertySet.of(keyValues1), "name", PropertySet.of(keyValues2)));

            assertEquals(test.contains("section"), true);
            assertEquals(test.section("section"), PropertySet.of(keyValues1));
            assertEquals(test.section("section").contains("c"), true);
            assertEquals(test.section("section").value("c"), "x");
            assertEquals(test.section("section").valueList("c"), ImmutableList.of("x"));
            assertEquals(test.section("section").contains("b"), true);
            assertEquals(test.section("section").value("b"), "y");
            assertEquals(test.section("section").valueList("b"), ImmutableList.of("y"));
            assertEquals(test.section("section").contains("a"), true);
            assertEquals(test.section("section").value("a"), "z");
            assertEquals(test.section("section").valueList("a"), ImmutableList.of("z"));
            assertEquals(test.section("section").contains("d"), false);
            // order must be retained
            assertEquals(ImmutableList.copyOf(test.section("section").keys()), ImmutableList.of("c", "b", "a"));
            assertEquals(test.section("section").asMultimap(), ImmutableListMultimap.of("c", "x", "b", "y", "a", "z"));

            assertEquals(test.contains("name"), true);
            assertEquals(test.section("name"), PropertySet.of(keyValues2));
            assertEquals(test.section("name").contains("a"), true);
            assertEquals(test.section("name").value("a"), "m");
            assertEquals(test.section("name").valueList("a"), ImmutableList.of("m"));
            assertEquals(test.section("name").contains("b"), true);
            assertEquals(test.section("name").value("b"), "n");
            assertEquals(test.section("name").valueList("b"), ImmutableList.of("n"));
            assertEquals(test.section("name").contains("c"), false);
            assertEquals(ImmutableList.copyOf(test.section("name").keys()), ImmutableList.of("a", "b"));
            assertEquals(test.section("name").asMultimap(), ImmutableListMultimap.of("a", "m", "b", "n"));

            assertEquals(test.contains("unknown"), false);
            assertThrowsIllegalArg(() => test.section("unknown"));
            assertEquals(test.section("section").valueList("unknown"), ImmutableList.of());
            assertThrowsIllegalArg(() => test.section("section").value("unknown"));
            assertEquals(test.ToString(), "{section={c=[x], b=[y], a=[z]}, name={a=[m], b=[n]}}");
        }
        public virtual void bucketedCs01Test()
        {
            double[] expectedFd                   = new double[] { 0.02446907003406107, 0.1166137422736746, 0.5196553952424576, 1.4989046391578054, 3.5860718603647483, 4233.77162264947, 0.0 };
            CurrencyParameterSensitivity fd       = CS01_FD.bucketedCs01(CDS1, ImmutableList.copyOf(MARKET_CDS), RATES_PROVIDER, REF_DATA);
            CurrencyParameterSensitivity analytic = CS01_AN.bucketedCs01(CDS1, ImmutableList.copyOf(MARKET_CDS), RATES_PROVIDER, REF_DATA);

            assertEquals(fd.Currency, USD);
            assertEquals(fd.MarketDataName, CurveName.of("impliedSpreads"));
            assertEquals(fd.ParameterCount, NUM_MARKET_CDS);
            assertEquals(fd.ParameterMetadata, CDS_METADATA);
            assertTrue(DoubleArrayMath.fuzzyEquals(fd.Sensitivity.multipliedBy(ONE_BP).toArray(), expectedFd, NOTIONAL * TOL));
            assertEquals(analytic.Currency, USD);
            assertEquals(analytic.MarketDataName, CurveName.of("impliedSpreads"));
            assertEquals(analytic.ParameterCount, NUM_MARKET_CDS);
            assertEquals(analytic.ParameterMetadata, CDS_METADATA);
            assertTrue(DoubleArrayMath.fuzzyEquals(analytic.Sensitivity.toArray(), fd.Sensitivity.toArray(), NOTIONAL * ONE_BP * 10d));
            PointSensitivities             point      = PRICER.presentValueOnSettleSensitivity(CDS1, RATES_PROVIDER, REF_DATA);
            CurrencyParameterSensitivity   paramSensi = RATES_PROVIDER.singleCreditCurveParameterSensitivity(point, LEGAL_ENTITY, USD);
            CurrencyParameterSensitivities quoteSensi = QUOTE_CAL.sensitivity(CurrencyParameterSensitivities.of(paramSensi), RATES_PROVIDER);

            assertTrue(DoubleArrayMath.fuzzyEquals(quoteSensi.Sensitivities.get(0).Sensitivity.toArray(), analytic.Sensitivity.toArray(), NOTIONAL * TOL));
        }
        public virtual void bucketedCs01IndexTest()
        {
            CurrencyParameterSensitivity fdSingle       = CS01_FD.bucketedCs01(CDS2, ImmutableList.copyOf(MARKET_CDS), RATES_PROVIDER, REF_DATA);
            CurrencyParameterSensitivity analyticSingle = CS01_AN.bucketedCs01(CDS2, ImmutableList.copyOf(MARKET_CDS), RATES_PROVIDER, REF_DATA);
            CurrencyParameterSensitivity fd             = CS01_FD.bucketedCs01(CDS_INDEX, ImmutableList.copyOf(MARKET_CDS_INDEX), RATES_PROVIDER, REF_DATA);
            CurrencyParameterSensitivity analytic       = CS01_AN.bucketedCs01(CDS_INDEX, ImmutableList.copyOf(MARKET_CDS_INDEX), RATES_PROVIDER, REF_DATA);

            assertEquals(fd.Currency, USD);
            assertEquals(fd.MarketDataName, CurveName.of("impliedSpreads"));
            assertEquals(fd.ParameterCount, NUM_MARKET_CDS);
            assertEquals(fd.ParameterMetadata, CDS_INDEX_METADATA);
            assertTrue(DoubleArrayMath.fuzzyEquals(fd.Sensitivity.toArray(), fdSingle.Sensitivity.multipliedBy(INDEX_FACTOR).toArray(), NOTIONAL * TOL));
            assertEquals(analytic.Currency, USD);
            assertEquals(analytic.MarketDataName, CurveName.of("impliedSpreads"));
            assertEquals(analytic.ParameterCount, NUM_MARKET_CDS);
            assertEquals(analytic.ParameterMetadata, CDS_INDEX_METADATA);
            assertTrue(DoubleArrayMath.fuzzyEquals(analytic.Sensitivity.toArray(), analyticSingle.Sensitivity.multipliedBy(INDEX_FACTOR).toArray(), NOTIONAL * TOL));
            PointSensitivities             point      = PRICER_INDEX.presentValueOnSettleSensitivity(CDS_INDEX, RATES_PROVIDER, REF_DATA);
            CurrencyParameterSensitivity   paramSensi = RATES_PROVIDER.singleCreditCurveParameterSensitivity(point, INDEX_ID, USD);
            CurrencyParameterSensitivities quoteSensi = QUOTE_CAL.sensitivity(CurrencyParameterSensitivities.of(paramSensi), RATES_PROVIDER);

            assertTrue(DoubleArrayMath.fuzzyEquals(quoteSensi.Sensitivities.get(0).Sensitivity.toArray(), analytic.Sensitivity.toArray(), NOTIONAL * TOL));
        }
 //-------------------------------------------------------------------------
 internal static BondFuture sut()
 {
     return(BondFuture.builder().securityId(SECURITY_ID).deliveryBasket(BOND_PRODUCT).conversionFactors(ImmutableList.copyOf(CONVERSION_FACTOR)).firstNoticeDate(FIRST_NOTICE_DATE).firstDeliveryDate(FIRST_DELIVERY_DATE).lastNoticeDate(LAST_NOTICE_DATE).lastDeliveryDate(LAST_DELIVERY_DATE).lastTradeDate(LAST_TRADING_DATE).rounding(ROUNDING).build());
 }