Ejemplo n.º 1
0
 /**
  * Merges discounting curve providers.
  *
  * @param providers The providers to merge, not null or empty
  * @return The merged providers
  */
 public static MulticurveProviderDiscount mergeDiscountingProviders(
     final Collection<MulticurveProviderDiscount> providers) {
   ArgumentChecker.notNull(providers, "providers");
   ArgumentChecker.notEmpty(providers, "providers");
   final MulticurveProviderDiscount result = new MulticurveProviderDiscount();
   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());
     }
     final FXMatrix matrix = provider.getFxRates();
     final Collection<Currency> currencies = matrix.getCurrencies().keySet();
     final Iterator<Currency> iterator = currencies.iterator();
     if (currencies.size() > 0) {
       final Currency initialCurrency = iterator.next();
       while (iterator.hasNext()) {
         final Currency otherCurrency = iterator.next();
         result
             .getFxRates()
             .addCurrency(
                 initialCurrency, otherCurrency, matrix.getFxRate(initialCurrency, otherCurrency));
       }
     }
   }
   return result;
 }
 @Override
 protected void buildMessage(
     final FudgeSerializer serializer, final MutableFudgeMsg message, final FXMatrix object) {
   final Map<Currency, Integer> currencies = object.getCurrencies();
   for (final Map.Entry<Currency, Integer> entry : currencies.entrySet()) {
     message.add(CURRENCY_FIELD, entry.getKey().getCode());
     message.add(ORDER_FIELD, entry.getValue());
   }
   final double[][] rates = object.getRates();
   for (final double[] array : rates) {
     message.add(ENTRIES_FIELD, array.length);
     final MutableFudgeMsg msg = serializer.newMessage();
     serializer.addToMessageWithClassHeaders(msg, ROW_FIELD, null, array);
     message.add(FX_RATES_FIELD, msg);
   }
 }
Ejemplo n.º 3
0
 /**
  * Merges a discounting curve provider and an FX matrix.
  *
  * @param provider The provider, not null
  * @param matrix The FX matrix, not null
  * @return The merged provider
  */
 public static MulticurveProviderDiscount mergeDiscountingProviders(
     final MulticurveProviderDiscount provider, final FXMatrix matrix) {
   ArgumentChecker.notNull(provider, "provider");
   ArgumentChecker.notNull(matrix, "matrix");
   final MulticurveProviderDiscount result = provider.copy();
   final Collection<Currency> currencies = matrix.getCurrencies().keySet();
   final Iterator<Currency> iterator = currencies.iterator();
   if (currencies.size() > 0) {
     final Currency initialCurrency = iterator.next();
     while (iterator.hasNext()) {
       final Currency otherCurrency = iterator.next();
       result
           .getFxRates()
           .addCurrency(
               initialCurrency, otherCurrency, matrix.getFxRate(initialCurrency, otherCurrency));
     }
   }
   return result;
 }
Ejemplo n.º 4
0
 /**
  * Merges Hull-White one-factor providers.
  *
  * @param providers The providers to merge, not null or empty
  * @return The merged providers
  */
 public static HullWhiteOneFactorProviderDiscount mergeHullWhiteProviders(
     final Collection<HullWhiteOneFactorProviderDiscount> providers) {
   ArgumentChecker.notNull(providers, "providers");
   ArgumentChecker.notEmpty(providers, "providers");
   final Iterator<HullWhiteOneFactorProviderDiscount> iter = providers.iterator();
   final HullWhiteOneFactorProviderDiscount result = iter.next().copy();
   while (iter.hasNext()) {
     final HullWhiteOneFactorProviderDiscount provider = iter.next().copy();
     final MulticurveProviderDiscount underlying = provider.getMulticurveProvider().copy();
     for (final Map.Entry<Currency, YieldAndDiscountCurve> entry :
         underlying.getDiscountingCurves().entrySet()) {
       result.setCurve(entry.getKey(), entry.getValue());
     }
     for (final Map.Entry<IborIndex, YieldAndDiscountCurve> entry :
         underlying.getForwardIborCurves().entrySet()) {
       result.setCurve(entry.getKey(), entry.getValue());
     }
     for (final Map.Entry<IndexON, YieldAndDiscountCurve> entry :
         underlying.getForwardONCurves().entrySet()) {
       result.setCurve(entry.getKey(), entry.getValue());
     }
     final FXMatrix matrix = underlying.getFxRates();
     final Collection<Currency> currencies = matrix.getCurrencies().keySet();
     final Iterator<Currency> iterator = currencies.iterator();
     if (currencies.size() > 0) {
       final Currency initialCurrency = iterator.next();
       while (iterator.hasNext()) {
         final Currency otherCurrency = iterator.next();
         underlying
             .getFxRates()
             .addCurrency(
                 initialCurrency, otherCurrency, matrix.getFxRate(initialCurrency, otherCurrency));
       }
     }
     // TODO actually merge.
   }
   return result;
 }