public virtual void requirementsMissingConfig() { FxRateMarketDataFunction function = new FxRateMarketDataFunction(); string regex = "No configuration found .*FxRateConfig"; assertThrowsIllegalArg(() => function.requirements(RATE_ID, MarketDataConfig.empty()), regex); }
public virtual void buildMissingConfig() { FxRateMarketDataFunction function = new FxRateMarketDataFunction(); string regex = "No configuration found .*FxRateConfig"; assertThrowsIllegalArg(() => function.build(RATE_ID, MarketDataConfig.empty(), ScenarioMarketData.empty(), REF_DATA), regex); }
/// <summary> /// Test that a failure is returned if there is no config for the curve group. /// </summary> public virtual void buildMissingGroupConfig() { RatesCurveInputsMarketDataFunction marketDataFunction = new RatesCurveInputsMarketDataFunction(); RatesCurveInputsId curveInputsId = RatesCurveInputsId.of(CurveGroupName.of("curve group"), CurveName.of("curve"), ObservableSource.NONE); ScenarioMarketData emptyData = ScenarioMarketData.empty(); assertThrows(() => marketDataFunction.build(curveInputsId, MarketDataConfig.empty(), emptyData, REF_DATA), typeof(System.ArgumentException), "No configuration found for type .*"); }
// 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)); }
/// <summary> /// Test that an exception is thrown if there is no curve group configuration corresponding to the ID /// </summary> public virtual void requirementsMissingGroupConfig() { RatesCurveInputsMarketDataFunction marketDataFunction = new RatesCurveInputsMarketDataFunction(); RatesCurveInputsId curveInputsId = RatesCurveInputsId.of(CurveGroupName.of("curve group"), CurveName.of("curve"), ObservableSource.NONE); assertThrowsIllegalArg(() => marketDataFunction.requirements(curveInputsId, MarketDataConfig.empty())); }
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)); }
/// <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 for which to calculate a P&L series IList <Trade> trades = ImmutableList.of(createTrade()); // the columns, specifying the measures to be calculated IList <Column> columns = ImmutableList.of(Column.of(Measures.PRESENT_VALUE)); // use the built-in example historical scenario market data ExampleMarketDataBuilder marketDataBuilder = ExampleMarketDataBuilder.ofResource(MARKET_DATA_RESOURCE_ROOT); // the complete set of rules for calculating measures CalculationFunctions functions = StandardComponents.calculationFunctions(); CalculationRules rules = CalculationRules.of(functions, marketDataBuilder.ratesLookup(LocalDate.of(2015, 4, 23))); // load the historical calibrated curves from which we will build our scenarios // these curves are provided in the example data environment SortedDictionary <LocalDate, RatesCurveGroup> historicalCurves = marketDataBuilder.loadAllRatesCurves(); // sorted list of dates for the available series of curves // the entries in the P&L vector we produce will correspond to these dates IList <LocalDate> scenarioDates = new List <LocalDate>(historicalCurves.Keys); // build the historical scenarios ScenarioDefinition historicalScenarios = buildHistoricalScenarios(historicalCurves, scenarioDates); // build a market data snapshot for the valuation date // this is the base snapshot which will be perturbed by the scenarios LocalDate valuationDate = LocalDate.of(2015, 4, 23); 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, historicalScenarios); Results results = runner.calculateMultiScenario(rules, trades, columns, scenarioMarketData, refData); // the results contain the one measure requested (Present 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<?> scenarioValuations = (com.opengamma.strata.data.scenario.ScenarioArray<?>) results.get(0, 0).getValue(); ScenarioArray <object> scenarioValuations = (ScenarioArray <object>)results.get(0, 0).Value; outputPnl(scenarioDates, scenarioValuations); }