Esempio 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 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));
        }
        // 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 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 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);
        }
        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);
        }
        /// <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));
        }
Esempio n. 9
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));
        }
Esempio n. 10
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);
        }
        /// <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]));
        }