//------------------------------------------------------------------------- public override DoubleArray apply(DoubleArray x) { // create child provider from matrix ImmutableRatesProvider childProvider = providerGenerator.generate(x); // calculate value for each trade using the child provider return(DoubleArray.of(trades.Count, i => measures.value(trades[i], childProvider))); }
//------------------------------------------------------------------------- // Check market data computation public virtual void market_data() { RatesCurveGroupDefinition group = GROUPS_SYN_EUR; RatesProvider multicurveTsLarge = MULTICURVE_INPUT_EUR_TSEMPTY.toBuilder().timeSeries(TS_LARGE).build(); MarketData madTsEmpty = CALIBRATOR_SYNTHETIC.marketData(group, MULTICURVE_INPUT_EUR_TSEMPTY, REF_DATA); MarketData madTsLarge = CALIBRATOR_SYNTHETIC.marketData(group, multicurveTsLarge, REF_DATA); assertEquals(madTsEmpty.ValuationDate, VALUATION_DATE); foreach (CurveDefinition entry in group.CurveDefinitions) { ImmutableList <CurveNode> nodes = entry.Nodes; foreach (CurveNode node in nodes) { ResolvedTrade tradeTsEmpty = node.resolvedTrade(1d, madTsEmpty, REF_DATA); double mqTsEmpty = MQ_MEASURES.value(tradeTsEmpty, MULTICURVE_INPUT_EUR_TSEMPTY); assertEquals(mqTsEmpty, (double?)madTsEmpty.getValue(node.requirements().GetEnumerator().next()), TOLERANCE_MQ); ResolvedTrade tradeTsLarge = node.resolvedTrade(1d, madTsLarge, REF_DATA); double mqTsLarge = MQ_MEASURES.value(tradeTsLarge, multicurveTsLarge); assertEquals(mqTsLarge, (double?)madTsLarge.getValue(node.requirements().GetEnumerator().next()), TOLERANCE_MQ); // Market Quote for Fixed v ibor swaps should have changed with the fixing if ((tradeTsLarge is ResolvedSwapTrade) && (((ResolvedSwapTrade)tradeTsLarge)).Product.getLegs(SwapLegType.IBOR).size() == 1) { assertTrue(Math.Abs(mqTsEmpty - mqTsLarge) > TOLERANCE_MQ); } } } assertEquals(madTsEmpty.TimeSeriesIds, ImmutableSet.of()); assertEquals(madTsLarge.TimeSeriesIds, ImmutableSet.of(IndexQuoteId.of(EUR_EURIBOR_3M), IndexQuoteId.of(EUR_EURIBOR_6M))); }
public virtual void check_pv_with_measures() { ImmutableRatesProvider multicurve = CALIBRATOR.calibrate(GROUP_DEFINITION, MARKET_QUOTES, REF_DATA); // the trades used for calibration IList <ResolvedTrade> trades = new List <ResolvedTrade>(); ImmutableList <CurveDefinition> curveGroups = GROUP_DEFINITION.CurveDefinitions; foreach (CurveDefinition entry in curveGroups) { ImmutableList <CurveNode> nodes = entry.Nodes; foreach (CurveNode node in nodes) { trades.Add(node.resolvedTrade(1d, MARKET_QUOTES, REF_DATA)); } } // Check PV = 0 foreach (ResolvedTrade trade in trades) { double pv = PV_MEASURES.value(trade, multicurve); assertEquals(pv, 0.0, TOLERANCE_PV); } }
public virtual void test_measureNotKnown() { CalibrationMeasures test = CalibrationMeasures.of("Test", TradeCalibrationMeasure.FRA_PAR_SPREAD); assertThrowsIllegalArg(() => test.value(SwapDummyData.SWAP_TRADE, ImmutableRatesProviderSimpleData.IMM_PROV_EUR_FIX), "Trade type 'ResolvedSwapTrade' is not supported for calibration"); }
/// <summary> /// Constructs the synthetic market data from an existing rates provider and the configuration of the new curves. /// </summary> /// <param name="group"> the curve group definition for the synthetic curves and instruments </param> /// <param name="inputProvider"> the input rates provider </param> /// <param name="refData"> the reference data, used to resolve the trades </param> /// <returns> the market data </returns> public ImmutableMarketData marketData(RatesCurveGroupDefinition group, RatesProvider inputProvider, ReferenceData refData) { // Retrieve the set of required indices and the list of required currencies ISet <Index> indicesRequired = new HashSet <Index>(); IList <Currency> ccyRequired = new List <Currency>(); foreach (RatesCurveGroupEntry entry in group.Entries) { indicesRequired.addAll(entry.Indices); ((IList <Currency>)ccyRequired).AddRange(entry.DiscountCurrencies); } // Retrieve the required time series if present in the original provider IDictionary <IndexQuoteId, LocalDateDoubleTimeSeries> ts = new Dictionary <IndexQuoteId, LocalDateDoubleTimeSeries>(); foreach (Index idx in Sets.intersection(inputProvider.TimeSeriesIndices, indicesRequired)) { ts[IndexQuoteId.of(idx)] = inputProvider.timeSeries(idx); } LocalDate valuationDate = inputProvider.ValuationDate; ImmutableList <CurveDefinition> curveGroups = group.CurveDefinitions; // Create fake market quotes of 0, only to be able to generate trades //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> mapId0 = new java.util.HashMap<>(); IDictionary <MarketDataId <object>, double> mapId0 = new Dictionary <MarketDataId <object>, double>(); foreach (CurveDefinition entry in curveGroups) { ImmutableList <CurveNode> nodes = entry.Nodes; for (int i = 0; i < nodes.size(); i++) { //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: for (com.opengamma.strata.data.MarketDataId<?> key : nodes.get(i).requirements()) foreach (MarketDataId <object> key in nodes.get(i).requirements()) { mapId0[key] = 0.0d; } } } ImmutableMarketData marketQuotes0 = ImmutableMarketData.of(valuationDate, mapId0); // Generate market quotes from the trades //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> mapIdSy = new java.util.HashMap<>(); IDictionary <MarketDataId <object>, object> mapIdSy = new Dictionary <MarketDataId <object>, object>(); foreach (CurveDefinition entry in curveGroups) { ImmutableList <CurveNode> nodes = entry.Nodes; foreach (CurveNode node in nodes) { ResolvedTrade trade = node.resolvedTrade(1d, marketQuotes0, refData); double mq = measures.value(trade, inputProvider); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: com.opengamma.strata.data.MarketDataId<?> k = node.requirements().iterator().next(); MarketDataId <object> k = node.requirements().GetEnumerator().next(); mapIdSy[k] = mq; } } // Generate quotes for FX pairs. The first currency is arbitrarily selected as starting point. // The crosses are automatically generated by the MarketDataFxRateProvider used in calibration. for (int loopccy = 1; loopccy < ccyRequired.Count; loopccy++) { CurrencyPair ccyPair = CurrencyPair.of(ccyRequired[0], ccyRequired[loopccy]); FxRateId fxId = FxRateId.of(ccyPair); mapIdSy[fxId] = FxRate.of(ccyPair, inputProvider.fxRate(ccyPair)); } return(ImmutableMarketData.builder(valuationDate).addValueMap(mapIdSy).addTimeSeriesMap(ts).build()); }