예제 #1
0
        /// <summary>
        /// Test that inputs are correctly built from market data.
        /// </summary>
        public virtual void build()
        {
            FraCurveNode node1x4 = fraNode(1, "a");
            FraCurveNode node2x5 = fraNode(2, "b");
            FraCurveNode node3x6 = fraNode(3, "c");

            InterpolatedNodalCurveDefinition curveDefn = InterpolatedNodalCurveDefinition.builder().name(CurveName.of("curve")).xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.ZERO_RATE).dayCount(DayCounts.ACT_ACT_ISDA).interpolator(CurveInterpolators.DOUBLE_QUADRATIC).extrapolatorLeft(CurveExtrapolators.FLAT).extrapolatorRight(CurveExtrapolators.FLAT).nodes(node1x4, node2x5, node3x6).build();

            RatesCurveGroupDefinition groupDefn = RatesCurveGroupDefinition.builder().name(CurveGroupName.of("curve group")).addDiscountCurve(curveDefn, Currency.USD).build();

            MarketDataConfig marketDataConfig = MarketDataConfig.builder().add(groupDefn.Name, groupDefn).build();

            QuoteId idA = QuoteId.of(StandardId.of("test", "a"));
            QuoteId idB = QuoteId.of(StandardId.of("test", "b"));
            QuoteId idC = QuoteId.of(StandardId.of("test", "c"));

            ScenarioMarketData marketData = ImmutableScenarioMarketData.builder(VAL_DATE).addValue(idA, 1d).addValue(idB, 2d).addValue(idC, 3d).build();

            RatesCurveInputsMarketDataFunction marketDataFunction = new RatesCurveInputsMarketDataFunction();
            RatesCurveInputsId curveInputsId        = RatesCurveInputsId.of(groupDefn.Name, curveDefn.Name, ObservableSource.NONE);
            MarketDataBox <RatesCurveInputs> result = marketDataFunction.build(curveInputsId, marketDataConfig, marketData, REF_DATA);

            RatesCurveInputs curveInputs = result.SingleValue;

            assertThat(curveInputs.MarketData.get(idA)).isEqualTo(1d);
            assertThat(curveInputs.MarketData.get(idB)).isEqualTo(2d);
            assertThat(curveInputs.MarketData.get(idC)).isEqualTo(3d);

            IList <ParameterMetadata> expectedMetadata = ImmutableList.of(node1x4.metadata(VAL_DATE, REF_DATA), node2x5.metadata(VAL_DATE, REF_DATA), node3x6.metadata(VAL_DATE, REF_DATA));

            assertThat(curveInputs.CurveMetadata.ParameterMetadata).hasValue(expectedMetadata);
        }
예제 #2
0
        /// <summary>
        /// Test that an exception is thrown if there is no curve group configuration corresponding to the ID
        /// </summary>
        public virtual void requirementsMissingGroupConfig()
        {
            RatesCurveInputsMarketDataFunction marketDataFunction = new RatesCurveInputsMarketDataFunction();
            RatesCurveInputsId curveInputsId = RatesCurveInputsId.of(CurveGroupName.of("curve group"), CurveName.of("curve"), ObservableSource.NONE);

            assertThrowsIllegalArg(() => marketDataFunction.requirements(curveInputsId, MarketDataConfig.empty()));
        }
예제 #3
0
        /// <summary>
        /// Test that a failure is returned if there is no config for the curve group.
        /// </summary>
        public virtual void buildMissingGroupConfig()
        {
            RatesCurveInputsMarketDataFunction marketDataFunction = new RatesCurveInputsMarketDataFunction();
            RatesCurveInputsId curveInputsId = RatesCurveInputsId.of(CurveGroupName.of("curve group"), CurveName.of("curve"), ObservableSource.NONE);
            ScenarioMarketData emptyData     = ScenarioMarketData.empty();

            assertThrows(() => marketDataFunction.build(curveInputsId, MarketDataConfig.empty(), emptyData, REF_DATA), typeof(System.ArgumentException), "No configuration found for type .*");
        }
예제 #4
0
        /// <summary>
        /// Test that requirements are empty if the curve group config exists but not the curve
        /// </summary>
        public virtual void requirementsMissingCurveDefinition()
        {
            RatesCurveInputsMarketDataFunction marketDataFunction = new RatesCurveInputsMarketDataFunction();
            RatesCurveInputsId        curveInputsId    = RatesCurveInputsId.of(CurveGroupName.of("curve group"), CurveName.of("curve"), ObservableSource.NONE);
            RatesCurveGroupDefinition groupDefn        = RatesCurveGroupDefinition.builder().name(CurveGroupName.of("curve group")).build();
            MarketDataConfig          marketDataConfig = MarketDataConfig.builder().add(groupDefn.Name, groupDefn).build();
            MarketDataRequirements    requirements     = marketDataFunction.requirements(curveInputsId, marketDataConfig);

            assertThat(requirements.Observables).Empty;
        }
예제 #5
0
        /// <summary>
        /// Test that a failure is returned if there is config for the curve group but it doesn't contain the named curve.
        /// </summary>
        public virtual void buildMissingCurveDefinition()
        {
            RatesCurveInputsMarketDataFunction marketDataFunction = new RatesCurveInputsMarketDataFunction();
            RatesCurveInputsId        curveInputsId    = RatesCurveInputsId.of(CurveGroupName.of("curve group"), CurveName.of("curve"), ObservableSource.NONE);
            RatesCurveGroupDefinition groupDefn        = RatesCurveGroupDefinition.builder().name(CurveGroupName.of("curve group")).build();
            MarketDataConfig          marketDataConfig = MarketDataConfig.builder().add(groupDefn.Name, groupDefn).build();
            ScenarioMarketData        emptyData        = ScenarioMarketData.empty();

            assertThrows(() => marketDataFunction.build(curveInputsId, marketDataConfig, emptyData, REF_DATA), typeof(System.ArgumentException), "No curve named .*");
        }
예제 #6
0
        /// <summary>
        /// Test that the curve node requirements are extracted and returned.
        /// </summary>
        public virtual void requirements()
        {
            FraCurveNode node1x4 = fraNode(1, "a");
            FraCurveNode node2x5 = fraNode(2, "b");
            FraCurveNode node3x6 = fraNode(3, "c");

            InterpolatedNodalCurveDefinition curve = InterpolatedNodalCurveDefinition.builder().name(CurveName.of("curve")).interpolator(CurveInterpolators.DOUBLE_QUADRATIC).extrapolatorLeft(CurveExtrapolators.FLAT).extrapolatorRight(CurveExtrapolators.FLAT).nodes(node1x4, node2x5, node3x6).build();

            RatesCurveGroupDefinition groupDefn = RatesCurveGroupDefinition.builder().name(CurveGroupName.of("curve group")).addDiscountCurve(curve, Currency.USD).build();

            MarketDataConfig marketDataConfig = MarketDataConfig.builder().add(groupDefn.Name, groupDefn).build();

            RatesCurveInputsMarketDataFunction marketDataFunction = new RatesCurveInputsMarketDataFunction();
            RatesCurveInputsId     curveInputsId = RatesCurveInputsId.of(groupDefn.Name, curve.Name, ObservableSource.NONE);
            MarketDataRequirements requirements  = marketDataFunction.requirements(curveInputsId, marketDataConfig);

            assertThat(requirements.Observables).contains(QuoteId.of(StandardId.of("test", "a"))).contains(QuoteId.of(StandardId.of("test", "b"))).contains(QuoteId.of(StandardId.of("test", "c")));
        }
예제 #7
0
        /// <summary>
        /// Test that a failure is returned if the observable data isn't available.
        /// </summary>
        public virtual void buildMissingMarketData()
        {
            FraCurveNode node1x4 = fraNode(1, "a");
            FraCurveNode node2x5 = fraNode(2, "b");
            FraCurveNode node3x6 = fraNode(3, "c");

            InterpolatedNodalCurveDefinition curve = InterpolatedNodalCurveDefinition.builder().name(CurveName.of("curve")).interpolator(CurveInterpolators.DOUBLE_QUADRATIC).extrapolatorLeft(CurveExtrapolators.FLAT).extrapolatorRight(CurveExtrapolators.FLAT).nodes(node1x4, node2x5, node3x6).build();

            RatesCurveGroupDefinition groupDefn = RatesCurveGroupDefinition.builder().name(CurveGroupName.of("curve group")).addDiscountCurve(curve, Currency.USD).build();

            MarketDataConfig marketDataConfig = MarketDataConfig.builder().add(groupDefn.Name, groupDefn).build();

            ScenarioMarketData emptyData = ScenarioMarketData.of(1, date(2016, 6, 30), ImmutableMap.of(), ImmutableMap.of());

            RatesCurveInputsMarketDataFunction marketDataFunction = new RatesCurveInputsMarketDataFunction();
            RatesCurveInputsId curveInputsId = RatesCurveInputsId.of(groupDefn.Name, curve.Name, ObservableSource.NONE);

            assertThrows(() => marketDataFunction.build(curveInputsId, marketDataConfig, emptyData, REF_DATA), typeof(MarketDataNotFoundException));
        }
예제 #8
0
        // one valuation date, scenario market data
        private MarketDataBox <RatesCurveInputs> buildMultipleCurveInputs <T1>(MarketDataBox <CurveDefinition> filteredDefns, IDictionary <T1> marketData, MarketDataBox <LocalDate> valuationDates, ReferenceData refData) where T1 : com.opengamma.strata.data.MarketDataId <T1>
        {
            // If there are multiple values for any of the input data values or for the valuation
            // dates then we need to create multiple sets of inputs
            int scenarioCount = RatesCurveInputsMarketDataFunction.scenarioCount(valuationDates, marketData);

            ImmutableList.Builder <CurveMetadata> curveMetadataBuilder = ImmutableList.builder();
            for (int i = 0; i < scenarioCount; i++)
            {
                LocalDate       valDate = valuationDates.getValue(i);
                CurveDefinition defn    = filteredDefns.getValue(i);
                curveMetadataBuilder.add(defn.metadata(valDate, refData));
            }
            IList <CurveMetadata> curveMetadata = curveMetadataBuilder.build();

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.List<java.util.Map<? extends com.opengamma.strata.data.MarketDataId<?>, ?>> scenarioValues = java.util.stream.IntStream.range(0, scenarioCount).mapToObj(i -> buildScenarioValues(marketData, i)).collect(toImmutableList());
            IList <IDictionary <MarketDataId <object>, ?> > scenarioValues = IntStream.range(0, scenarioCount).mapToObj(i => buildScenarioValues(marketData, i)).collect(toImmutableList());

            IList <RatesCurveInputs> curveInputs = zip(scenarioValues.stream(), curveMetadata.stream()).map(pair => RatesCurveInputs.of(pair.First, pair.Second)).collect(toImmutableList());

            return(MarketDataBox.ofScenarioValues(curveInputs));
        }