//-------------------------------------------------------------------------
        public virtual void test_of()
        {
            DiscountFxForwardRates test = DiscountFxForwardRates.of(CURRENCY_PAIR, FX_RATE, DFCURVE_GBP, DFCURVE_USD);

            assertEquals(test.CurrencyPair, CURRENCY_PAIR);
            assertEquals(test.ValuationDate, DATE_VAL);
            assertEquals(test.BaseCurrencyDiscountFactors, DFCURVE_GBP);
            assertEquals(test.CounterCurrencyDiscountFactors, DFCURVE_USD);
            assertEquals(test.FxRateProvider, FX_RATE);
            assertEquals(test.findData(CURVE1.Name), CURVE1);
            assertEquals(test.findData(CURVE2.Name), CURVE2);
            assertEquals(test.findData(CurveName.of("Rubbish")), null);

            int baseSize = DFCURVE_USD.ParameterCount;

            assertEquals(test.ParameterCount, DFCURVE_GBP.ParameterCount + baseSize);
            assertEquals(test.getParameter(0), DFCURVE_GBP.getParameter(0));
            assertEquals(test.getParameter(baseSize), DFCURVE_USD.getParameter(0));
            assertEquals(test.getParameterMetadata(0), DFCURVE_GBP.getParameterMetadata(0));
            assertEquals(test.getParameterMetadata(baseSize), DFCURVE_USD.getParameterMetadata(0));
            assertEquals(test.withParameter(0, 1d).BaseCurrencyDiscountFactors, DFCURVE_GBP.withParameter(0, 1d));
            assertEquals(test.withParameter(0, 1d).CounterCurrencyDiscountFactors, DFCURVE_USD);
            assertEquals(test.withParameter(baseSize, 1d).BaseCurrencyDiscountFactors, DFCURVE_GBP);
            assertEquals(test.withParameter(baseSize, 1d).CounterCurrencyDiscountFactors, DFCURVE_USD.withParameter(0, 1d));
            assertEquals(test.withPerturbation((i, v, m) => v + 1d).BaseCurrencyDiscountFactors, DFCURVE_GBP.withPerturbation((i, v, m) => v + 1d));
            assertEquals(test.withPerturbation((i, v, m) => v + 1d).CounterCurrencyDiscountFactors, DFCURVE_USD.withPerturbation((i, v, m) => v + 1d));
        }
        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));
        }
Пример #3
0
        public virtual void getter()
        {
            assertEquals(PARAMETERS.AlphaCurve, ALPHA_CURVE);
            assertEquals(PARAMETERS.BetaCurve, BETA_CURVE);
            assertEquals(PARAMETERS.RhoCurve, RHO_CURVE);
            assertEquals(PARAMETERS.NuCurve, NU_CURVE);
            assertEquals(PARAMETERS.SabrVolatilityFormula, FORMULA);
            assertEquals(PARAMETERS.ShiftCurve.Name, CurveName.of("Zero shift"));
            assertEquals(PARAMETERS.DayCount, ACT_ACT_ISDA);
            assertEquals(PARAMETERS.ParameterCount, 9);
            double expiry = 2.0;
            double alpha  = ALPHA_CURVE.yValue(expiry);
            double beta   = BETA_CURVE.yValue(expiry);
            double rho    = RHO_CURVE.yValue(expiry);
            double nu     = NU_CURVE.yValue(expiry);

            assertEquals(PARAMETERS.alpha(expiry), alpha);
            assertEquals(PARAMETERS.beta(expiry), beta);
            assertEquals(PARAMETERS.rho(expiry), rho);
            assertEquals(PARAMETERS.nu(expiry), nu);
            double strike  = 1.1;
            double forward = 1.05;

            assertEquals(PARAMETERS.volatility(expiry, strike, forward), FORMULA.volatility(forward, strike, expiry, alpha, beta, rho, nu));
            double[] adjCmp = PARAMETERS.volatilityAdjoint(expiry, strike, forward).Derivatives.toArray();
            double[] adjExp = FORMULA.volatilityAdjoint(forward, strike, expiry, alpha, beta, rho, nu).Derivatives.toArray();
            for (int i = 0; i < 6; ++i)
            {
                assertEquals(adjCmp[i], adjExp[i]);
            }
            for (int i = 0; i < 9; ++i)
            {
                if (i < 2)
                {
                    assertEquals(PARAMETERS.getParameterMetadata(i), ALPHA_CURVE.getParameterMetadata(i));
                    assertEquals(PARAMETERS.getParameter(i), ALPHA_CURVE.getParameter(i));
                }
                else if (i < 4)
                {
                    assertEquals(PARAMETERS.getParameterMetadata(i), BETA_CURVE.getParameterMetadata(i - 2));
                    assertEquals(PARAMETERS.getParameter(i), BETA_CURVE.getParameter(i - 2));
                }
                else if (i < 6)
                {
                    assertEquals(PARAMETERS.getParameterMetadata(i), RHO_CURVE.getParameterMetadata(i - 4));
                    assertEquals(PARAMETERS.getParameter(i), RHO_CURVE.getParameter(i - 4));
                }
                else if (i < 8)
                {
                    assertEquals(PARAMETERS.getParameterMetadata(i), NU_CURVE.getParameterMetadata(i - 6));
                    assertEquals(PARAMETERS.getParameter(i), NU_CURVE.getParameter(i - 6));
                }
                else
                {
                    assertEquals(PARAMETERS.getParameterMetadata(i), ParameterMetadata.empty());
                    assertEquals(PARAMETERS.getParameter(i), 0d);
                }
            }
        }
Пример #4
0
        public virtual void test_findData()
        {
            ImmutableLegalEntityDiscountingProvider test = ImmutableLegalEntityDiscountingProvider.builder().issuerCurves(ImmutableMap.of(Pair.of(GROUP_ISSUER, GBP), DSC_FACTORS_ISSUER)).issuerCurveGroups(ImmutableMap.of(ID_ISSUER, GROUP_ISSUER)).repoCurves(ImmutableMap.of(Pair.of(GROUP_REPO_ISSUER, GBP), DSC_FACTORS_REPO)).repoCurveGroups(ImmutableMap.of(ID_ISSUER, GROUP_REPO_ISSUER)).valuationDate(DATE).build();

            assertEquals(test.findData(DSC_FACTORS_ISSUER.Curve.Name), DSC_FACTORS_ISSUER.Curve);
            assertEquals(test.findData(DSC_FACTORS_REPO.Curve.Name), DSC_FACTORS_REPO.Curve);
            assertEquals(test.findData(CurveName.of("Rubbish")), null);
        }
Пример #5
0
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            ParameterSize test = ParameterSize.of(CURVE_NAME, 3);

            coverImmutableBean(test);
            ParameterSize test2 = ParameterSize.of(CurveName.of("Foo"), 4);

            coverBeanEquals(test, test2);
        }
Пример #6
0
        public virtual void test_of()
        {
            ConstantRecoveryRates test = ConstantRecoveryRates.of(LEGAL_ENTITY, VALUATION, RECOVERY_RATE);

            assertEquals(test.LegalEntityId, LEGAL_ENTITY);
            assertEquals(test.RecoveryRate, RECOVERY_RATE);
            assertEquals(test.ValuationDate, VALUATION);
            assertEquals(test.recoveryRate(DATE_AFTER), RECOVERY_RATE);
            assertEquals(test.findData(CurveName.of("Rubbish")), null);
            assertEquals(test.getParameter(0), RECOVERY_RATE);
            assertEquals(test.ParameterCount, 1);
            assertEquals(test.getParameterMetadata(0), ParameterMetadata.empty());
            assertEquals(test.withParameter(0, 0.5), ConstantRecoveryRates.of(LEGAL_ENTITY, VALUATION, 0.5));
        }
Пример #7
0
        public virtual void test_of_interface()
        {
            ConstantCurve         curve = ConstantCurve.of(DefaultCurveMetadata.builder().yValueType(ValueType.RECOVERY_RATE).curveName("recoveryRate").build(), RECOVERY_RATE);
            ConstantRecoveryRates test  = (ConstantRecoveryRates)RecoveryRates.of(LEGAL_ENTITY, VALUATION, curve);

            assertEquals(test.LegalEntityId, LEGAL_ENTITY);
            assertEquals(test.RecoveryRate, RECOVERY_RATE);
            assertEquals(test.ValuationDate, VALUATION);
            assertEquals(test.recoveryRate(DATE_AFTER), RECOVERY_RATE);
            assertEquals(test.findData(CurveName.of("Rubbish")), null);
            assertEquals(test.getParameter(0), RECOVERY_RATE);
            assertEquals(test.ParameterCount, 1);
            assertEquals(test.getParameterMetadata(0), ParameterMetadata.empty());
            assertEquals(test.withParameter(0, 0.5), ConstantRecoveryRates.of(LEGAL_ENTITY, VALUATION, 0.5));
        }
        //-------------------------------------------------------------------------
        public virtual void test_of_withoutFixings()
        {
            ForwardFxIndexRates test = ForwardFxIndexRates.of(GBP_USD_WM, FWD_RATES);

            assertEquals(test.Index, GBP_USD_WM);
            assertEquals(test.ValuationDate, DATE_VAL);
            assertEquals(test.Fixings, SERIES_EMPTY);
            assertEquals(test.FxForwardRates, FWD_RATES);
            assertEquals(test.findData(CURVE1.Name), CURVE1);
            assertEquals(test.findData(CURVE2.Name), CURVE2);
            assertEquals(test.findData(CurveName.of("Rubbish")), null);
            assertEquals(test.ParameterCount, FWD_RATES.ParameterCount);
            assertEquals(test.getParameter(0), FWD_RATES.getParameter(0));
            assertEquals(test.getParameterMetadata(0), FWD_RATES.getParameterMetadata(0));
            assertEquals(test.withParameter(0, 1d).FxForwardRates, FWD_RATES.withParameter(0, 1d));
            assertEquals(test.withPerturbation((i, v, m) => v + 1d).FxForwardRates, FWD_RATES.withPerturbation((i, v, m) => v + 1d));
        }
Пример #9
0
        public virtual void absoluteScenarios()
        {
            CurveName      curveName                  = CurveName.of("curveName");
            CurveGroupName curveGroupName             = CurveGroupName.of("curveGroupName");
            Curve          curve                      = ConstantCurve.of(curveName, 2);
            PerturbationMapping <Curve> mapping       = PerturbationMapping.of(MarketDataFilter.ofName(curveName), CurveParallelShifts.absolute(0.1, 0.2, 0.3));
            CurveId                curveId            = CurveId.of(curveGroupName, curveName);
            ScenarioMarketData     marketData         = ImmutableScenarioMarketData.builder(TestHelper.date(2011, 3, 8)).addValue(curveId, curve).build();
            ScenarioDefinition     scenarioDefinition = ScenarioDefinition.ofMappings(mapping);
            MarketDataFactory      marketDataFactory  = MarketDataFactory.of(mock(typeof(ObservableDataProvider)), mock(typeof(TimeSeriesProvider)));
            MarketDataRequirements requirements       = MarketDataRequirements.builder().addValues(curveId).build();
            ScenarioMarketData     scenarioData       = marketDataFactory.createMultiScenario(requirements, MarketDataConfig.empty(), marketData, REF_DATA, scenarioDefinition);
            MarketDataBox <Curve>  curves             = scenarioData.getValue(curveId);

            assertThat(curves.ScenarioCount).isEqualTo(3);
            checkCurveValues(curves.getValue(0), 2.1);
            checkCurveValues(curves.getValue(1), 2.2);
            checkCurveValues(curves.getValue(2), 2.3);
        }
Пример #10
0
        //-------------------------------------------------------------------------
        public virtual void test_of_noSeasonality()
        {
            SimplePriceIndexValues test = SimplePriceIndexValues.of(US_CPI_U, VAL_DATE, CURVE_NOFIX, USCPI_TS);

            assertEquals(test.Index, US_CPI_U);
            assertEquals(test.ValuationDate, VAL_DATE);
            assertEquals(test.Curve, CURVE_NOFIX);
            assertEquals(test.ParameterCount, CURVE_NOFIX.ParameterCount);
            assertEquals(test.getParameter(0), CURVE_NOFIX.getParameter(0));
            assertEquals(test.getParameterMetadata(0), CURVE_NOFIX.getParameterMetadata(0));
            assertEquals(test.withParameter(0, 1d).Curve, CURVE_NOFIX.withParameter(0, 1d));
            assertEquals(test.withPerturbation((i, v, m) => v + 1d).Curve, CURVE_NOFIX.withPerturbation((i, v, m) => v + 1d));
            assertEquals(test.findData(CURVE_NOFIX.Name), CURVE_NOFIX);
            assertEquals(test.findData(CurveName.of("Rubbish")), null);
            // check PriceIndexValues
            PriceIndexValues test2 = PriceIndexValues.of(US_CPI_U, VAL_DATE, CURVE_NOFIX, USCPI_TS);

            assertEquals(test, test2);
        }
        //-------------------------------------------------------------------------
        public virtual void test_of_withoutFixings()
        {
            DiscountOvernightIndexRates test = DiscountOvernightIndexRates.of(GBP_SONIA, DFCURVE);

            assertEquals(test.Index, GBP_SONIA);
            assertEquals(test.ValuationDate, DATE_VAL);
            assertEquals(test.Fixings, SERIES_EMPTY);
            assertEquals(test.DiscountFactors, DFCURVE);
            assertEquals(test.ParameterCount, DFCURVE.ParameterCount);
            assertEquals(test.getParameter(0), DFCURVE.getParameter(0));
            assertEquals(test.getParameterMetadata(0), DFCURVE.getParameterMetadata(0));
            assertEquals(test.withParameter(0, 1d).DiscountFactors, DFCURVE.withParameter(0, 1d));
            assertEquals(test.withPerturbation((i, v, m) => v + 1d).DiscountFactors, DFCURVE.withPerturbation((i, v, m) => v + 1d));
            assertEquals(test.findData(CURVE.Name), CURVE);
            assertEquals(test.findData(CurveName.of("Rubbish")), null);
            // check IborIndexRates
            OvernightIndexRates test2 = OvernightIndexRates.of(GBP_SONIA, DATE_VAL, CURVE);

            assertEquals(test, test2);
        }
Пример #12
0
        //-------------------------------------------------------------------------
        public virtual void test_of_withoutFixings()
        {
            SimpleIborIndexRates test = SimpleIborIndexRates.of(GBP_LIBOR_3M, DATE_VAL, CURVE);

            assertEquals(test.Index, GBP_LIBOR_3M);
            assertEquals(test.ValuationDate, DATE_VAL);
            assertEquals(test.Fixings, SERIES_EMPTY);
            assertEquals(test.Curve, CURVE);
            assertEquals(test.ParameterCount, CURVE.ParameterCount);
            assertEquals(test.getParameter(0), CURVE.getParameter(0));
            assertEquals(test.getParameterMetadata(0), CURVE.getParameterMetadata(0));
            assertEquals(test.withParameter(0, 1d).Curve, CURVE.withParameter(0, 1d));
            assertEquals(test.withPerturbation((i, v, m) => v + 1d).Curve, CURVE.withPerturbation((i, v, m) => v + 1d));
            assertEquals(test.findData(CURVE.Name), CURVE);
            assertEquals(test.findData(CurveName.of("Rubbish")), null);
            // check IborIndexRates
            IborIndexRates test2 = IborIndexRates.of(GBP_LIBOR_3M, DATE_VAL, CURVE);

            assertEquals(test, test2);
        }
        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 bucketedCs01WithNodesIndexTest()
        {
            CurrencyParameterSensitivity fdSingle       = CS01_FD.bucketedCs01(CDS2, RATES_PROVIDER, REF_DATA);
            CurrencyParameterSensitivity analyticSingle = CS01_AN.bucketedCs01(CDS2, RATES_PROVIDER, REF_DATA);
            CurrencyParameterSensitivity fd             = CS01_FD.bucketedCs01(CDS_INDEX, RATES_PROVIDER, REF_DATA);
            CurrencyParameterSensitivity analytic       = CS01_AN.bucketedCs01(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));
        }
        public virtual void test_bondDiscountingProvider()
        {
            ImmutableMap <SecurityId, RepoGroup>               repoSecurityGroups = ImmutableMap.of(SEC_A1, GROUP_REPO_X);
            ImmutableMap <LegalEntityId, RepoGroup>            repoGroups         = ImmutableMap.of(ISSUER_B, GROUP_REPO_X);
            ImmutableMap <Pair <RepoGroup, Currency>, CurveId> repoCurves         = ImmutableMap.of(Pair.of(GROUP_REPO_X, USD), CURVE_ID_USD1);

            ImmutableMap <LegalEntityId, LegalEntityGroup>            issuerGroups = ImmutableMap.of(ISSUER_A, GROUP_ISSUER_M);
            ImmutableMap <Pair <LegalEntityGroup, Currency>, CurveId> issuerCurves = ImmutableMap.of(Pair.of(GROUP_ISSUER_M, USD), CURVE_ID_USD3);

            LegalEntityDiscountingMarketDataLookup test = LegalEntityDiscountingMarketDataLookup.of(repoSecurityGroups, repoGroups, repoCurves, issuerGroups, issuerCurves);
            LocalDate  valDate     = date(2015, 6, 30);
            Curve      repoCurve   = ConstantCurve.of(Curves.discountFactors(CURVE_ID_USD1.CurveName, ACT_360), 1d);
            Curve      issuerCurve = ConstantCurve.of(Curves.discountFactors(CURVE_ID_USD3.CurveName, ACT_360), 2d);
            MarketData md          = ImmutableMarketData.of(valDate, ImmutableMap.of(CURVE_ID_USD1, repoCurve, CURVE_ID_USD3, issuerCurve));
            LegalEntityDiscountingProvider provider = test.discountingProvider(md);

            assertEquals(provider.ValuationDate, valDate);
            assertEquals(provider.findData(CURVE_ID_USD1.CurveName), repoCurve);
            assertEquals(provider.findData(CURVE_ID_USD3.CurveName), issuerCurve);
            assertEquals(provider.findData(CurveName.of("Rubbish")), null);
            // check repo
            RepoCurveDiscountFactors rcdf = provider.repoCurveDiscountFactors(SEC_A1, ISSUER_A, USD);
            SimpleDiscountFactors    rdf  = (SimpleDiscountFactors)rcdf.DiscountFactors;

            assertEquals(rdf.Curve.Name, repoCurve.Name);
            assertEquals(rcdf, provider.repoCurveDiscountFactors(SEC_B1, ISSUER_B, USD));
            assertThrowsIllegalArg(() => provider.repoCurveDiscountFactors(SEC_A1, ISSUER_A, GBP));
            assertThrowsIllegalArg(() => provider.repoCurveDiscountFactors(SEC_C1, ISSUER_C, USD));
            // check issuer
            IssuerCurveDiscountFactors icdf = provider.issuerCurveDiscountFactors(ISSUER_A, USD);
            SimpleDiscountFactors      idf  = (SimpleDiscountFactors)icdf.DiscountFactors;

            assertEquals(idf.Curve.Name, issuerCurve.Name);
            assertThrowsIllegalArg(() => provider.issuerCurveDiscountFactors(ISSUER_A, GBP));
            assertThrowsIllegalArg(() => provider.issuerCurveDiscountFactors(ISSUER_C, USD));
        }
        static SpreadSensitivityCalculatorTest()
        {
            double flatRate = 0.05;
            double t        = 20.0;

            YIELD_CURVE = IsdaCreditDiscountFactors.of(USD, VALUATION_DATE, CurveName.of("discount"), DoubleArray.of(t), DoubleArray.of(flatRate), ACT_365F);
            ImmutableMarketDataBuilder dataBuilder = ImmutableMarketData.builder(VALUATION_DATE);

            ImmutableList.Builder <CdsIsdaCreditCurveNode>         nodesBuilder            = ImmutableList.builder();
            ImmutableList.Builder <ResolvedTradeParameterMetadata> cdsMetadataBuilder      = ImmutableList.builder();
            ImmutableList.Builder <ResolvedTradeParameterMetadata> cdsIndexMetadataBuilder = ImmutableList.builder();
            for (int i = 0; i < NUM_MARKET_CDS; i++)
            {
                QuoteId quoteId             = QuoteId.of(StandardId.of("OG", PAR_SPD_DATES[i].ToString()));
                CdsIsdaCreditCurveNode node = CdsIsdaCreditCurveNode.ofParSpread(DatesCdsTemplate.of(VALUATION_DATE, PAR_SPD_DATES[i], CDS_CONV), quoteId, LEGAL_ENTITY);
                MARKET_CDS[i]       = CdsTrade.builder().product(Cds.of(BUY, LEGAL_ENTITY, USD, NOTIONAL, VALUATION_DATE, PAR_SPD_DATES[i], P3M, SAT_SUN, PAR_SPREADS[i] * ONE_BP)).info(TradeInfo.of(VALUATION_DATE)).build().resolve(REF_DATA);
                MARKET_CDS_INDEX[i] = CdsIndexTrade.builder().product(CdsIndex.of(BuySell.BUY, INDEX_ID, LEGAL_ENTITIES, USD, NOTIONAL, VALUATION_DATE, PAR_SPD_DATES[i], P3M, SAT_SUN, PAR_SPREADS[i] * ONE_BP)).info(TradeInfo.of(VALUATION_DATE)).build().resolve(REF_DATA);
                dataBuilder.addValue(quoteId, PAR_SPREADS[i] * ONE_BP);
                nodesBuilder.add(node);
                cdsMetadataBuilder.add(ResolvedTradeParameterMetadata.of(MARKET_CDS[i], MARKET_CDS[i].Product.ProtectionEndDate.ToString()));
                cdsIndexMetadataBuilder.add(ResolvedTradeParameterMetadata.of(MARKET_CDS_INDEX[i], MARKET_CDS_INDEX[i].Product.ProtectionEndDate.ToString()));
            }
            ImmutableMarketData marketData = dataBuilder.build();
            ImmutableList <CdsIsdaCreditCurveNode> nodes = nodesBuilder.build();

            CDS_METADATA       = cdsMetadataBuilder.build();
            CDS_INDEX_METADATA = cdsIndexMetadataBuilder.build();
            ImmutableCreditRatesProvider rates      = ImmutableCreditRatesProvider.builder().valuationDate(VALUATION_DATE).recoveryRateCurves(ImmutableMap.of(LEGAL_ENTITY, RECOVERY_CURVE)).discountCurves(ImmutableMap.of(USD, YIELD_CURVE)).build();
            IsdaCreditCurveDefinition    definition = IsdaCreditCurveDefinition.of(CREDIT_CURVE_NAME, USD, VALUATION_DATE, ACT_365F, nodes, true, true);

            CREDIT_CURVE = BUILDER.calibrate(definition, marketData, rates, REF_DATA);
            NodalCurve underlyingCurve = ((IsdaCreditDiscountFactors)CREDIT_CURVE.SurvivalProbabilities).Curve;
            NodalCurve curveWithFactor = underlyingCurve.withMetadata(underlyingCurve.Metadata.withInfo(CurveInfoType.CDS_INDEX_FACTOR, INDEX_FACTOR).withParameterMetadata(CDS_INDEX_METADATA));     // replace parameter metadata

            CREDIT_CURVE_INDEX = LegalEntitySurvivalProbabilities.of(INDEX_ID, IsdaCreditDiscountFactors.of(USD, VALUATION_DATE, curveWithFactor));
        }
Пример #17
0
        static CreditDataSet()
        {
            ImmutableList.Builder <StandardId> builder = ImmutableList.builder();
            for (int i = 0; i < 97; ++i)
            {
                builder.add(StandardId.of("OG", i.ToString()));
            }
            LEGAL_ENTITIES = builder.build();
            double flatRate = 0.05;
            double t        = 20.0;
            IsdaCreditDiscountFactors yieldCurve = IsdaCreditDiscountFactors.of(USD, VALUATION_DATE, CurveName.of("discount"), DoubleArray.of(t), DoubleArray.of(flatRate), ACT_365F);

            DISCOUNT_CURVE = yieldCurve.Curve;
            RecoveryRates recoveryRate = ConstantRecoveryRates.of(LEGAL_ENTITY, VALUATION_DATE, RECOVERY_RATE);
            // create the curve nodes and input market quotes
            ImmutableMarketDataBuilder marketQuoteBuilder = ImmutableMarketData.builder(VALUATION_DATE);

            ImmutableList.Builder <CdsIsdaCreditCurveNode>         nodesBuilder            = ImmutableList.builder();
            ImmutableList.Builder <ResolvedTradeParameterMetadata> cdsMetadataBuilder      = ImmutableList.builder();
            ImmutableList.Builder <ResolvedTradeParameterMetadata> cdsIndexMetadataBuilder = ImmutableList.builder();
            for (int i = 0; i < NUM_MARKET_CDS; i++)
            {
                QuoteId quoteId             = QuoteId.of(StandardId.of("OG", PAR_SPD_DATES[i].ToString()));
                CdsIsdaCreditCurveNode node = CdsIsdaCreditCurveNode.ofParSpread(DatesCdsTemplate.of(VALUATION_DATE, PAR_SPD_DATES[i], CDS_CONV), quoteId, LEGAL_ENTITY);
                MARKET_CDS[i]       = CdsTrade.builder().product(Cds.of(BUY, LEGAL_ENTITY, USD, NOTIONAL, VALUATION_DATE, PAR_SPD_DATES[i], P3M, SAT_SUN, PAR_SPREADS[i] * ONE_BP)).info(TradeInfo.of(VALUATION_DATE)).build().resolve(REF_DATA);
                MARKET_CDS_INDEX[i] = CdsIndexTrade.builder().product(CdsIndex.of(BuySell.BUY, INDEX_ID, LEGAL_ENTITIES, USD, NOTIONAL, VALUATION_DATE, PAR_SPD_DATES[i], P3M, SAT_SUN, PAR_SPREADS[i] * ONE_BP)).info(TradeInfo.of(VALUATION_DATE)).build().resolve(REF_DATA);
                marketQuoteBuilder.addValue(quoteId, PAR_SPREADS[i] * ONE_BP);
                nodesBuilder.add(node);
                cdsMetadataBuilder.add(ResolvedTradeParameterMetadata.of(MARKET_CDS[i], MARKET_CDS[i].Product.ProtectionEndDate.ToString()));
                cdsIndexMetadataBuilder.add(ResolvedTradeParameterMetadata.of(MARKET_CDS_INDEX[i], MARKET_CDS_INDEX[i].Product.ProtectionEndDate.ToString()));
            }
            ImmutableMarketData marketQuotes             = marketQuoteBuilder.build();
            ImmutableList <CdsIsdaCreditCurveNode> nodes = nodesBuilder.build();

            CDS_METADATA       = cdsMetadataBuilder.build();
            CDS_INDEX_METADATA = cdsIndexMetadataBuilder.build();
            ImmutableCreditRatesProvider rates      = ImmutableCreditRatesProvider.builder().valuationDate(VALUATION_DATE).recoveryRateCurves(ImmutableMap.of(LEGAL_ENTITY, recoveryRate)).discountCurves(ImmutableMap.of(USD, yieldCurve)).build();
            IsdaCreditCurveDefinition    definition = IsdaCreditCurveDefinition.of(CREDIT_CURVE_NAME, USD, VALUATION_DATE, ACT_365F, nodes, true, true);
            // calibrate
            LegalEntitySurvivalProbabilities calibrated = BUILDER.calibrate(definition, marketQuotes, rates, REF_DATA);
            NodalCurve underlyingCurve = ((IsdaCreditDiscountFactors)calibrated.SurvivalProbabilities).Curve;

            CDS_CREDIT_CURVE    = underlyingCurve;
            INDEX_CREDIT_CURVE  = underlyingCurve.withMetadata(underlyingCurve.Metadata.withInfo(CurveInfoType.CDS_INDEX_FACTOR, INDEX_FACTOR).withParameterMetadata(CDS_INDEX_METADATA));    // replace parameter metadata
            CDS_RECOVERY_RATE   = ConstantCurve.of(Curves.recoveryRates("CDS recovery rate", ACT_365F), RECOVERY_RATE);
            INDEX_RECOVERY_RATE = ConstantCurve.of(Curves.recoveryRates("Index recovery rate", ACT_365F), RECOVERY_RATE);
        }
        public virtual void formatForDisplay()
        {
            CurrencyParameterSensitivity sensitivity = CurrencyParameterSensitivity.of(CurveName.of("foo"), Currency.AED, DoubleArray.of(1, 2, 3));
            string str = CurrencyParameterSensitivityValueFormatter.INSTANCE.formatForDisplay(sensitivity);

            assertThat(str).isEqualTo("1 = 1.00        | 2 = 2.00        | 3 = 3.00       ");
        }
        public virtual void formatForCsv()
        {
            CurrencyParameterSensitivity sensitivity = CurrencyParameterSensitivity.of(CurveName.of("foo"), Currency.AED, DoubleArray.of(10, 20, 30));
            string str = CurrencyParameterSensitivityValueFormatter.INSTANCE.formatForCsv(sensitivity);

            assertThat(str).isEqualTo("1 = 10 | 2 = 20 | 3 = 30");
        }