public void test_convertedTo_rateProvider_noConversionSize1() { FxRateProvider provider = (ccy1, ccy2) -> { throw new IllegalArgumentException(); }; MultiCurrencyAmount test = MultiCurrencyAmount.of(CA2); assertEquals(test.convertedTo(CCY2, provider), CA2); }
public void test_convertedTo_rateProvider_conversionSize1() { FxRateProvider provider = (ccy1, ccy2) -> { if (ccy1.equals(CCY1) && ccy2.equals(CCY2)) { return 2.5d; } throw new IllegalArgumentException(); }; MultiCurrencyAmount test = MultiCurrencyAmount.of(CA1); assertEquals(test.convertedTo(CCY2, provider), CurrencyAmount.of(CCY2, AMT1 * 2.5d)); }
public void test_currencyExposure() { CurrencyAmount pv = PRICER.presentValue(NDF, PROVIDER); MultiCurrencyAmount ce = PRICER.currencyExposure(NDF, PROVIDER); CurrencyAmount ceConverted = ce.convertedTo(pv.getCurrency(), PROVIDER); assertEquals(pv.getAmount(), ceConverted.getAmount(), NOMINAL_USD * TOL); }
public void test_parSpread_beforeStart() { double parSpread = PRICER.parSpread(SWAP_PRODUCT, PROVIDER); ResolvedFxSwap product = ResolvedFxSwap.ofForwardPoints( CurrencyAmount.of(USD, NOMINAL_USD), KRW, FX_RATE, FX_FWD_POINTS + parSpread, PAYMENT_DATE_NEAR, PAYMENT_DATE_FAR); MultiCurrencyAmount pv = PRICER.presentValue(product, PROVIDER); assertEquals(pv.convertedTo(USD, PROVIDER).getAmount(), 0d, NOMINAL_USD * TOL); }
public void test_convertedTo_rateProvider_conversionSize2() { FxRateProvider provider = (ccy1, ccy2) -> { if (ccy1.equals(ccy2)) { return 1d; } if (ccy1.equals(CCY1) && ccy2.equals(CCY2)) { return 2.5d; } throw new IllegalArgumentException(); }; MultiCurrencyAmount test = MultiCurrencyAmount.of(CA1, CA2); assertEquals(test.convertedTo(CCY2, provider), CA2.plus(CurrencyAmount.of(CCY2, AMT1 * 2.5d))); }
public void test_parSpread() { double spread = PRICER.parSpread(FWD, PROVIDER); ResolvedFxSingle fwdSp = ResolvedFxSingle.of(CurrencyAmount.of(USD, NOMINAL_USD), FxRate.of(USD, KRW, FX_RATE + spread), PAYMENT_DATE); MultiCurrencyAmount pv = PRICER.presentValue(fwdSp, PROVIDER); assertEquals(pv.convertedTo(USD, PROVIDER).getAmount(), 0d, NOMINAL_USD * TOL); }
MultiCurrencyAmount pvFx = FX_PRICER.presentValue( ((ResolvedFxSwapTrade) eurTrades.get(i)).getProduct(), result); assertEquals(pvFx.convertedTo(USD, result).getAmount(), 0.0, TOLERANCE_PV);
/** * Calculates the par spread. * <p> * This is the spread that should be added to the FX points to have a zero value. * * @param fx the product * @param provider the rates provider * @return the spread */ public double parSpread(ResolvedFxSingle fx, RatesProvider provider) { Payment basePayment = fx.getBaseCurrencyPayment(); Payment counterPayment = fx.getCounterCurrencyPayment(); MultiCurrencyAmount pv = presentValue(fx, provider); double pvCounterCcy = pv.convertedTo(counterPayment.getCurrency(), provider).getAmount(); double dfEnd = provider.discountFactor(counterPayment.getCurrency(), fx.getPaymentDate()); double notionalBaseCcy = basePayment.getAmount(); return pvCounterCcy / (notionalBaseCcy * dfEnd); }
public void test_parSpread_started() { ResolvedFxSwap product = ResolvedFxSwap.ofForwardPoints( CurrencyAmount.of(USD, NOMINAL_USD), KRW, FX_RATE, FX_FWD_POINTS, PAYMENT_DATE_PAST, PAYMENT_DATE_NEAR); double parSpread = PRICER.parSpread(product, PROVIDER); ResolvedFxSwap productPar = ResolvedFxSwap.ofForwardPoints( CurrencyAmount.of(USD, NOMINAL_USD), KRW, FX_RATE, FX_FWD_POINTS + parSpread, PAYMENT_DATE_PAST, PAYMENT_DATE_NEAR); MultiCurrencyAmount pv = PRICER.presentValue(productPar, PROVIDER); assertEquals(pv.convertedTo(USD, PROVIDER).getAmount(), 0d, NOMINAL_USD * TOL); }
/** * Calculates the par spread. * <p> * The par spread is the spread that should be added to the FX forward points to have a zero value. * * @param swap the product * @param provider the rates provider * @return the spread */ public double parSpread(ResolvedFxSwap swap, RatesProvider provider) { Payment counterPaymentNear = swap.getNearLeg().getCounterCurrencyPayment(); MultiCurrencyAmount pv = presentValue(swap, provider); double pvCounterCcy = pv.convertedTo(counterPaymentNear.getCurrency(), provider).getAmount(); double dfEnd = provider.discountFactor(counterPaymentNear.getCurrency(), swap.getFarLeg().getPaymentDate()); double notionalBaseCcy = swap.getNearLeg().getBaseCurrencyPayment().getAmount(); return -pvCounterCcy / (notionalBaseCcy * dfEnd); }
MultiCurrencyAmount pvFx = FX_PRICER.presentValue( ((ResolvedFxSwapTrade) eurTrades.get(i)).getProduct(), result); assertEquals(pvFx.convertedTo(USD, result).getAmount(), 0.0, TOLERANCE_PV); MultiCurrencyAmount pvFx = SWAP_PRICER.presentValue( ((ResolvedSwapTrade) eurTrades.get(EUR_DSC_NB_FX_NODES + i)).getProduct(), result); assertEquals(pvFx.convertedTo(USD, result).getAmount(), 0.0, TOLERANCE_PV);
/** * Calculates the par spread sensitivity to the curves. * <p> * The sensitivity is reported in the counter currency of the product, but is actually dimensionless. * * @param swap the product * @param provider the rates provider * @return the spread curve sensitivity */ public PointSensitivities parSpreadSensitivity(ResolvedFxSwap swap, RatesProvider provider) { Payment counterPaymentNear = swap.getNearLeg().getCounterCurrencyPayment(); MultiCurrencyAmount pv = presentValue(swap, provider); double pvCounterCcy = pv.convertedTo(counterPaymentNear.getCurrency(), provider).getAmount(); double dfEnd = provider.discountFactor(counterPaymentNear.getCurrency(), swap.getFarLeg().getPaymentDate()); double notionalBaseCcy = swap.getNearLeg().getBaseCurrencyPayment().getAmount(); double ps = -pvCounterCcy / (notionalBaseCcy * dfEnd); // backward sweep double psBar = 1d; double pvCounterCcyBar = -1d / (notionalBaseCcy * dfEnd) * psBar; double dfEndBar = -ps / dfEnd * psBar; ZeroRateSensitivity ddfEnddr = provider.discountFactors(counterPaymentNear.getCurrency()) .zeroRatePointSensitivity(swap.getFarLeg().getPaymentDate()); PointSensitivities result = ddfEnddr.multipliedBy(dfEndBar).build(); PointSensitivities dpvdr = presentValueSensitivity(swap, provider); PointSensitivities dpvdrConverted = dpvdr.convertedTo(counterPaymentNear.getCurrency(), provider); return result.combinedWith(dpvdrConverted.multipliedBy(pvCounterCcyBar)); }