// 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)); // use the built-in example market data LocalDate valuationDate = LocalDate.of(2014, 1, 22); ExampleMarketDataBuilder marketDataBuilder = ExampleMarketData.builder(); MarketData marketData = marketDataBuilder.buildSnapshot(valuationDate); // the complete set of rules for calculating measures CalculationFunctions functions = StandardComponents.calculationFunctions(); CalculationRules rules = CalculationRules.of(functions, marketDataBuilder.ratesLookup(valuationDate)); // the reference data, such as holidays and securities ReferenceData refData = ReferenceData.standard(); // calculate the results Results results = runner.calculate(rules, trades, columns, marketData, refData); // use the report runner to transform the engine results into a trade report ReportCalculationResults calculationResults = ReportCalculationResults.of(valuationDate, trades, columns, results, functions, refData); TradeReportTemplate reportTemplate = ExampleData.loadTradeReportTemplate("swap-report-template"); TradeReport tradeReport = TradeReport.of(calculationResults, reportTemplate); tradeReport.writeAsciiTable(System.out); }
// 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 = ImmutableList.of(createFutureTrade1(), createFutureTrade2(), createOptionTrade1(), createOptionTrade2()); // the columns, specifying the measures to be calculated IList <Column> columns = ImmutableList.of(Column.of(Measures.PRESENT_VALUE)); // use the built-in example market data LocalDate valuationDate = LocalDate.of(2014, 1, 22); ExampleMarketDataBuilder marketDataBuilder = ExampleMarketData.builder(); MarketData marketData = marketDataBuilder.buildSnapshot(valuationDate); // the complete set of rules for calculating measures CalculationFunctions functions = StandardComponents.calculationFunctions(); CalculationRules rules = CalculationRules.of(functions); // the reference data, such as holidays and securities //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: com.opengamma.strata.basics.ReferenceData refData = com.opengamma.strata.basics.ImmutableReferenceData.of(com.google.common.collect.ImmutableMap.of<com.opengamma.strata.basics.ReferenceDataId<?>, Object>(FGBL_MAR14_ID, FGBL_MAR14, OGBL_MAR14_C150_ID, OGBL_MAR14_C150, ED_MAR14_ID, ED_MAR14)); ReferenceData refData = ImmutableReferenceData.of(ImmutableMap.of <ReferenceDataId <object>, object>(FGBL_MAR14_ID, FGBL_MAR14, OGBL_MAR14_C150_ID, OGBL_MAR14_C150, ED_MAR14_ID, ED_MAR14)); // calculate the results Results results = runner.calculate(rules, trades, columns, marketData, refData); // use the report runner to transform the engine results into a trade report ReportCalculationResults calculationResults = ReportCalculationResults.of(valuationDate, trades, columns, results, functions, refData); TradeReportTemplate reportTemplate = ExampleData.loadTradeReportTemplate("security-report-template"); TradeReport tradeReport = TradeReport.of(calculationResults, reportTemplate); tradeReport.writeAsciiTable(System.out); }
/// <summary> /// Tests the full set of results against a golden copy. /// </summary> public virtual void testResults() { IList <Trade> trades = ImmutableList.of(createTrade1()); 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.ACCRUED_INTEREST)); ExampleMarketDataBuilder marketDataBuilder = ExampleMarketData.builder(); LocalDate valuationDate = LocalDate.of(2009, 7, 31); CalculationRules rules = CalculationRules.of(StandardComponents.calculationFunctions(), Currency.USD, marketDataBuilder.ratesLookup(valuationDate)); MarketData marketData = marketDataBuilder.buildSnapshot(valuationDate); // using the direct executor means there is no need to close/shutdown the runner CalculationTasks tasks = CalculationTasks.of(rules, trades, columns, REF_DATA); MarketDataRequirements reqs = tasks.requirements(REF_DATA); MarketData calibratedMarketData = marketDataFactory().create(reqs, MarketDataConfig.empty(), marketData, REF_DATA); CalculationTaskRunner runner = CalculationTaskRunner.of(MoreExecutors.newDirectExecutorService()); Results results = runner.calculate(tasks, calibratedMarketData, REF_DATA); ReportCalculationResults calculationResults = ReportCalculationResults.of(valuationDate, trades, columns, results); TradeReportTemplate reportTemplate = ExampleData.loadTradeReportTemplate("swap-report-regression-test-template"); TradeReport tradeReport = TradeReport.of(calculationResults, reportTemplate); string expectedResults = ExampleData.loadExpectedResults("swap-report"); TradeReportRegressionTestUtils.assertAsciiTableEquals(tradeReport.toAsciiTableString(), expectedResults); }
// 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); }
// 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); }