public virtual void stream()
        {
            RatesCurveGroup test     = RatesCurveGroup.of(NAME, DISCOUNT_CURVES, IBOR_CURVES);
            IList <Curve>   expected = ImmutableList.builder <Curve>().addAll(DISCOUNT_CURVES.Values).addAll(IBOR_CURVES.Values).build();

            assertThat(test.ToList()).containsOnlyElementsOf(expected);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a curve group using a curve group definition and a list of existing curves.
        /// <para>
        /// If there are curves named in the definition which are not present in the curves the group is built using
        /// whatever curves are available.
        /// </para>
        /// <para>
        /// If there are multiple curves with the same name in the curves one of them is arbitrarily chosen.
        /// </para>
        /// <para>
        /// Multiple curves with the same name are allowed to support the use case where the list contains the same
        /// curve multiple times. This means the caller doesn't have to filter the input curves to remove duplicates.
        ///
        /// </para>
        /// </summary>
        /// <param name="curveGroupDefinition">  the definition of a curve group </param>
        /// <param name="curves">  some curves </param>
        /// <returns> a curve group built from the definition and the list of curves </returns>
        public static RatesCurveGroup ofCurves <T1>(RatesCurveGroupDefinition curveGroupDefinition, ICollection <T1> curves) where T1 : Curve
        {
            IDictionary <Currency, Curve>  discountCurves = new Dictionary <Currency, Curve>();
            IDictionary <Index, Curve>     forwardCurves  = new Dictionary <Index, Curve>();
            IDictionary <CurveName, Curve> curveMap       = curves.ToDictionary(curve => curve.Metadata.CurveName, curve => curve, (curve1, curve2) => curve1);

            foreach (RatesCurveGroupEntry entry in curveGroupDefinition.Entries)
            {
                CurveName curveName = entry.CurveName;
                Curve     curve     = curveMap[curveName];

                if (curve == null)
                {
                    log.debug("No curve found named '{}' when building curve group '{}'", curveName, curveGroupDefinition.Name);
                    continue;
                }
                foreach (Currency currency in entry.DiscountCurrencies)
                {
                    discountCurves[currency] = curve;
                }
                foreach (Index index in entry.Indices)
                {
                    forwardCurves[index] = curve;
                }
            }
            return(RatesCurveGroup.of(curveGroupDefinition.Name, discountCurves, forwardCurves));
        }
        public virtual void test_ofCurves_duplicateCurveName()
        {
            RatesCurveGroupDefinition definition = RatesCurveGroupDefinition.builder().name(CurveGroupName.of("group")).addForwardCurve(IBOR_NAME, USD_LIBOR_1M, USD_LIBOR_2M).build();
            RatesCurveGroup           group      = RatesCurveGroup.ofCurves(definition, IBOR_CURVE, IBOR_CURVE);

            assertThat(group.findForwardCurve(USD_LIBOR_1M)).hasValue(IBOR_CURVE);
            assertThat(group.findForwardCurve(USD_LIBOR_2M)).hasValue(IBOR_CURVE);
        }
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            RatesCurveGroup test = RatesCurveGroup.of(NAME, DISCOUNT_CURVES, IBOR_CURVES);

            coverImmutableBean(test);
            RatesCurveGroup test2 = RatesCurveGroup.of(NAME2, ImmutableMap.of(), ImmutableMap.of());

            coverBeanEquals(test, test2);
        }
        public virtual void test_ofCurves()
        {
            RatesCurveGroupDefinition definition = RatesCurveGroupDefinition.builder().name(CurveGroupName.of("group")).addCurve(DISCOUNT_NAME, GBP, GBP_LIBOR_1M).addForwardCurve(IBOR_NAME, USD_LIBOR_1M, USD_LIBOR_2M).addForwardCurve(OVERNIGHT_NAME, EUR_EONIA).build();
            RatesCurveGroup           group      = RatesCurveGroup.ofCurves(definition, DISCOUNT_CURVE, OVERNIGHT_CURVE, IBOR_CURVE);

            assertThat(group.findDiscountCurve(GBP)).hasValue(DISCOUNT_CURVE);
            assertThat(group.findForwardCurve(USD_LIBOR_1M)).hasValue(IBOR_CURVE);
            assertThat(group.findForwardCurve(USD_LIBOR_2M)).hasValue(IBOR_CURVE);
            assertThat(group.findForwardCurve(EUR_EONIA)).hasValue(OVERNIGHT_CURVE);
        }
        public virtual void test_builder()
        {
            RatesCurveGroup test = RatesCurveGroup.builder().name(NAME).discountCurves(DISCOUNT_CURVES).forwardCurves(IBOR_CURVES).build();

            assertThat(test.Name).isEqualTo(NAME);
            assertThat(test.DiscountCurves).isEqualTo(DISCOUNT_CURVES);
            assertThat(test.ForwardCurves).isEqualTo(IBOR_CURVES);
            assertThat(test.findDiscountCurve(GBP)).hasValue(DISCOUNT_CURVE);
            assertThat(test.findDiscountCurve(USD)).Empty;
            assertThat(test.findForwardCurve(GBP_LIBOR_3M)).hasValue(IBOR_CURVE);
            assertThat(test.findForwardCurve(CHF_LIBOR_3M)).Empty;
        }
        //-------------------------------------------------------------------------
        public virtual void test_of()
        {
            RatesCurveGroup test = RatesCurveGroup.of(NAME, DISCOUNT_CURVES, IBOR_CURVES);

            assertThat(test.Name).isEqualTo(NAME);
            assertThat(test.DiscountCurves).isEqualTo(DISCOUNT_CURVES);
            assertThat(test.ForwardCurves).isEqualTo(IBOR_CURVES);
            assertThat(test.findCurve(DISCOUNT_NAME)).hasValue(DISCOUNT_CURVE);
            assertThat(test.findCurve(IBOR_NAME)).hasValue(IBOR_CURVE);
            assertThat(test.findCurve(OVERNIGHT_NAME)).Empty;
            assertThat(test.findDiscountCurve(GBP)).hasValue(DISCOUNT_CURVE);
            assertThat(test.findDiscountCurve(USD)).Empty;
            assertThat(test.findForwardCurve(GBP_LIBOR_3M)).hasValue(IBOR_CURVE);
            assertThat(test.findForwardCurve(CHF_LIBOR_3M)).Empty;
        }
        public virtual void test_serialization()
        {
            RatesCurveGroup test = RatesCurveGroup.of(NAME, DISCOUNT_CURVES, IBOR_CURVES);

            assertSerialization(test);
        }