public void test_minus_double() { CurrencyAmount test = CCY_AMOUNT.minus(AMT2); assertEquals(test, CurrencyAmount.of(CCY1, AMT1 - AMT2)); }
public void test_minus_CurrencyAmount_null() { assertThrowsIllegalArg(() -> CCY_AMOUNT.minus(null)); }
public void test_minus_CurrencyAmount() { CurrencyAmount ccyAmount = CurrencyAmount.of(CCY1, AMT2); CurrencyAmount test = CCY_AMOUNT.minus(ccyAmount); assertEquals(test, CurrencyAmount.of(CCY1, AMT1 - AMT2)); }
private static ImmutableList<SwapPaymentEvent> createStandardEvents( List<NotionalPaymentPeriod> payPeriods, LocalDate initialExchangePaymentDate, boolean initialExchange, boolean intermediateExchange, boolean finalExchange) { NotionalPaymentPeriod firstPeriod = payPeriods.get(0); ImmutableList.Builder<SwapPaymentEvent> events = ImmutableList.builder(); if (initialExchange) { events.add(NotionalExchange.of(firstPeriod.getNotionalAmount().negated(), initialExchangePaymentDate)); } if (intermediateExchange) { for (int i = 0; i < payPeriods.size() - 1; i++) { NotionalPaymentPeriod period1 = payPeriods.get(i); NotionalPaymentPeriod period2 = payPeriods.get(i + 1); if (period1.getNotionalAmount().getAmount() != period2.getNotionalAmount().getAmount()) { events.add(NotionalExchange.of( period1.getNotionalAmount().minus(period2.getNotionalAmount()), period1.getPaymentDate())); } } } if (finalExchange) { NotionalPaymentPeriod lastPeriod = payPeriods.get(payPeriods.size() - 1); events.add(NotionalExchange.of(lastPeriod.getNotionalAmount(), lastPeriod.getPaymentDate())); } return events.build(); }
public void test_minus_CurrencyAmount_wrongCurrency() { assertThrowsIllegalArg(() -> CCY_AMOUNT.minus(CurrencyAmount.of(CCY2, AMT2))); }
/** * Returns a copy of this {@code CurrencyAmount} with the specified amount subtracted. * <p> * This subtracts the specified amount to this monetary amount, returning a new object. * The addition simply uses standard {@code double} arithmetic. * <p> * This instance is immutable and unaffected by this method. * * @param amountToSubtract the amount to subtract, in the same currency * @return an amount based on this with the specified amount subtracted * @throws IllegalArgumentException if the currencies are not equal */ public CurrencyAmount minus(CurrencyAmount amountToSubtract) { ArgChecker.notNull(amountToSubtract, "amountToSubtract"); ArgChecker.isTrue(amountToSubtract.getCurrency().equals(currency), "Unable to subtract amounts in different currencies"); return minus(amountToSubtract.getAmount()); }
private double forecastValueFwdSensitivity(ResolvedFra fra, double forwardRate, double eps) { RateComputationFn<RateComputation> obsFuncNew = mock(RateComputationFn.class); RatesProvider provNew = mock(RatesProvider.class); when(provNew.getValuationDate()).thenReturn(VAL_DATE); when(obsFuncNew.rate(fra.getFloatingRate(), fra.getStartDate(), fra.getEndDate(), provNew)) .thenReturn(forwardRate + eps); CurrencyAmount upValue = new DiscountingFraProductPricer(obsFuncNew).forecastValue(fra, provNew); when(obsFuncNew.rate(fra.getFloatingRate(), fra.getStartDate(), fra.getEndDate(), provNew)) .thenReturn(forwardRate - eps); CurrencyAmount downValue = new DiscountingFraProductPricer(obsFuncNew).forecastValue(fra, provNew); return upValue.minus(downValue).multipliedBy(0.5 / eps).getAmount(); }
private double dscSensitivity( ResolvedFra fra, double forwardRate, double discountFactor, double paymentTime, double eps) { RatesProvider provNew = mock(RatesProvider.class); when(provNew.getValuationDate()).thenReturn(VAL_DATE); RateComputationFn<RateComputation> obsFuncNew = mock(RateComputationFn.class); when(obsFuncNew.rate(fra.getFloatingRate(), fra.getStartDate(), fra.getEndDate(), provNew)) .thenReturn(forwardRate); when(provNew.discountFactor(fra.getCurrency(), fra.getPaymentDate())) .thenReturn(discountFactor * Math.exp(-eps * paymentTime)); CurrencyAmount upDscValue = new DiscountingFraProductPricer(obsFuncNew).presentValue(fra, provNew); when(provNew.discountFactor(fra.getCurrency(), fra.getPaymentDate())) .thenReturn(discountFactor * Math.exp(eps * paymentTime)); CurrencyAmount downDscValue = new DiscountingFraProductPricer(obsFuncNew).presentValue(fra, provNew); return upDscValue.minus(downDscValue).multipliedBy(0.5 / eps).getAmount(); }
private double presentValueFwdSensitivity(ResolvedFra fra, double forwardRate, double discountFactor, double eps) { RateComputationFn<RateComputation> obsFuncNew = mock(RateComputationFn.class); RatesProvider provNew = mock(RatesProvider.class); when(provNew.getValuationDate()).thenReturn(VAL_DATE); when(provNew.discountFactor(fra.getCurrency(), fra.getPaymentDate())) .thenReturn(discountFactor); when(obsFuncNew.rate(fra.getFloatingRate(), fra.getStartDate(), fra.getEndDate(), provNew)) .thenReturn(forwardRate + eps); CurrencyAmount upValue = new DiscountingFraProductPricer(obsFuncNew).presentValue(fra, provNew); when(obsFuncNew.rate(fra.getFloatingRate(), fra.getStartDate(), fra.getEndDate(), provNew)) .thenReturn(forwardRate - eps); CurrencyAmount downValue = new DiscountingFraProductPricer(obsFuncNew).presentValue(fra, provNew); return upValue.minus(downValue).multipliedBy(0.5 / eps).getAmount(); }