ProviderUtils { public static MulticurveProviderDiscount mergeDiscountingProviders(final Collection<MulticurveProviderDiscount> providers) { ArgumentChecker.notNull(providers, "providers"); ArgumentChecker.notEmpty(providers, "providers"); final MulticurveProviderDiscount result = new MulticurveProviderDiscount(); FXMatrix matrix = new FXMatrix(); int loop = 0; for (final MulticurveProviderDiscount provider : providers) { for (final Map.Entry<Currency, YieldAndDiscountCurve> entry : provider.getDiscountingCurves().entrySet()) { result.setCurve(entry.getKey(), entry.getValue()); } for (final Map.Entry<IborIndex, YieldAndDiscountCurve> entry : provider.getForwardIborCurves().entrySet()) { result.setCurve(entry.getKey(), entry.getValue()); } for (final Map.Entry<IndexON, YieldAndDiscountCurve> entry : provider.getForwardONCurves().entrySet()) { result.setCurve(entry.getKey(), entry.getValue()); } if (loop == 0) { matrix = new FXMatrix(provider.getFxRates()); loop++; } else { matrix = FXMatrixUtils.merge(matrix, provider.getFxRates()); } } result.setForexMatrix(matrix); return result; }  static MulticurveProviderDiscount mergeDiscountingProviders(final Collection<MulticurveProviderDiscount> providers); static MulticurveProviderDiscount mergeWithDuplicateDiscountingProviders(final Collection<MulticurveProviderDiscount> providers); static HullWhiteOneFactorProviderDiscount mergeHullWhiteProviders(final Collection<HullWhiteOneFactorProviderDiscount> providers); static MulticurveProviderDiscount mergeDiscountingProviders(final MulticurveProviderDiscount provider, final FXMatrix matrix); static HullWhiteOneFactorProviderDiscount mergeHullWhiteProviders(final HullWhiteOneFactorProviderDiscount provider, final FXMatrix matrix);  }
@Test public void mergeUSD136() { final ArrayList<MulticurveProviderDiscount> multicurveList = new ArrayList<>(); multicurveList.add(MULTICURVE_USD136); final MulticurveProviderDiscount merged1 = ProviderUtils.mergeDiscountingProviders(multicurveList); assertEquals("ProviderUtils - Merge multi-curve provider", MULTICURVE_USD136.getCurve(USD), merged1.getCurve(USD)); for (int loopi = 0; loopi < INDEX_USD136.length; loopi++) { assertEquals("ProviderUtils - Merge multi-curve provider", MULTICURVE_USD136.getCurve(INDEX_USD136[loopi]), merged1.getCurve(INDEX_USD136[loopi])); } assertTrue("ProviderUtils - Merge multi-curve provider", FXMatrixUtils.compare(MULTICURVE_USD136.getFxRates(), merged1.getFxRates(), TOLERANCE_FX_RATE)); }
@Test public void mergeUSDEURForex() { final ArrayList<MulticurveProviderDiscount> multicurveList = new ArrayList<>(); multicurveList.add(MULTICURVE_USDEUR_FX); final MulticurveProviderDiscount merged1 = ProviderUtils.mergeDiscountingProviders(multicurveList); assertEquals("ProviderUtils - Merge multi-curve provider", MULTICURVE_USDEUR_FX.getCurve(USD), merged1.getCurve(USD)); assertEquals("ProviderUtils - Merge multi-curve provider", MULTICURVE_USDEUR_FX.getCurve(EUR), merged1.getCurve(EUR)); assertTrue("ProviderUtils - Merge multi-curve provider", FXMatrixUtils.compare(MULTICURVE_USDEUR_FX.getFxRates(), merged1.getFxRates(), TOLERANCE_FX_RATE)); }