Example #1
0
        //-------------------------------------------------------------------------
        // creates a simple provider
        private SimpleRatesProvider createProvider(LocalDate valDate)
        {
            Curve               curve = ConstantCurve.of(Curves.discountFactors("Test", DAY_COUNT), DISCOUNT_FACTOR);
            DiscountFactors     df    = SimpleDiscountFactors.of(GBP, valDate, curve);
            SimpleRatesProvider prov  = new SimpleRatesProvider(valDate);

            prov.DayCount        = DAY_COUNT;
            prov.DiscountFactors = df;
            return(prov);
        }
        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));
        }