@Override public MutablePointSensitivities withCurrency(Currency currency) { sensitivities.replaceAll(ps -> ps.withCurrency(currency)); return this; }
public void test_withCurrency() { MutablePointSensitivities test = new MutablePointSensitivities(); test.addAll(Lists.newArrayList(CS3, CS2, CS1)); test.withCurrency(USD); assertEquals( test.getSensitivities(), ImmutableList.of(CS3.withCurrency(USD), CS2.withCurrency(USD), CS1.withCurrency(USD))); }
/** * Converts this instance to an equivalent amount in the specified currency. * <p> * The result will be expressed in terms of the given currency. * Any FX conversion that is required will use rates from the provider. * * @param resultCurrency the currency of the result * @param rateProvider the provider of FX rates * @return the converted instance, which should be expressed in the specified currency * @throws RuntimeException if no FX rate could be found */ @Override public default PointSensitivity convertedTo(Currency resultCurrency, FxRateProvider rateProvider) { if (getCurrency().equals(resultCurrency)) { return this; } double fxRate = rateProvider.fxRate(getCurrency(), resultCurrency); return withCurrency(resultCurrency).withSensitivity(fxRate * getSensitivity()); }