// 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);
        }
        /// <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);
        }
Ejemplo n.º 3
0
        // 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);
        }
        // obtains the data and calculates the grid of results
        private static void calculate(CalculationRunner runner)
        {
            // the trade that will have measures calculated
            IList <Trade> trades = ImmutableList.of(createVanillaFixedVsLibor3mSwap());

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

            // use the built-in example market data
            ExampleMarketDataBuilder marketDataBuilder = ExampleMarketData.builder();

            // the complete set of rules for calculating measures
            LocalDate            valuationDate = LocalDate.of(2014, 1, 22);
            CalculationFunctions functions     = StandardComponents.calculationFunctions();
            CalculationRules     rules         = CalculationRules.of(functions, Currency.USD, marketDataBuilder.ratesLookup(valuationDate));

            // mappings that select which market data to apply perturbations to
            // this applies the perturbations above to all curves
            PerturbationMapping <Curve> mapping = PerturbationMapping.of(MarketDataFilter.ofIdType(typeof(CurveId)), CurveParallelShifts.absolute(0, ONE_BP));

            // create a scenario definition containing the single mapping above
            // this creates two scenarios - one for each perturbation in the mapping
            ScenarioDefinition scenarioDefinition = ScenarioDefinition.ofMappings(mapping);

            // build a market data snapshot for the valuation date
            MarketData marketData = marketDataBuilder.buildSnapshot(valuationDate);

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

            // calculate the results
            MarketDataRequirements reqs = MarketDataRequirements.of(rules, trades, columns, refData);
            ScenarioMarketData     scenarioMarketData = marketDataFactory().createMultiScenario(reqs, MarketDataConfig.empty(), marketData, refData, scenarioDefinition);
            Results results = runner.calculateMultiScenario(rules, trades, columns, scenarioMarketData, refData);

            // TODO Replace the results processing below with a report once the reporting framework supports scenarios

            // The results are lists of currency amounts containing one value for each scenario
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.data.scenario.ScenarioArray<?> pvList = (com.opengamma.strata.data.scenario.ScenarioArray<?>) results.get(0, 0).getValue();
            ScenarioArray <object> pvList = (ScenarioArray <object>)results.get(0, 0).Value;
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.data.scenario.ScenarioArray<?> pv01List = (com.opengamma.strata.data.scenario.ScenarioArray<?>) results.get(0, 1).getValue();
            ScenarioArray <object> pv01List = (ScenarioArray <object>)results.get(0, 1).Value;

            double       pvBase       = ((CurrencyAmount)pvList.get(0)).Amount;
            double       pvShifted    = ((CurrencyAmount)pvList.get(1)).Amount;
            double       pv01Base     = ((CurrencyAmount)pv01List.get(0)).Amount;
            NumberFormat numberFormat = new DecimalFormat("###,##0.00", new DecimalFormatSymbols(Locale.ENGLISH));

            Console.WriteLine("                         PV (base) = " + numberFormat.format(pvBase));
            Console.WriteLine("             PV (1 bp curve shift) = " + numberFormat.format(pvShifted));
            Console.WriteLine("PV01 (algorithmic differentiation) = " + numberFormat.format(pv01Base));
            Console.WriteLine("          PV01 (finite difference) = " + numberFormat.format(pvShifted - pvBase));
        }
Ejemplo n.º 5
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));
        }