public void test_of_function() { MultiCurrencyAmount mca1 = MultiCurrencyAmount.of(CurrencyAmount.of(Currency.GBP, 10), CurrencyAmount.of(Currency.USD, 20)); MultiCurrencyAmount mca2 = MultiCurrencyAmount.of(CurrencyAmount.of(Currency.GBP, 10), CurrencyAmount.of(Currency.EUR, 30)); MultiCurrencyAmount mca3 = MultiCurrencyAmount.of(CurrencyAmount.of(Currency.USD, 40)); List<MultiCurrencyAmount> amounts = ImmutableList.of(mca1, mca2, mca3); MultiCurrencyAmountArray test = MultiCurrencyAmountArray.of(3, i -> amounts.get(i)); assertThat(test.get(0)).isEqualTo(mca1.plus(Currency.EUR, 0)); assertThat(test.get(1)).isEqualTo(mca2.plus(Currency.USD, 0)); assertThat(test.get(2)).isEqualTo(mca3.plus(Currency.GBP, 0).plus(Currency.EUR, 0)); }
private MultiCurrencyAmount currencyExposurePeriodsInternal(ResolvedSwapLeg leg, RatesProvider provider) { MultiCurrencyAmount total = MultiCurrencyAmount.empty(); for (SwapPaymentPeriod period : leg.getPaymentPeriods()) { if (!period.getPaymentDate().isBefore(provider.getValuationDate())) { total = total.plus(paymentPeriodPricer.currencyExposure(period, provider)); } } return total; }
public void test_currencyExposure() { CurrencyAmount pv = TRADE_PRICER.presentValue(FUTURE_TRADE, PROVIDER, LASTMARG_PRICE); PointSensitivities point = TRADE_PRICER.presentValueSensitivity(FUTURE_TRADE, PROVIDER); MultiCurrencyAmount expected = PROVIDER.currencyExposure(point).plus(pv); MultiCurrencyAmount computed = TRADE_PRICER.currencyExposure(FUTURE_TRADE, PROVIDER, LASTMARG_PRICE); assertEquals(computed, expected); }
public void test_presentValue() { MultiCurrencyAmount computedWithPayLeg = PRICER.presentValue(TRADE_PAYLEG, RATES, VOLS); MultiCurrencyAmount computedWithPremium = PRICER.presentValue(TRADE_PREMIUM, RATES, VOLS); MultiCurrencyAmount pvOneLeg = PRICER_PRODUCT.presentValue(CAP_ONE_LEG, RATES, VOLS); MultiCurrencyAmount pvTwoLegs = PRICER_PRODUCT.presentValue(CAP_TWO_LEGS, RATES, VOLS); CurrencyAmount pvPrem = PRICER_PREMIUM.presentValue(PREMIUM, RATES); assertEquals(computedWithPayLeg, pvTwoLegs); assertEquals(computedWithPremium, pvOneLeg.plus(pvPrem)); }
public void test_currencyExposure_crossCurrency() { PointSensitivities point = SWAP_PRODUCT_PRICER.parRateSensitivity(SWAP_CROSS_CURRENCY, RATES_GBP_USD).build(); MultiCurrencyAmount expected = RATES_GBP_USD.currencyExposure(point) .plus(SWAP_PRODUCT_PRICER.presentValue(SWAP_CROSS_CURRENCY, RATES_GBP_USD)); MultiCurrencyAmount computed = SWAP_PRODUCT_PRICER.currencyExposure(SWAP_CROSS_CURRENCY, RATES_GBP_USD); assertEquals(computed, expected); MultiCurrencyAmount fromTrade = SWAP_TRADE_PRICER.currencyExposure(SWAP_TRADE_CROSS_CURRENCY, RATES_GBP_USD); assertEquals(fromTrade, computed); }
public void test_currentCash_onPay() { MultiCurrencyAmount cc1 = PRICER.currentCash(CAP_ONE_LEG, RATES_PAY, VOLS_PAY); MultiCurrencyAmount cc2 = PRICER.currentCash(CAP_TWO_LEGS, RATES_PAY, VOLS_PAY); CurrencyAmount ccCap = PRICER_CAP_LEG.currentCash(CAP_LEG, RATES_PAY, VOLS_PAY); CurrencyAmount ccPay = PRICER_PAY_LEG.currentCash(PAY_LEG, RATES_PAY); assertEquals(cc1, MultiCurrencyAmount.of(ccCap)); assertEquals(cc2, MultiCurrencyAmount.of(ccCap).plus(ccPay)); }
public void test_currencyExposure_singleCurrency() { PointSensitivities point = SWAP_PRODUCT_PRICER.parRateSensitivity(SWAP, RATES_GBP).build(); MultiCurrencyAmount expected = RATES_GBP.currencyExposure(point) .plus(SWAP_PRODUCT_PRICER.presentValue(SWAP, RATES_GBP)); MultiCurrencyAmount computed = SWAP_PRODUCT_PRICER.currencyExposure(SWAP, RATES_GBP); assertEquals(computed, expected); MultiCurrencyAmount fromTrade = SWAP_TRADE_PRICER.currencyExposure(SWAP_TRADE, RATES_GBP); assertEquals(fromTrade, computed); }
public void test_currencyExposure() { ResolvedSwapLeg expSwapLeg = IBOR_SWAP_LEG_REC_GBP; PointSensitivities point = PRICER_LEG.presentValueSensitivity(expSwapLeg, RATES_GBP).build(); MultiCurrencyAmount expected = RATES_GBP.currencyExposure(point).plus(PRICER_LEG.presentValue(expSwapLeg, RATES_GBP)); MultiCurrencyAmount computed = PRICER_LEG.currencyExposure(expSwapLeg, RATES_GBP); assertEquals(computed, expected); }
public void test_plus_MultiCurrencyAmount_empty() { CurrencyAmount ca = CurrencyAmount.of(Currency.AUD, 117); CurrencyAmount cb = CurrencyAmount.of(Currency.USD, 12); MultiCurrencyAmount mc1 = MultiCurrencyAmount.of(ca, cb); MultiCurrencyAmount mc2 = MultiCurrencyAmount.of(); MultiCurrencyAmount test = mc1.plus(mc2); assertMCA(test, ca, cb); }
public void test_plus_CurrencyAmount_add() { CurrencyAmount ca = CurrencyAmount.of(Currency.AUD, 117); CurrencyAmount cb = CurrencyAmount.of(Currency.USD, 12); CurrencyAmount cc = CurrencyAmount.of(Currency.NZD, 3); MultiCurrencyAmount mc1 = MultiCurrencyAmount.of(ca, cb); MultiCurrencyAmount test = mc1.plus(cc); assertMCA(test, ca, cb, cc); }
public void test_currencyExposureFromCleanPrice() { MultiCurrencyAmount computed = PRICER.currencyExposureFromCleanPrice( TRADE_STANDARD, RATES_PROVIDER, ISSUER_RATES_PROVIDER, REF_DATA, TRADE_PRICE); PointSensitivities point = PRICER.presentValueSensitivityFromCleanPrice( TRADE_STANDARD, RATES_PROVIDER, ISSUER_RATES_PROVIDER, REF_DATA, TRADE_PRICE); MultiCurrencyAmount expected = RATES_PROVIDER.currencyExposure(point).plus( PRICER.presentValueFromCleanPrice(TRADE_STANDARD, RATES_PROVIDER, ISSUER_RATES_PROVIDER, REF_DATA, TRADE_PRICE)); assertEquals(computed.getAmounts().size(), 1); assertEquals(computed.getAmount(USD).getAmount(), expected.getAmount(USD).getAmount(), NOTIONAL * QUANTITY * TOL); }
public void test_currencyExposureFromCleanPriceWithZSpread() { MultiCurrencyAmount computed = PRICER.currencyExposureFromCleanPriceWithZSpread( TRADE_STANDARD, RATES_PROVIDER, ISSUER_RATES_PROVIDER, REF_DATA, TRADE_PRICE, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); PointSensitivities point = PRICER.presentValueSensitivityFromCleanPriceWithZSpread( TRADE_STANDARD, RATES_PROVIDER, ISSUER_RATES_PROVIDER, REF_DATA, TRADE_PRICE, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); MultiCurrencyAmount expected = RATES_PROVIDER.currencyExposure(point).plus( PRICER.presentValueFromCleanPriceWithZSpread(TRADE_STANDARD, RATES_PROVIDER, ISSUER_RATES_PROVIDER, REF_DATA, TRADE_PRICE, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR)); assertEquals(computed.getAmounts().size(), 1); assertEquals(computed.getAmount(USD).getAmount(), expected.getAmount(USD).getAmount(), NOTIONAL * QUANTITY * TOL); }
public void test_currencyExposureWithZSpread() { MultiCurrencyAmount computed = PRICER.currencyExposureWithZSpread( TRADE_STANDARD, RATES_PROVIDER, ISSUER_RATES_PROVIDER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); PointSensitivities point = PRICER.presentValueSensitivityWithZSpread( TRADE_STANDARD, RATES_PROVIDER, ISSUER_RATES_PROVIDER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); MultiCurrencyAmount expected = RATES_PROVIDER.currencyExposure(point).plus(PRICER.presentValueWithZSpread( TRADE_STANDARD, RATES_PROVIDER, ISSUER_RATES_PROVIDER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR)); assertEquals(computed.getAmounts().size(), 1); assertEquals(computed.getAmount(USD).getAmount(), expected.getAmount(USD).getAmount(), NOTIONAL * QUANTITY * TOL); }
public void test_currencyExposure() { MultiCurrencyAmount computed = PRICER.currencyExposure(TRADE_STANDARD, RATES_PROVIDER, ISSUER_RATES_PROVIDER); PointSensitivities point = PRICER.presentValueSensitivity( TRADE_STANDARD, RATES_PROVIDER, ISSUER_RATES_PROVIDER); MultiCurrencyAmount expected = RATES_PROVIDER.currencyExposure(point).plus( PRICER.presentValue(TRADE_STANDARD, RATES_PROVIDER, ISSUER_RATES_PROVIDER)); assertEquals(computed.getAmounts().size(), 1); assertEquals(computed.getAmount(USD).getAmount(), expected.getAmount(USD).getAmount(), NOTIONAL * QUANTITY * TOL); }
public void test_currencyExposure() { MultiCurrencyAmount computed1 = TRADE_PRICER.currencyExposure(CMS_TRADE_PREMIUM, RATES_PROVIDER, VOLATILITIES); MultiCurrencyAmount computed2 = TRADE_PRICER.currencyExposure(CMS_TRADE, RATES_PROVIDER, VOLATILITIES); MultiCurrencyAmount pv1 = TRADE_PRICER.presentValue(CMS_TRADE_PREMIUM, RATES_PROVIDER, VOLATILITIES); PointSensitivities pt1 = TRADE_PRICER.presentValueSensitivityRates(CMS_TRADE_PREMIUM, RATES_PROVIDER, VOLATILITIES); MultiCurrencyAmount expected1 = RATES_PROVIDER.currencyExposure(pt1).plus(pv1); MultiCurrencyAmount pv2 = TRADE_PRICER.presentValue(CMS_TRADE, RATES_PROVIDER, VOLATILITIES); PointSensitivities pt2 = TRADE_PRICER.presentValueSensitivityRates(CMS_TRADE, RATES_PROVIDER, VOLATILITIES); MultiCurrencyAmount expected2 = RATES_PROVIDER.currencyExposure(pt2).plus(pv2); assertEquals(computed1.getAmount(EUR).getAmount(), expected1.getAmount(EUR).getAmount(), NOTIONAL_VALUE * TOL); assertEquals(computed2.getAmount(EUR).getAmount(), expected2.getAmount(EUR).getAmount(), NOTIONAL_VALUE * TOL); }
public void test_currencyExposure() { MultiCurrencyAmount ceComputed = PRICER_TRADE.currencyExposure(OPTION_TRADE, RATES_PROVIDER, VOLS); PointSensitivities point = PRICER_TRADE.presentValueSensitivityRatesStickyStrike(OPTION_TRADE, RATES_PROVIDER, VOLS); MultiCurrencyAmount pv = PRICER_TRADE.presentValue(OPTION_TRADE, RATES_PROVIDER, VOLS); MultiCurrencyAmount ceExpected = RATES_PROVIDER.currencyExposure(point).plus(pv); assertEquals(ceComputed.size(), 2); assertEquals(ceComputed.getAmount(EUR).getAmount(), ceExpected.getAmount(EUR).getAmount(), TOL * NOTIONAL); assertEquals(ceComputed.getAmount(USD).getAmount(), ceExpected.getAmount(USD).getAmount(), TOL * NOTIONAL); }
public void test_currencyExposure() { MultiCurrencyAmount computed1 = PRICER.currencyExposure(CAP_ONE_LEG, RATES, VOLS); MultiCurrencyAmount computed2 = PRICER.currencyExposure(CAP_TWO_LEGS, RATES, VOLS); MultiCurrencyAmount pv1 = PRICER.presentValue(CAP_ONE_LEG, RATES, VOLS); MultiCurrencyAmount pv2 = PRICER.presentValue(CAP_TWO_LEGS, RATES, VOLS); PointSensitivityBuilder point1 = PRICER.presentValueSensitivityRates(CAP_ONE_LEG, RATES, VOLS); PointSensitivityBuilder point2 = PRICER.presentValueSensitivityRates(CAP_TWO_LEGS, RATES, VOLS); MultiCurrencyAmount expected1 = RATES.currencyExposure(point1.build()).plus(pv1); MultiCurrencyAmount expected2 = RATES.currencyExposure(point2.build()).plus(pv2); assertEquals(computed1.getAmount(EUR).getAmount(), expected1.getAmount(EUR).getAmount(), NOTIONAL_VALUE * TOL); assertEquals(computed2.getAmount(EUR).getAmount(), expected2.getAmount(EUR).getAmount(), NOTIONAL_VALUE * TOL); }
public void test_currencyExposure() { MultiCurrencyAmount computed1 = PRICER.currencyExposure(CAP_ONE_LEG, RATES, VOLS); MultiCurrencyAmount computed2 = PRICER.currencyExposure(CAP_TWO_LEGS, RATES, VOLS); MultiCurrencyAmount pv1 = PRICER.presentValue(CAP_ONE_LEG, RATES, VOLS); MultiCurrencyAmount pv2 = PRICER.presentValue(CAP_TWO_LEGS, RATES, VOLS); PointSensitivityBuilder point1 = PRICER.presentValueSensitivityRates(CAP_ONE_LEG, RATES, VOLS); PointSensitivityBuilder point2 = PRICER.presentValueSensitivityRates(CAP_TWO_LEGS, RATES, VOLS); MultiCurrencyAmount expected1 = RATES.currencyExposure(point1.build()).plus(pv1); MultiCurrencyAmount expected2 = RATES.currencyExposure(point2.build()).plus(pv2); assertEquals(computed1.getAmount(EUR).getAmount(), expected1.getAmount(EUR).getAmount(), NOTIONAL_VALUE * TOL); assertEquals(computed2.getAmount(EUR).getAmount(), expected2.getAmount(EUR).getAmount(), NOTIONAL_VALUE * TOL); }
public void test_currencyExposure() { ImmutableRatesProvider prov = ImmutableRatesProvider.builder(VAL_DATE) .discountCurve(GBP, DISCOUNT_CURVE_GBP) .build(); MultiCurrencyAmount computed = PRICER.currencyExposure(PERIOD, prov); PointSensitivities point = PRICER.presentValueSensitivity(PERIOD, prov).build(); MultiCurrencyAmount expected = prov.currencyExposure(point) .plus(CurrencyAmount.of(GBP, PRICER.presentValue(PERIOD, prov))); assertEquals(computed, expected); }
public void test_currencyExposure_from_pt_sensitivity_inverse() { MultiCurrencyAmount ceDirect = PRICER.currencyExposure(NDF_INVERSE, PROVIDER); PointSensitivities pts = PRICER.presentValueSensitivity(NDF_INVERSE, PROVIDER); MultiCurrencyAmount cePts = PROVIDER.currencyExposure(pts); CurrencyAmount cePv = PRICER.presentValue(NDF_INVERSE, PROVIDER); MultiCurrencyAmount ceExpected = cePts.plus(cePv); assertEquals(ceDirect.getAmount(USD).getAmount(), ceExpected.getAmount(USD).getAmount(), NOMINAL_USD * TOL); assertEquals(ceDirect.getAmount(KRW).getAmount(), ceExpected.getAmount(KRW).getAmount(), NOMINAL_USD * TOL * FX_MATRIX.fxRate(USD, KRW)); }