//------------------------------------------------------------------------- public virtual void test_tradesInitialGuesses() { RatesCurveGroupDefinition test = RatesCurveGroupDefinition.builder().name(CurveGroupName.of("Test")).addCurve(CURVE_DEFN1, GBP, GBP_LIBOR_1M, GBP_LIBOR_3M).build(); MarketData marketData = ImmutableMarketData.of(date(2015, 6, 30), ImmutableMap.of(GBP_LIBOR_1M_ID, 0.5d, GBP_LIBOR_3M_ID, 1.5d)); Trade trade1 = NODE1.trade(1d, marketData, REF_DATA); Trade trade2 = NODE2.trade(1d, marketData, REF_DATA); assertEquals(test.TotalParameterCount, 2); assertEquals(test.resolvedTrades(marketData, REF_DATA), ImmutableList.of(trade1, trade2)); assertEquals(test.initialGuesses(marketData), ImmutableList.of(0.5d, 1.5d)); }
/// <summary> /// Calibrates a list of curve groups, each containing one or more curves. /// <para> /// The calibration is defined using a list of <seealso cref="RatesCurveGroupDefinition"/>. /// Observable market data and existing known data are also needed to complete the calibration. /// </para> /// <para> /// A curve must only exist in one group. /// /// </para> /// </summary> /// <param name="allGroupsDefn"> the curve group definitions </param> /// <param name="knownData"> the starting data for the calibration </param> /// <param name="marketData"> the market data required to build a trade for the instrument </param> /// <param name="refData"> the reference data, used to resolve the trades </param> /// <returns> the rates provider resulting from the calibration </returns> public ImmutableRatesProvider calibrate(IList <RatesCurveGroupDefinition> allGroupsDefn, ImmutableRatesProvider knownData, MarketData marketData, ReferenceData refData) { // this method effectively takes one CurveGroupDefinition // the list is a split of the definition, not multiple independent definitions if (!knownData.ValuationDate.Equals(marketData.ValuationDate)) { throw new System.ArgumentException(Messages.format("Valuation dates do not match: {} and {}", knownData.ValuationDate, marketData.ValuationDate)); } // perform calibration one group at a time, building up the result by mutating these variables ImmutableRatesProvider providerCombined = knownData; ImmutableList <CurveParameterSize> orderPrev = ImmutableList.of(); ImmutableMap <CurveName, JacobianCalibrationMatrix> jacobians = ImmutableMap.of(); foreach (RatesCurveGroupDefinition groupDefn in allGroupsDefn) { if (groupDefn.Entries.Empty) { continue; } RatesCurveGroupDefinition groupDefnBound = groupDefn.bindTimeSeries(knownData.ValuationDate, knownData.TimeSeries); // combine all data in the group into flat lists ImmutableList <ResolvedTrade> trades = groupDefnBound.resolvedTrades(marketData, refData); ImmutableList <double> initialGuesses = groupDefnBound.initialGuesses(marketData); ImmutableList <CurveParameterSize> orderGroup = toOrder(groupDefnBound); ImmutableList <CurveParameterSize> orderPrevAndGroup = ImmutableList.builder <CurveParameterSize>().addAll(orderPrev).addAll(orderGroup).build(); // calibrate RatesProviderGenerator providerGenerator = ImmutableRatesProviderGenerator.of(providerCombined, groupDefnBound, refData); DoubleArray calibratedGroupParams = calibrateGroup(providerGenerator, trades, initialGuesses, orderGroup); ImmutableRatesProvider calibratedProvider = providerGenerator.generate(calibratedGroupParams); // use calibration to build Jacobian matrices if (groupDefnBound.ComputeJacobian) { jacobians = updateJacobiansForGroup(calibratedProvider, trades, orderGroup, orderPrev, orderPrevAndGroup, jacobians); } ImmutableMap <CurveName, DoubleArray> sensitivityToMarketQuote = ImmutableMap.of(); if (groupDefnBound.ComputePvSensitivityToMarketQuote) { ImmutableRatesProvider providerWithJacobian = providerGenerator.generate(calibratedGroupParams, jacobians); sensitivityToMarketQuote = sensitivityToMarketQuoteForGroup(providerWithJacobian, trades, orderGroup); } orderPrev = orderPrevAndGroup; // use Jacobians to build output curves providerCombined = providerGenerator.generate(calibratedGroupParams, jacobians, sensitivityToMarketQuote); } // return the calibrated provider return(providerCombined); }