Exemplo n.º 1
0
        /// <summary>
        /// End-to-end test for curve calibration and round-tripping that uses the <seealso cref="MarketDataFactory"/>
        /// to calibrate a curve and calculate PVs for the instruments at the curve nodes.
        ///
        /// This tests the full pipeline of market data functions:
        ///   - Par rates
        ///   - Curve group (including calibration)
        ///   - Individual curves
        ///   - Discount factors
        /// </summary>
        public virtual void roundTripFraAndFixedFloatSwap()
        {
            // Configuration and market data for the curve ---------------------------------

            string fra3x6 = "fra3x6";
            string fra6x9 = "fra6x9";
            string swap1y = "swap1y";
            string swap2y = "swap2y";
            string swap3y = "swap3y";

            FraCurveNode           fra3x6Node = fraNode(3, fra3x6);
            FraCurveNode           fra6x9Node = fraNode(6, fra6x9);
            FixedIborSwapCurveNode swap1yNode = fixedIborSwapNode(Tenor.TENOR_1Y, swap1y);
            FixedIborSwapCurveNode swap2yNode = fixedIborSwapNode(Tenor.TENOR_2Y, swap2y);
            FixedIborSwapCurveNode swap3yNode = fixedIborSwapNode(Tenor.TENOR_3Y, swap3y);

            IDictionary <ObservableId, double> parRateData = ImmutableMap.builder <ObservableId, double>().put(id(fra3x6), 0.0037).put(id(fra6x9), 0.0054).put(id(swap1y), 0.005).put(id(swap2y), 0.0087).put(id(swap3y), 0.012).build();

            LocalDate valuationDate = date(2011, 3, 8);

            // Build the trades from the node instruments
            MarketData quotes      = ImmutableMarketData.of(valuationDate, parRateData);
            Trade      fra3x6Trade = fra3x6Node.trade(1d, quotes, REF_DATA);
            Trade      fra6x9Trade = fra6x9Node.trade(1d, quotes, REF_DATA);
            Trade      swap1yTrade = swap1yNode.trade(1d, quotes, REF_DATA);
            Trade      swap2yTrade = swap2yNode.trade(1d, quotes, REF_DATA);
            Trade      swap3yTrade = swap3yNode.trade(1d, quotes, REF_DATA);

            IList <Trade> trades = ImmutableList.of(fra3x6Trade, fra6x9Trade, swap1yTrade, swap2yTrade, swap3yTrade);

            IList <CurveNode> nodes     = ImmutableList.of(fra3x6Node, fra6x9Node, swap1yNode, swap2yNode, swap3yNode);
            CurveGroupName    groupName = CurveGroupName.of("Curve Group");
            CurveName         curveName = CurveName.of("FRA and Fixed-Float Swap Curve");

            InterpolatedNodalCurveDefinition curveDefn = InterpolatedNodalCurveDefinition.builder().name(curveName).xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.ZERO_RATE).dayCount(DayCounts.ACT_ACT_ISDA).nodes(nodes).interpolator(CurveInterpolators.DOUBLE_QUADRATIC).extrapolatorLeft(CurveExtrapolators.FLAT).extrapolatorRight(CurveExtrapolators.FLAT).build();

            RatesCurveGroupDefinition groupDefn = RatesCurveGroupDefinition.builder().name(groupName).addCurve(curveDefn, Currency.USD, IborIndices.USD_LIBOR_3M).build();

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

            // Rules for market data and calculations ---------------------------------

            RatesMarketDataLookup ratesLookup      = RatesMarketDataLookup.of(groupDefn);
            CalculationRules      calculationRules = CalculationRules.of(functions(), Currency.USD, ratesLookup);

            // Calculate the results and check the PVs for the node instruments are zero ----------------------

            IList <Column> columns         = ImmutableList.of(Column.of(Measures.PRESENT_VALUE));
            MarketData     knownMarketData = MarketData.of(date(2011, 3, 8), parRateData);

            // using the direct executor means there is no need to close/shutdown the runner
            CalculationTasks       tasks = CalculationTasks.of(calculationRules, trades, columns, REF_DATA);
            MarketDataRequirements reqs  = tasks.requirements(REF_DATA);
            MarketData             enhancedMarketData = marketDataFactory().create(reqs, marketDataConfig, knownMarketData, REF_DATA);
            CalculationTaskRunner  runner             = CalculationTaskRunner.of(MoreExecutors.newDirectExecutorService());
            Results results = runner.calculate(tasks, enhancedMarketData, REF_DATA);

            results.Cells.ForEach(this.checkPvIsZero);
        }
        //-------------------------------------------------------------------------
        public virtual FunctionRequirements requirements(FxSingleTrade trade, ISet <Measure> measures, CalculationParameters parameters, ReferenceData refData)
        {
            // extract data from product
            ImmutableSet <Currency> currencies = trade.Product.CurrencyPair.toSet();

            // use lookup to build requirements
            RatesMarketDataLookup ratesLookup = parameters.getParameter(typeof(RatesMarketDataLookup));

            return(ratesLookup.requirements(currencies));
        }
        //-------------------------------------------------------------------------
        public virtual FunctionRequirements requirements(BulletPaymentTrade trade, ISet <Measure> measures, CalculationParameters parameters, ReferenceData refData)
        {
            // extract data from product
            BulletPayment product  = trade.Product;
            Currency      currency = product.Currency;

            // use lookup to build requirements
            RatesMarketDataLookup ratesLookup = parameters.getParameter(typeof(RatesMarketDataLookup));

            return(ratesLookup.requirements(currency));
        }
        //-------------------------------------------------------------------------
        public virtual FunctionRequirements requirements(SwapTrade trade, ISet <Measure> measures, CalculationParameters parameters, ReferenceData refData)
        {
            // extract data from product
            Swap product = trade.Product;
            ImmutableSet <Currency> currencies = product.allPaymentCurrencies();

            // use lookup to build requirements
            RatesMarketDataLookup ratesLookup = parameters.getParameter(typeof(RatesMarketDataLookup));

            return(ratesLookup.requirements(currencies, product.allIndices()));
        }
Exemplo n.º 5
0
        //-------------------------------------------------------------------------
        public virtual FunctionRequirements requirements(FxNdfTrade trade, ISet <Measure> measures, CalculationParameters parameters, ReferenceData refData)
        {
            // extract data from product
            FxNdf    fx                        = trade.Product;
            Currency settleCurrency            = fx.SettlementCurrency;
            Currency otherCurrency             = fx.NonDeliverableCurrency;
            ImmutableSet <Currency> currencies = ImmutableSet.of(settleCurrency, otherCurrency);

            // use lookup to build requirements
            RatesMarketDataLookup ratesLookup = parameters.getParameter(typeof(RatesMarketDataLookup));

            return(ratesLookup.requirements(currencies));
        }
        public virtual void test_fxProvider()
        {
            RatesMarketDataLookup test    = RatesMarketDataLookup.of(ImmutableMap.of(), ImmutableMap.of());
            LocalDate             valDate = date(2015, 6, 30);
            FxRateId       gbpUsdId       = FxRateId.of(GBP, USD);
            FxRate         gbpUsdRate     = FxRate.of(GBP, USD, 1.6);
            MarketData     md             = ImmutableMarketData.of(valDate, ImmutableMap.of(gbpUsdId, gbpUsdRate));
            FxRateProvider fxProvider     = test.fxRateProvider(md);

            assertEquals(fxProvider.fxRate(GBP, USD), 1.6);
            assertEquals(test.marketDataView(md).fxRateProvider().fxRate(GBP, USD), 1.6);
            assertThrows(() => fxProvider.fxRate(EUR, USD), typeof(MarketDataNotFoundException));
        }
        public virtual void test_of_groupNameAndMap()
        {
            ImmutableMap <Currency, CurveName> discounts = ImmutableMap.of(USD, CURVE_ID_DSC.CurveName);
            ImmutableMap <Index, CurveName>    forwards  = ImmutableMap.of(USD_LIBOR_3M, CURVE_ID_FWD.CurveName);
            RatesMarketDataLookup test = RatesMarketDataLookup.of(CURVE_ID_DSC.CurveGroupName, discounts, forwards);

            assertEquals(test.queryType(), typeof(RatesMarketDataLookup));
            assertEquals(test.DiscountCurrencies, ImmutableSet.of(USD));
            assertEquals(test.getDiscountMarketDataIds(USD), ImmutableSet.of(CURVE_ID_DSC));
            assertEquals(test.ForwardIndices, ImmutableSet.of(USD_LIBOR_3M));
            assertEquals(test.getForwardMarketDataIds(USD_LIBOR_3M), ImmutableSet.of(CURVE_ID_FWD));
            assertThrowsIllegalArg(() => test.getDiscountMarketDataIds(GBP));
            assertThrowsIllegalArg(() => test.getForwardMarketDataIds(GBP_LIBOR_3M));
        }
        //-------------------------------------------------------------------------
        public virtual FunctionRequirements requirements(FxSingleBarrierOptionTrade trade, ISet <Measure> measures, CalculationParameters parameters, ReferenceData refData)
        {
            // extract data from product
            FxSingleBarrierOption product      = trade.Product;
            CurrencyPair          currencyPair = product.CurrencyPair;

            // use lookup to build requirements
            RatesMarketDataLookup    ratesLookup  = parameters.getParameter(typeof(RatesMarketDataLookup));
            FunctionRequirements     ratesReqs    = ratesLookup.requirements(ImmutableSet.of(currencyPair.Base, currencyPair.Counter));
            FxOptionMarketDataLookup optionLookup = parameters.getParameter(typeof(FxOptionMarketDataLookup));
            FunctionRequirements     optionReqs   = optionLookup.requirements(currencyPair);

            return(ratesReqs.combinedWith(optionReqs));
        }
        // obtains the data and calculates the grid of results
        private static void calculate(CalculationRunner runner)
        {
            // the trades that will have measures calculated
            IList <Trade> trades = createSwapTrades();

            // the columns, specifying the measures to be calculated
            IList <Column> columns = ImmutableList.of(Column.of(Measures.PRESENT_VALUE), Column.of(Measures.PAR_RATE), Column.of(Measures.PV01_MARKET_QUOTE_BUCKETED), Column.of(Measures.PV01_CALIBRATED_BUCKETED));

            // load quotes
            ImmutableMap <QuoteId, double> quotesCcp1 = QuotesCsvLoader.load(VAL_DATE, QUOTES_RESOURCE_CCP1);
            ImmutableMap <QuoteId, double> quotesCcp2 = QuotesCsvLoader.load(VAL_DATE, QUOTES_RESOURCE_CCP2);

            // load fixings
            ImmutableMap <ObservableId, LocalDateDoubleTimeSeries> fixings = FixingSeriesCsvLoader.load(FIXINGS_RESOURCE);

            // create the market data
            MarketData marketData = ImmutableMarketData.builder(VAL_DATE).addValueMap(quotesCcp1).addValueMap(quotesCcp2).addTimeSeriesMap(fixings).build();

            // the reference data, such as holidays and securities
            ReferenceData refData = ReferenceData.standard();

            // load the curve definition
            IDictionary <CurveGroupName, RatesCurveGroupDefinition> defnsCcp1 = RatesCalibrationCsvLoader.load(GROUPS_RESOURCE_CCP1, SETTINGS_RESOURCE_CCP1, CALIBRATION_RESOURCE_CCP1);
            IDictionary <CurveGroupName, RatesCurveGroupDefinition> defnsCcp2 = RatesCalibrationCsvLoader.load(GROUPS_RESOURCE_CCP2, SETTINGS_RESOURCE_CCP2, CALIBRATION_RESOURCE_CCP2);
            RatesCurveGroupDefinition curveGroupDefinitionCcp1 = defnsCcp1[CURVE_GROUP_NAME_CCP1].filtered(VAL_DATE, refData);
            RatesCurveGroupDefinition curveGroupDefinitionCcp2 = defnsCcp2[CURVE_GROUP_NAME_CCP2].filtered(VAL_DATE, refData);

            // the configuration that defines how to create the curves when a curve group is requested
            MarketDataConfig marketDataConfig = MarketDataConfig.builder().add(CURVE_GROUP_NAME_CCP1, curveGroupDefinitionCcp1).add(CURVE_GROUP_NAME_CCP2, curveGroupDefinitionCcp2).build();

            // the complete set of rules for calculating measures
            CalculationFunctions  functions       = StandardComponents.calculationFunctions();
            RatesMarketDataLookup ratesLookupCcp1 = RatesMarketDataLookup.of(curveGroupDefinitionCcp1);
            RatesMarketDataLookup ratesLookupCcp2 = RatesMarketDataLookup.of(curveGroupDefinitionCcp2);
            // choose RatesMarketDataLookup instance based on counterparty
            TradeCounterpartyCalculationParameter perCounterparty = TradeCounterpartyCalculationParameter.of(ImmutableMap.of(CCP1_ID, ratesLookupCcp1, CCP2_ID, ratesLookupCcp2), ratesLookupCcp1);
            CalculationRules rules = CalculationRules.of(functions, perCounterparty);

            // calibrate the curves and calculate the results
            MarketDataRequirements reqs = MarketDataRequirements.of(rules, trades, columns, refData);
            MarketData             calibratedMarketData = marketDataFactory().create(reqs, marketDataConfig, marketData, refData);
            Results results = runner.calculate(rules, trades, columns, calibratedMarketData, refData);

            // use the report runner to transform the engine results into a trade report
            ReportCalculationResults calculationResults = ReportCalculationResults.of(VAL_DATE, trades, columns, results, functions, refData);
            TradeReportTemplate      reportTemplate     = ExampleData.loadTradeReportTemplate("swap-report-template2");
            TradeReport tradeReport = TradeReport.of(calculationResults, reportTemplate);

            tradeReport.writeAsciiTable(System.out);
        }
        //-------------------------------------------------------------------------
        public virtual FunctionRequirements requirements(SwaptionTrade trade, ISet <Measure> measures, CalculationParameters parameters, ReferenceData refData)
        {
            // extract data from product
            Swaption  product  = trade.Product;
            Currency  currency = product.Currency;
            IborIndex index    = product.Index;

            // use lookup to build requirements
            RatesMarketDataLookup    ratesLookup    = parameters.getParameter(typeof(RatesMarketDataLookup));
            FunctionRequirements     ratesReqs      = ratesLookup.requirements(currency, index);
            SwaptionMarketDataLookup swaptionLookup = parameters.getParameter(typeof(SwaptionMarketDataLookup));
            FunctionRequirements     swaptionReqs   = swaptionLookup.requirements(index);

            return(ratesReqs.combinedWith(swaptionReqs));
        }
        //-------------------------------------------------------------------------
        public virtual FunctionRequirements requirements(FraTrade trade, ISet <Measure> measures, CalculationParameters parameters, ReferenceData refData)
        {
            // extract data from product
            Fra product = trade.Product;
            ISet <IborIndex> indices = new HashSet <IborIndex>();

            indices.Add(product.Index);
            product.IndexInterpolated.ifPresent(indices.add);
            ImmutableSet <Currency> currencies = ImmutableSet.of(product.Currency);

            // use lookup to build requirements
            RatesMarketDataLookup ratesLookup = parameters.getParameter(typeof(RatesMarketDataLookup));

            return(ratesLookup.requirements(currencies, indices));
        }
Exemplo n.º 12
0
        //-------------------------------------------------------------------------
        public virtual FunctionRequirements requirements(IborCapFloorTrade trade, ISet <Measure> measures, CalculationParameters parameters, ReferenceData refData)
        {
            // extract data from product
            IborCapFloor    product    = trade.Product;
            ISet <Currency> currencies = product.allPaymentCurrencies();
            ISet <Index>    indices    = product.allIndices();

            // use lookup to build requirements
            RatesMarketDataLookup        ratesLookup    = parameters.getParameter(typeof(RatesMarketDataLookup));
            FunctionRequirements         ratesReqs      = ratesLookup.requirements(currencies, indices);
            IborCapFloorMarketDataLookup capFloorLookup = parameters.getParameter(typeof(IborCapFloorMarketDataLookup));
            FunctionRequirements         capFloorReqs   = capFloorLookup.requirements(product.CapFloorLeg.Index);

            return(ratesReqs.combinedWith(capFloorReqs));
        }
        //-------------------------------------------------------------------------
        public virtual FunctionRequirements requirements(T target, ISet <Measure> measures, CalculationParameters parameters, ReferenceData refData)
        {
            // extract data from product
            CapitalIndexedBond product       = target.Product;
            Currency           currency      = product.Currency;
            SecurityId         securityId    = product.SecurityId;
            LegalEntityId      legalEntityId = product.LegalEntityId;

            // use lookup to build requirements
            RatesMarketDataLookup ratesLookup = parameters.getParameter(typeof(RatesMarketDataLookup));
            FunctionRequirements  ratesReqs   = ratesLookup.requirements(ImmutableSet.of(), ImmutableSet.of(product.RateCalculation.Index));
            LegalEntityDiscountingMarketDataLookup ledLookup = parameters.getParameter(typeof(LegalEntityDiscountingMarketDataLookup));
            FunctionRequirements ledReqs = ledLookup.requirements(securityId, legalEntityId, currency);

            return(ratesReqs.combinedWith(ledReqs));
        }
        //-------------------------------------------------------------------------
        public virtual FunctionRequirements requirements(T target, ISet <Measure> measures, CalculationParameters parameters, ReferenceData refData)
        {
            // extract data from product
            OvernightFuture product = target.Product;
            QuoteId         quoteId = QuoteId.of(target.Product.SecurityId.StandardId, FieldName.SETTLEMENT_PRICE);
            OvernightIndex  index   = product.Index;

            // use lookup to build requirements
            RatesMarketDataLookup ratesLookup = parameters.getParameter(typeof(RatesMarketDataLookup));
            FunctionRequirements  ratesReqs   = ratesLookup.requirements(ImmutableSet.of(), ImmutableSet.of(index));
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.google.common.collect.ImmutableSet<com.opengamma.strata.data.MarketDataId<?>> valueReqs = com.google.common.collect.ImmutableSet.builder<com.opengamma.strata.data.MarketDataId<?>>().add(quoteId).addAll(ratesReqs.getValueRequirements()).build();
            ImmutableSet <MarketDataId <object> > valueReqs = ImmutableSet.builder <MarketDataId <object> >().add(quoteId).addAll(ratesReqs.ValueRequirements).build();

            return(ratesReqs.toBuilder().valueRequirements(valueReqs).build());
        }
        //-------------------------------------------------------------------------
        public virtual FunctionRequirements requirements(CmsTrade trade, ISet <Measure> measures, CalculationParameters parameters, ReferenceData refData)
        {
            // extract data from product
            Cms             product    = trade.Product;
            ISet <Currency> currencies = product.allPaymentCurrencies();
            IborIndex       cmsIndex   = trade.Product.CmsLeg.UnderlyingIndex;
            ISet <Index>    payIndices = trade.Product.allRateIndices();
            ISet <Index>    indices    = ImmutableSet.builder <Index>().add(cmsIndex).addAll(payIndices).build();

            // use lookup to build requirements
            RatesMarketDataLookup    ratesLookup    = parameters.getParameter(typeof(RatesMarketDataLookup));
            FunctionRequirements     ratesReqs      = ratesLookup.requirements(currencies, indices);
            SwaptionMarketDataLookup swaptionLookup = parameters.getParameter(typeof(SwaptionMarketDataLookup));
            FunctionRequirements     swaptionReqs   = swaptionLookup.requirements(cmsIndex);

            return(ratesReqs.combinedWith(swaptionReqs));
        }
        //-------------------------------------------------------------------------
        public virtual void test_marketDataView()
        {
            ImmutableMap <Currency, CurveId> discounts = ImmutableMap.of(USD, CURVE_ID_DSC);
            ImmutableMap <Index, CurveId>    forwards  = ImmutableMap.of(USD_LIBOR_3M, CURVE_ID_FWD);
            RatesMarketDataLookup            test      = RatesMarketDataLookup.of(discounts, forwards);
            LocalDate               valDate            = date(2015, 6, 30);
            ScenarioMarketData      md            = new TestMarketDataMap(valDate, ImmutableMap.of(), ImmutableMap.of());
            RatesScenarioMarketData multiScenario = test.marketDataView(md);

            assertEquals(multiScenario.Lookup, test);
            assertEquals(multiScenario.MarketData, md);
            assertEquals(multiScenario.ScenarioCount, 1);
            RatesMarketData scenario = multiScenario.scenario(0);

            assertEquals(scenario.Lookup, test);
            assertEquals(scenario.MarketData, md.scenario(0));
            assertEquals(scenario.ValuationDate, valDate);
        }
        // obtains the data and calculates the grid of results
        private static void calculate(CalculationRunner runner)
        {
            // the trades that will have measures calculated
            IList <Trade> trades = createSwapTrades();

            // the columns, specifying the measures to be calculated
            IList <Column> columns = ImmutableList.of(Column.of(Measures.LEG_INITIAL_NOTIONAL), Column.of(Measures.PRESENT_VALUE), Column.of(Measures.LEG_PRESENT_VALUE), Column.of(Measures.PV01_CALIBRATED_SUM), Column.of(Measures.PAR_RATE), Column.of(Measures.ACCRUED_INTEREST), Column.of(Measures.PV01_CALIBRATED_BUCKETED), Column.of(AdvancedMeasures.PV01_SEMI_PARALLEL_GAMMA_BUCKETED));

            // load quotes
            ImmutableMap <QuoteId, double> quotes = QuotesCsvLoader.load(VAL_DATE, QUOTES_RESOURCE);

            // load fixings
            ImmutableMap <ObservableId, LocalDateDoubleTimeSeries> fixings = FixingSeriesCsvLoader.load(FIXINGS_RESOURCE);

            // create the market data
            MarketData marketData = MarketData.of(VAL_DATE, quotes, fixings);

            // the reference data, such as holidays and securities
            ReferenceData refData = ReferenceData.standard();

            // load the curve definition
            IDictionary <CurveGroupName, RatesCurveGroupDefinition> defns = RatesCalibrationCsvLoader.load(GROUPS_RESOURCE, SETTINGS_RESOURCE, CALIBRATION_RESOURCE);
            RatesCurveGroupDefinition curveGroupDefinition = defns[CURVE_GROUP_NAME].filtered(VAL_DATE, refData);

            // the configuration that defines how to create the curves when a curve group is requested
            MarketDataConfig marketDataConfig = MarketDataConfig.builder().add(CURVE_GROUP_NAME, curveGroupDefinition).build();

            // the complete set of rules for calculating measures
            CalculationFunctions  functions   = StandardComponents.calculationFunctions();
            RatesMarketDataLookup ratesLookup = RatesMarketDataLookup.of(curveGroupDefinition);
            CalculationRules      rules       = CalculationRules.of(functions, ratesLookup);

            // calibrate the curves and calculate the results
            MarketDataRequirements reqs = MarketDataRequirements.of(rules, trades, columns, refData);
            MarketData             calibratedMarketData = marketDataFactory().create(reqs, marketDataConfig, marketData, refData);
            Results results = runner.calculate(rules, trades, columns, calibratedMarketData, refData);

            // use the report runner to transform the engine results into a trade report
            ReportCalculationResults calculationResults = ReportCalculationResults.of(VAL_DATE, trades, columns, results, functions, refData);
            TradeReportTemplate      reportTemplate     = ExampleData.loadTradeReportTemplate("swap-report-template");
            TradeReport tradeReport = TradeReport.of(calculationResults, reportTemplate);

            tradeReport.writeAsciiTable(System.out);
        }
Exemplo n.º 18
0
        private ReportCalculationResults runCalculationRequirements(ReportRequirements requirements)
        {
            IList <Column> columns = requirements.TradeMeasureRequirements;

            ExampleMarketDataBuilder marketDataBuilder = marketDataRoot == null?ExampleMarketData.builder() : ExampleMarketDataBuilder.ofPath(marketDataRoot.toPath());

            CalculationFunctions  functions   = StandardComponents.calculationFunctions();
            RatesMarketDataLookup ratesLookup = marketDataBuilder.ratesLookup(valuationDate);
            CalculationRules      rules       = CalculationRules.of(functions, ratesLookup);

            MarketData marketData = marketDataBuilder.buildSnapshot(valuationDate);

            IList <Trade> trades;

            if (Strings.nullToEmpty(idSearch).Trim().Empty)
            {
                trades = tradeList.Trades;
            }
            else
            {
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
                trades = tradeList.Trades.Where(t => t.Info.Id.Present).Where(t => t.Info.Id.get().Value.Equals(idSearch)).collect(toImmutableList());
                if (trades.Count > 1)
                {
                    throw new System.ArgumentException(Messages.format("More than one trade found matching ID: '{}'", idSearch));
                }
            }
            if (trades.Count == 0)
            {
                throw new System.ArgumentException("No trades found. Please check the input portfolio or trade ID filter.");
            }

            // the reference data, such as holidays and securities
            ReferenceData refData = ReferenceData.standard();

            // calculate the results
            CalculationTasks       tasks = CalculationTasks.of(rules, trades, columns, refData);
            MarketDataRequirements reqs  = tasks.requirements(refData);
            MarketData             calibratedMarketData = marketDataFactory().create(reqs, MarketDataConfig.empty(), marketData, refData);
            Results results = runner.TaskRunner.calculate(tasks, calibratedMarketData, refData);

            return(ReportCalculationResults.of(valuationDate, trades, requirements.TradeMeasureRequirements, results, functions, refData));
        }
        public virtual void test_ratesProvider()
        {
            ImmutableMap <Currency, CurveId> discounts = ImmutableMap.of(USD, CURVE_ID_DSC);
            ImmutableMap <Index, CurveId>    forwards  = ImmutableMap.of(USD_FED_FUND, CURVE_ID_DSC, USD_LIBOR_3M, CURVE_ID_FWD, US_CPI_U, CURVE_ID_FWD);
            RatesMarketDataLookup            test      = RatesMarketDataLookup.of(discounts, forwards);
            LocalDate     valDate       = date(2015, 6, 30);
            Curve         dscCurve      = ConstantCurve.of(Curves.discountFactors(CURVE_ID_DSC.CurveName, ACT_360), 1d);
            Curve         fwdCurve      = ConstantCurve.of(Curves.discountFactors(CURVE_ID_FWD.CurveName, ACT_360), 2d);
            MarketData    md            = ImmutableMarketData.of(valDate, ImmutableMap.of(CURVE_ID_DSC, dscCurve, CURVE_ID_FWD, fwdCurve));
            RatesProvider ratesProvider = test.ratesProvider(md);

            assertEquals(ratesProvider.ValuationDate, valDate);
            assertEquals(ratesProvider.findData(CURVE_ID_DSC.CurveName), dscCurve);
            assertEquals(ratesProvider.findData(CURVE_ID_FWD.CurveName), fwdCurve);
            assertEquals(ratesProvider.findData(CurveName.of("Rubbish")), null);
            assertEquals(ratesProvider.IborIndices, ImmutableSet.of(USD_LIBOR_3M));
            assertEquals(ratesProvider.OvernightIndices, ImmutableSet.of(USD_FED_FUND));
            assertEquals(ratesProvider.PriceIndices, ImmutableSet.of(US_CPI_U));
            assertEquals(ratesProvider.TimeSeriesIndices, ImmutableSet.of());
            // check discount factors
            SimpleDiscountFactors df = (SimpleDiscountFactors)ratesProvider.discountFactors(USD);

            assertEquals(df.Curve.Name, dscCurve.Name);
            assertThrowsIllegalArg(() => ratesProvider.discountFactors(GBP));
            // check Ibor
            DiscountIborIndexRates ibor   = (DiscountIborIndexRates)ratesProvider.iborIndexRates(USD_LIBOR_3M);
            SimpleDiscountFactors  iborDf = (SimpleDiscountFactors)ibor.DiscountFactors;

            assertEquals(iborDf.Curve.Name, fwdCurve.Name);
            assertThrowsIllegalArg(() => ratesProvider.iborIndexRates(GBP_LIBOR_3M));
            // check Overnight
            DiscountOvernightIndexRates on   = (DiscountOvernightIndexRates)ratesProvider.overnightIndexRates(USD_FED_FUND);
            SimpleDiscountFactors       onDf = (SimpleDiscountFactors)on.DiscountFactors;

            assertEquals(onDf.Curve.Name, dscCurve.Name);
            assertThrowsIllegalArg(() => ratesProvider.overnightIndexRates(GBP_SONIA));
            // check price curve must be interpolated
            assertThrowsIllegalArg(() => ratesProvider.priceIndexValues(US_CPI_U));
            // to immutable
            ImmutableRatesProvider expectedImmutable = ImmutableRatesProvider.builder(valDate).fxRateProvider(MarketDataFxRateProvider.of(md)).discountCurve(USD, dscCurve).indexCurve(USD_FED_FUND, dscCurve).indexCurve(USD_LIBOR_3M, fwdCurve).indexCurve(US_CPI_U, fwdCurve).build();

            assertEquals(ratesProvider.toImmutableRatesProvider(), expectedImmutable);
        }
        //-------------------------------------------------------------------------
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: @Override public java.util.Map<com.opengamma.strata.calc.Measure, com.opengamma.strata.collect.result.Result<?>> calculate(T target, java.util.Set<com.opengamma.strata.calc.Measure> measures, com.opengamma.strata.calc.runner.CalculationParameters parameters, com.opengamma.strata.data.scenario.ScenarioMarketData scenarioMarketData, com.opengamma.strata.basics.ReferenceData refData)
        public virtual IDictionary <Measure, Result <object> > calculate(T target, ISet <Measure> measures, CalculationParameters parameters, ScenarioMarketData scenarioMarketData, ReferenceData refData)
        {
            // resolve the trade once for all measures and all scenarios
            ResolvedIborFutureTrade resolved = target.resolve(refData);

            // use lookup to query market data
            RatesMarketDataLookup   ratesLookup = parameters.getParameter(typeof(RatesMarketDataLookup));
            RatesScenarioMarketData marketData  = ratesLookup.marketDataView(scenarioMarketData);

            // loop around measures, calculating all scenarios for one measure
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Map<com.opengamma.strata.calc.Measure, com.opengamma.strata.collect.result.Result<?>> results = new java.util.HashMap<>();
            IDictionary <Measure, Result <object> > results = new Dictionary <Measure, Result <object> >();

            foreach (Measure measure in measures)
            {
                results[measure] = calculate(measure, resolved, marketData);
            }
            return(results);
        }
        //-------------------------------------------------------------------------
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: @Override public java.util.Map<com.opengamma.strata.calc.Measure, com.opengamma.strata.collect.result.Result<?>> calculate(com.opengamma.strata.product.fxopt.FxSingleBarrierOptionTrade trade, java.util.Set<com.opengamma.strata.calc.Measure> measures, com.opengamma.strata.calc.runner.CalculationParameters parameters, com.opengamma.strata.data.scenario.ScenarioMarketData scenarioMarketData, com.opengamma.strata.basics.ReferenceData refData)
        public virtual IDictionary <Measure, Result <object> > calculate(FxSingleBarrierOptionTrade trade, ISet <Measure> measures, CalculationParameters parameters, ScenarioMarketData scenarioMarketData, ReferenceData refData)
        {
            // expand the trade once for all measures and all scenarios
            ResolvedFxSingleBarrierOptionTrade resolved  = trade.resolve(refData);
            RatesMarketDataLookup       ratesLookup      = parameters.getParameter(typeof(RatesMarketDataLookup));
            RatesScenarioMarketData     ratesMarketData  = ratesLookup.marketDataView(scenarioMarketData);
            FxOptionMarketDataLookup    optionLookup     = parameters.getParameter(typeof(FxOptionMarketDataLookup));
            FxOptionScenarioMarketData  optionMarketData = optionLookup.marketDataView(scenarioMarketData);
            FxSingleBarrierOptionMethod method           = parameters.findParameter(typeof(FxSingleBarrierOptionMethod)).orElse(FxSingleBarrierOptionMethod.BLACK);

            // loop around measures, calculating all scenarios for one measure
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Map<com.opengamma.strata.calc.Measure, com.opengamma.strata.collect.result.Result<?>> results = new java.util.HashMap<>();
            IDictionary <Measure, Result <object> > results = new Dictionary <Measure, Result <object> >();

            foreach (Measure measure in measures)
            {
                results[measure] = calculate(measure, resolved, ratesMarketData, optionMarketData, method);
            }
            return(results);
        }
        /// <summary>
        /// Tests calibration a curve containing FRAs and pricing the curve instruments using the curve.
        /// </summary>
        public virtual void roundTripFra()
        {
            InterpolatedNodalCurveDefinition curveDefn = CurveTestUtils.fraCurveDefinition();

//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
            IList <FraCurveNode> nodes = curveDefn.Nodes.Select(typeof(FraCurveNode).cast).collect(toImmutableList());

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.List<com.opengamma.strata.data.MarketDataId<?>> keys = nodes.stream().map(CurveTestUtils::key).collect(toImmutableList());
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
            IList <MarketDataId <object> > keys = nodes.Select(CurveTestUtils.key).collect(toImmutableList());
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Map<com.opengamma.strata.data.MarketDataId<?>, double> inputData = com.google.common.collect.ImmutableMap.builder<com.opengamma.strata.data.MarketDataId<?>, double>().put(keys.get(0), 0.003).put(keys.get(1), 0.0033).put(keys.get(2), 0.0037).put(keys.get(3), 0.0054).put(keys.get(4), 0.007).put(keys.get(5), 0.0091).put(keys.get(6), 0.0134).build();
            IDictionary <MarketDataId <object>, double> inputData = ImmutableMap.builder <MarketDataId <object>, double>().put(keys[0], 0.003).put(keys[1], 0.0033).put(keys[2], 0.0037).put(keys[3], 0.0054).put(keys[4], 0.007).put(keys[5], 0.0091).put(keys[6], 0.0134).build();

            CurveGroupName   groupName   = CurveGroupName.of("Curve Group");
            CurveName        curveName   = CurveName.of("FRA Curve");
            RatesCurveInputs curveInputs = RatesCurveInputs.of(inputData, DefaultCurveMetadata.of(curveName));

            RatesCurveGroupDefinition groupDefn = RatesCurveGroupDefinition.builder().name(groupName).addCurve(curveDefn, Currency.USD, IborIndices.USD_LIBOR_3M).build();

            RatesCurveGroupMarketDataFunction function = new RatesCurveGroupMarketDataFunction();
            LocalDate          valuationDate           = date(2011, 3, 8);
            ScenarioMarketData inputMarketData         = ImmutableScenarioMarketData.builder(valuationDate).addValue(RatesCurveInputsId.of(groupName, curveName, ObservableSource.NONE), curveInputs).build();
            MarketDataBox <RatesCurveGroup> curveGroup = function.buildCurveGroup(groupDefn, CALIBRATOR, inputMarketData, REF_DATA, ObservableSource.NONE);

            Curve curve = curveGroup.SingleValue.findDiscountCurve(Currency.USD).get();

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Map<com.opengamma.strata.data.MarketDataId<?>, Object> marketDataMap = com.google.common.collect.ImmutableMap.builder<com.opengamma.strata.data.MarketDataId<?>, Object>().putAll(inputData).put(com.opengamma.strata.market.curve.CurveId.of(groupName, curveName), curve).build();
            IDictionary <MarketDataId <object>, object> marketDataMap = ImmutableMap.builder <MarketDataId <object>, object>().putAll(inputData).put(CurveId.of(groupName, curveName), curve).build();

            MarketData            marketData         = ImmutableMarketData.of(valuationDate, marketDataMap);
            TestMarketDataMap     scenarioMarketData = new TestMarketDataMap(valuationDate, marketDataMap, ImmutableMap.of());
            RatesMarketDataLookup lookup             = RatesMarketDataLookup.of(groupDefn);
            RatesProvider         ratesProvider      = lookup.ratesProvider(scenarioMarketData.scenario(0));

            // The PV should be zero for an instrument used to build the curve
            nodes.ForEach(node => checkFraPvIsZero(node, ratesProvider, marketData));
        }
Exemplo n.º 23
0
        //-------------------------------------------------------------------------
        public virtual void presentValueVanillaFixedVsLibor1mSwap()
        {
            SwapLeg payLeg = fixedLeg(LocalDate.of(2014, 9, 12), LocalDate.of(2016, 9, 12), Frequency.P6M, PayReceive.PAY, NOTIONAL, 0.0125, null);

            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2016, 9, 12)).frequency(Frequency.P1M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P1M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_1M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build();

            SwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 9, 10)).build()).product(Swap.of(payLeg, receiveLeg)).build();

            CurveGroupName groupName    = CurveGroupName.of("Test");
            CurveId        idUsdDsc     = CurveId.of(groupName, StandardDataSets.GROUP1_USD_DSC.Name);
            CurveId        idUsdOn      = CurveId.of(groupName, StandardDataSets.GROUP1_USD_ON.Name);
            CurveId        idUsdL1M     = CurveId.of(groupName, StandardDataSets.GROUP1_USD_L1M.Name);
            CurveId        idUsdL3M     = CurveId.of(groupName, StandardDataSets.GROUP1_USD_L3M.Name);
            CurveId        idUsdL6M     = CurveId.of(groupName, StandardDataSets.GROUP1_USD_L6M.Name);
            MarketData     suppliedData = ImmutableMarketData.builder(VAL_DATE).addValue(idUsdDsc, StandardDataSets.GROUP1_USD_DSC).addValue(idUsdOn, StandardDataSets.GROUP1_USD_ON).addValue(idUsdL1M, StandardDataSets.GROUP1_USD_L1M).addValue(idUsdL3M, StandardDataSets.GROUP1_USD_L3M).addValue(idUsdL6M, StandardDataSets.GROUP1_USD_L6M).build();

            CalculationFunctions functions = StandardComponents.calculationFunctions();

            RatesMarketDataLookup ratesLookup = RatesMarketDataLookup.of(ImmutableMap.of(USD, idUsdDsc), ImmutableMap.of(USD_FED_FUND, idUsdOn, USD_LIBOR_1M, idUsdL1M, USD_LIBOR_3M, idUsdL3M, USD_LIBOR_6M, idUsdL6M));

            // create the calculation runner
            IList <SwapTrade> trades  = ImmutableList.of(trade);
            IList <Column>    columns = ImmutableList.of(Column.of(Measures.PRESENT_VALUE));
            CalculationRules  rules   = CalculationRules.of(functions, USD, ratesLookup);

            // calculate results using the runner
            // using the direct executor means there is no need to close/shutdown the runner
            CalculationRunner runner  = CalculationRunner.of(MoreExecutors.newDirectExecutorService());
            Results           results = runner.calculate(rules, trades, columns, suppliedData, REF_DATA);

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> result = results.get(0, 0);
            Result <object> result = results.get(0, 0);

            assertThat(result).Success;

            CurrencyAmount pv = (CurrencyAmount)result.Value;

            assertThat(pv.Amount).isCloseTo(-1003684.8402, offset(TOLERANCE_PV));
        }
        //-------------------------------------------------------------------------
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: @Override public java.util.Map<com.opengamma.strata.calc.Measure, com.opengamma.strata.collect.result.Result<?>> calculate(com.opengamma.strata.product.cms.CmsTrade trade, java.util.Set<com.opengamma.strata.calc.Measure> measures, com.opengamma.strata.calc.runner.CalculationParameters parameters, com.opengamma.strata.data.scenario.ScenarioMarketData scenarioMarketData, com.opengamma.strata.basics.ReferenceData refData)
        public virtual IDictionary <Measure, Result <object> > calculate(CmsTrade trade, ISet <Measure> measures, CalculationParameters parameters, ScenarioMarketData scenarioMarketData, ReferenceData refData)
        {
            // expand the trade once for all measures and all scenarios
            ResolvedCmsTrade           resolved           = trade.resolve(refData);
            RatesMarketDataLookup      ratesLookup        = parameters.getParameter(typeof(RatesMarketDataLookup));
            RatesScenarioMarketData    ratesMarketData    = ratesLookup.marketDataView(scenarioMarketData);
            SwaptionMarketDataLookup   swaptionLookup     = parameters.getParameter(typeof(SwaptionMarketDataLookup));
            SwaptionScenarioMarketData swaptionMarketData = swaptionLookup.marketDataView(scenarioMarketData);
            CmsSabrExtrapolationParams cmsParams          = parameters.getParameter(typeof(CmsSabrExtrapolationParams));
            CmsMeasureCalculations     calculations       = new CmsMeasureCalculations(cmsParams);

            // loop around measures, calculating all scenarios for one measure
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Map<com.opengamma.strata.calc.Measure, com.opengamma.strata.collect.result.Result<?>> results = new java.util.HashMap<>();
            IDictionary <Measure, Result <object> > results = new Dictionary <Measure, Result <object> >();

            foreach (Measure measure in measures)
            {
                results[measure] = calculate(measure, resolved, calculations, ratesMarketData, swaptionMarketData);
            }
            return(results);
        }
Exemplo n.º 25
0
        // calculates the PV results for the instruments used in calibration from the config
        private static Pair <IList <Trade>, Results> calculate(CalculationRunner runner)
        {
            // the reference data, such as holidays and securities
            ReferenceData refData = ReferenceData.standard();

            // load quotes
            ImmutableMap <QuoteId, double> quotes = QuotesCsvLoader.load(VAL_DATE, QUOTES_RESOURCE);

            // load time series
            IDictionary <ObservableId, LocalDateDoubleTimeSeries> fixings = FixingSeriesCsvLoader.load(FIXING_RESOURCE);

            // create the market data
            MarketData marketData = ImmutableMarketData.builder(VAL_DATE).addValueMap(quotes).addTimeSeriesMap(fixings).build();

            // load the curve definition
            IDictionary <CurveGroupName, RatesCurveGroupDefinition> defns = RatesCalibrationCsvLoader.load(GROUPS_RESOURCE, SETTINGS_RESOURCE, CALIBRATION_RESOURCE);
            RatesCurveGroupDefinition curveGroupDefinition = defns[CURVE_GROUP_NAME].filtered(VAL_DATE, refData);

            // extract the trades used for calibration
            IList <Trade> trades = curveGroupDefinition.CurveDefinitions.stream().flatMap(defn => defn.Nodes.stream()).filter(node => !(node is IborFixingDepositCurveNode)).map(node => node.trade(1d, marketData, refData)).collect(toImmutableList());

            // the columns, specifying the measures to be calculated
            IList <Column> columns = ImmutableList.of(Column.of(Measures.PRESENT_VALUE));

            // the configuration that defines how to create the curves when a curve group is requested
            MarketDataConfig marketDataConfig = MarketDataConfig.builder().add(CURVE_GROUP_NAME, curveGroupDefinition).build();

            // the complete set of rules for calculating measures
            CalculationFunctions  functions   = StandardComponents.calculationFunctions();
            RatesMarketDataLookup ratesLookup = RatesMarketDataLookup.of(curveGroupDefinition);
            CalculationRules      rules       = CalculationRules.of(functions, ratesLookup);

            // calibrate the curves and calculate the results
            MarketDataRequirements reqs = MarketDataRequirements.of(rules, trades, columns, refData);
            MarketData             calibratedMarketData = marketDataFactory().create(reqs, marketDataConfig, marketData, refData);
            Results results = runner.calculate(rules, trades, columns, calibratedMarketData, refData);

            return(Pair.of(trades, results));
        }
        //-------------------------------------------------------------------------
        public virtual void test_of_map()
        {
            ImmutableMap <Currency, CurveId> discounts = ImmutableMap.of(USD, CURVE_ID_DSC);
            ImmutableMap <Index, CurveId>    forwards  = ImmutableMap.of(USD_LIBOR_3M, CURVE_ID_FWD);
            RatesMarketDataLookup            test      = RatesMarketDataLookup.of(discounts, forwards);

            assertEquals(test.queryType(), typeof(RatesMarketDataLookup));
            assertEquals(test.DiscountCurrencies, ImmutableSet.of(USD));
            assertEquals(test.getDiscountMarketDataIds(USD), ImmutableSet.of(CURVE_ID_DSC));
            assertEquals(test.ForwardIndices, ImmutableSet.of(USD_LIBOR_3M));
            assertEquals(test.getForwardMarketDataIds(USD_LIBOR_3M), ImmutableSet.of(CURVE_ID_FWD));
            assertThrowsIllegalArg(() => test.getDiscountMarketDataIds(GBP));
            assertThrowsIllegalArg(() => test.getForwardMarketDataIds(GBP_LIBOR_3M));
            assertEquals(test.ObservableSource, ObservableSource.NONE);
            assertEquals(test.FxRateLookup, FxRateLookup.ofRates());

            assertEquals(test.requirements(USD), FunctionRequirements.builder().valueRequirements(CURVE_ID_DSC).outputCurrencies(USD).build());
            assertEquals(test.requirements(USD, USD_LIBOR_3M), FunctionRequirements.builder().valueRequirements(CURVE_ID_DSC, CURVE_ID_FWD).timeSeriesRequirements(IndexQuoteId.of(USD_LIBOR_3M)).outputCurrencies(USD).build());
            assertEquals(test.requirements(ImmutableSet.of(USD), ImmutableSet.of(USD_LIBOR_3M)), FunctionRequirements.builder().valueRequirements(CURVE_ID_DSC, CURVE_ID_FWD).timeSeriesRequirements(IndexQuoteId.of(USD_LIBOR_3M)).outputCurrencies(USD).build());
            assertThrowsIllegalArg(() => test.requirements(ImmutableSet.of(USD), ImmutableSet.of(GBP_LIBOR_3M)));

            assertEquals(test.ratesProvider(MOCK_MARKET_DATA), DefaultLookupRatesProvider.of((DefaultRatesMarketDataLookup)test, MOCK_MARKET_DATA));
        }
        public virtual void roundTripFraAndFixedFloatSwap()
        {
            CurveGroupName groupName = CurveGroupName.of("Curve Group");
            InterpolatedNodalCurveDefinition curveDefn = CurveTestUtils.fraSwapCurveDefinition();
            CurveName         curveName = curveDefn.Name;
            IList <CurveNode> nodes     = curveDefn.Nodes;

            RatesCurveGroupDefinition groupDefn = RatesCurveGroupDefinition.builder().name(groupName).addCurve(curveDefn, Currency.USD, IborIndices.USD_LIBOR_3M).build();

            RatesCurveGroupMarketDataFunction function = new RatesCurveGroupMarketDataFunction();
            LocalDate valuationDate = date(2011, 3, 8);

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Map<com.opengamma.strata.data.MarketDataId<?>, double> inputData = com.google.common.collect.ImmutableMap.builder<com.opengamma.strata.data.MarketDataId<?>, double>().put(CurveTestUtils.key(nodes.get(0)), 0.0037).put(CurveTestUtils.key(nodes.get(1)), 0.0054).put(CurveTestUtils.key(nodes.get(2)), 0.005).put(CurveTestUtils.key(nodes.get(3)), 0.0087).put(CurveTestUtils.key(nodes.get(4)), 0.012).build();
            IDictionary <MarketDataId <object>, double> inputData = ImmutableMap.builder <MarketDataId <object>, double>().put(CurveTestUtils.key(nodes[0]), 0.0037).put(CurveTestUtils.key(nodes[1]), 0.0054).put(CurveTestUtils.key(nodes[2]), 0.005).put(CurveTestUtils.key(nodes[3]), 0.0087).put(CurveTestUtils.key(nodes[4]), 0.012).build();

            RatesCurveInputs   curveInputs     = RatesCurveInputs.of(inputData, DefaultCurveMetadata.of(curveName));
            ScenarioMarketData inputMarketData = ImmutableScenarioMarketData.builder(valuationDate).addValue(RatesCurveInputsId.of(groupName, curveName, ObservableSource.NONE), curveInputs).build();

            MarketDataBox <RatesCurveGroup> curveGroup = function.buildCurveGroup(groupDefn, CALIBRATOR, inputMarketData, REF_DATA, ObservableSource.NONE);
            Curve curve = curveGroup.SingleValue.findDiscountCurve(Currency.USD).get();

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Map<com.opengamma.strata.data.MarketDataId<?>, Object> marketDataMap = com.google.common.collect.ImmutableMap.builder<com.opengamma.strata.data.MarketDataId<?>, Object>().putAll(inputData).put(com.opengamma.strata.market.curve.CurveId.of(groupName, curveName), curve).build();
            IDictionary <MarketDataId <object>, object> marketDataMap = ImmutableMap.builder <MarketDataId <object>, object>().putAll(inputData).put(CurveId.of(groupName, curveName), curve).build();
            MarketData            marketData         = ImmutableMarketData.of(valuationDate, marketDataMap);
            TestMarketDataMap     scenarioMarketData = new TestMarketDataMap(valuationDate, marketDataMap, ImmutableMap.of());
            RatesMarketDataLookup lookup             = RatesMarketDataLookup.of(groupDefn);
            RatesProvider         ratesProvider      = lookup.ratesProvider(scenarioMarketData.scenario(0));

            checkFraPvIsZero((FraCurveNode)nodes[0], ratesProvider, marketData);
            checkFraPvIsZero((FraCurveNode)nodes[1], ratesProvider, marketData);
            checkSwapPvIsZero((FixedIborSwapCurveNode)nodes[2], ratesProvider, marketData);
            checkSwapPvIsZero((FixedIborSwapCurveNode)nodes[3], ratesProvider, marketData);
            checkSwapPvIsZero((FixedIborSwapCurveNode)nodes[4], ratesProvider, marketData);
        }
        private readonly AtomicReferenceArray <RatesMarketData> cache;  // derived

        //-------------------------------------------------------------------------
        /// <summary>
        /// Obtains an instance based on a lookup and market data.
        /// <para>
        /// The lookup provides the mapping from currency to discount curve, and from
        /// index to forward curve. The curves are in the market data.
        ///
        /// </para>
        /// </summary>
        /// <param name="lookup">  the lookup </param>
        /// <param name="marketData">  the market data </param>
        /// <returns> the rates market view </returns>
        public static DefaultRatesScenarioMarketData of(RatesMarketDataLookup lookup, ScenarioMarketData marketData)
        {
            return(new DefaultRatesScenarioMarketData(lookup, marketData));
        }
        /// <summary>
        /// Gets the rates market lookup to use with this environment.
        /// </summary>
        /// <param name="marketDataDate">  the date of the market data </param>
        /// <returns> the rates lookup </returns>
        public virtual RatesMarketDataLookup ratesLookup(LocalDate marketDataDate)
        {
            SortedDictionary <LocalDate, RatesCurveGroup> curves = loadAllRatesCurves();

            return(RatesMarketDataLookup.of(curves[marketDataDate]));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @ImmutableConstructor private DefaultRatesScenarioMarketData(RatesMarketDataLookup lookup, com.opengamma.strata.data.scenario.ScenarioMarketData marketData)
        private DefaultRatesScenarioMarketData(RatesMarketDataLookup lookup, ScenarioMarketData marketData)
        {
            this.lookup     = ArgChecker.notNull(lookup, "lookup");
            this.marketData = ArgChecker.notNull(marketData, "marketData");
            this.cache      = new AtomicReferenceArray <RatesMarketData>(marketData.ScenarioCount);
        }