/** * Returns a copy of this {@code CurrencyAmount} with a positive amount. * <p> * The result of this method will always be positive, where the amount is equal to {@code Math.abs(amount)}. * <p> * This instance is immutable and unaffected by this method. * * @return a currency amount based on this where the amount is positive */ public CurrencyAmount positive() { return amount < 0 ? negated() : this; }
/** * Returns a copy of this {@code CurrencyAmount} with a negative amount. * <p> * The result of this method will always be negative, equal to {@code -Math.abs(amount)}. * <p> * This instance is immutable and unaffected by this method. * * @return a currency amount based on this where the amount is negative */ public CurrencyAmount negative() { return amount > 0 ? negated() : this; }
/** * Returns a copy of this {@code Payment} with the value negated. * <p> * This takes this payment and negates it. * <p> * This instance is immutable and unaffected by this method. * * @return a payment based on this with the value negated */ public Payment negated() { return Payment.of(value.negated(), date); }
/** * Returns a copy of this payment with the value negated. * <p> * This takes this payment and negates it. * <p> * This instance is immutable and unaffected by this method. * * @return a payment based on this with the value negated */ public AdjustablePayment negated() { return AdjustablePayment.of(value.negated(), date); }
/** * Returns a copy of this {@code MultiCurrencyAmount} with the specified amount subtracted. * <p> * This subtracts the specified amount from this monetary amount, returning a new object. * If the currency is already present, the amount is subtracted from the existing amount. * If the currency is not yet present, the negated amount is included. * The subtraction uses standard {@code double} arithmetic. * <p> * This instance is immutable and unaffected by this method. * * @param amountToSubtract the amount to subtract * @return an amount based on this with the specified amount subtracted */ public MultiCurrencyAmount minus(CurrencyAmount amountToSubtract) { ArgChecker.notNull(amountToSubtract, "amountToSubtract"); return plus(amountToSubtract.negated()); }
@Override public ResolvedBulletPayment resolve(ReferenceData refData) { CurrencyAmount signed = payReceive == PayReceive.PAY ? value.negated() : value; Payment payment = Payment.of(signed, date.adjusted(refData)); return ResolvedBulletPayment.of(payment); }
public void test_negated() { assertEquals(CCY_AMOUNT.negated(), CCY_AMOUNT_NEGATIVE); assertEquals(CCY_AMOUNT_NEGATIVE.negated(), CCY_AMOUNT); assertEquals(CurrencyAmount.zero(Currency.USD), CurrencyAmount.zero(Currency.USD).negated()); assertEquals(CurrencyAmount.of(Currency.USD, -0d).negated(), CurrencyAmount.zero(Currency.USD)); }
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(); }
private AdjustablePayment parsePremium(XmlElement swaptionEl, FpmlDocument document, TradeInfoBuilder tradeInfoBuilder) { XmlElement premiumEl = swaptionEl.getChild("premium"); PayReceive payReceive = document.parsePayerReceiver(premiumEl, tradeInfoBuilder); XmlElement paymentAmountEl = premiumEl.getChild("paymentAmount"); CurrencyAmount ccyAmount = document.parseCurrencyAmount(paymentAmountEl); ccyAmount = payReceive.isPay() ? ccyAmount.negated() : ccyAmount; AdjustableDate paymentDate = premiumEl.findChild("paymentDate") .map(el -> document.parseAdjustableDate(el)).get(); return AdjustablePayment.of(ccyAmount, paymentDate); }
public void test_of_wrongCounterCurrency() { FxSingle nearLeg = FxSingle.of(USD_P1550, EUR_P1590.negated(), DATE_2011_11_21); FxSingle farLeg = FxSingle.of(GBP_M1000, EUR_P1590, DATE_2011_12_21); assertThrowsIllegalArg(() -> FxSwap.of(nearLeg, farLeg)); }
public void test_of_wrongCounterCurrency() { ResolvedFxSingle nearLeg = ResolvedFxSingle.of(USD_P1550, EUR_P1590.negated(), DATE_2011_11_21); ResolvedFxSingle farLeg = ResolvedFxSingle.of(GBP_M1000, EUR_P1590, DATE_2011_12_21); assertThrowsIllegalArg(() -> ResolvedFxSwap.of(nearLeg, farLeg)); }
private static FxSingle create( CurrencyAmount amount, FxRate fxRate, LocalDate paymentDate, BusinessDayAdjustment paymentDateAdjustment) { ArgChecker.notNull(amount, "amount"); ArgChecker.notNull(fxRate, "fxRate"); ArgChecker.notNull(paymentDate, "paymentDate"); CurrencyPair pair = fxRate.getPair(); if (!pair.contains(amount.getCurrency())) { throw new IllegalArgumentException(Messages.format( "FxRate '{}' and CurrencyAmount '{}' must have a currency in common", fxRate, amount)); } Currency currency2 = pair.getBase().equals(amount.getCurrency()) ? pair.getCounter() : pair.getBase(); CurrencyAmount amountCurrency2 = amount.convertedTo(currency2, fxRate).negated(); return create(amount, amountCurrency2, paymentDate, paymentDateAdjustment); }
FxSingle farLeg = FxSingle.of(amount.negated(), farRate, farDate); return of(nearLeg, farLeg);
public void test_negated() { MultiCurrencyAmount base = MultiCurrencyAmount.of(CA1, CA2); MultiCurrencyAmount test = base.negated(); assertMCA(test, CA1.negated(), CA2.negated()); assertEquals( MultiCurrencyAmount.of(CurrencyAmount.zero(Currency.USD), CurrencyAmount.zero(Currency.EUR)).negated(), MultiCurrencyAmount.of(CurrencyAmount.zero(Currency.USD), CurrencyAmount.zero(Currency.EUR))); assertEquals( MultiCurrencyAmount.of(CurrencyAmount.of(Currency.USD, -0d), CurrencyAmount.of(Currency.EUR, -0d)).negated(), MultiCurrencyAmount.of(CurrencyAmount.zero(Currency.USD), CurrencyAmount.zero(Currency.EUR))); }
public void test_minus_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.minus(cc); assertMCA(test, ca, cb, cc.negated()); }
double farFxRate = nearFxRate + forwardPoints; ResolvedFxSingle nearLeg = ResolvedFxSingle.of(amountCurrency1, FxRate.of(currency1, currency2, nearFxRate), nearDate); ResolvedFxSingle farLeg = ResolvedFxSingle.of(amountCurrency1.negated(), FxRate.of(currency1, currency2, farFxRate), farDate); return of(nearLeg, farLeg);
/** * Creates an {@code ResolvedFxSingle} using a rate. * <p> * This create an FX specifying a value date, notional in one currency, the second currency * and the FX rate between the two. * The currencies of the payments must differ. * <p> * This factory identifies the currency pair of the exchange and assigns the payments * to match the base or counter currency of the standardized currency pair. * For example, a EUR/USD exchange always has EUR as the base payment and USD as the counter payment. * <p> * No payment date adjustments apply. * * @param amountCurrency1 the amount of the near leg in the first currency * @param fxRate the near FX rate * @param paymentDate date that the FX settles * @return the resolved foreign exchange transaction */ public static ResolvedFxSingle of(CurrencyAmount amountCurrency1, FxRate fxRate, LocalDate paymentDate) { CurrencyPair pair = fxRate.getPair(); ArgChecker.isTrue(pair.contains(amountCurrency1.getCurrency())); Currency currency2 = pair.getBase().equals(amountCurrency1.getCurrency()) ? pair.getCounter() : pair.getBase(); CurrencyAmount amountCurrency2 = amountCurrency1.convertedTo(currency2, fxRate).negated(); return ResolvedFxSingle.of(Payment.of(amountCurrency1, paymentDate), Payment.of(amountCurrency2, paymentDate)); }
public void test_minus_MultiCurrencyAmount_mergeAndAdd() { CurrencyAmount ca = CurrencyAmount.of(Currency.AUD, 117); CurrencyAmount cb = CurrencyAmount.of(Currency.USD, 12); CurrencyAmount cc = CurrencyAmount.of(Currency.AUD, 3); CurrencyAmount cd = CurrencyAmount.of(Currency.NZD, 3); MultiCurrencyAmount mc1 = MultiCurrencyAmount.of(ca, cb); MultiCurrencyAmount mc2 = MultiCurrencyAmount.of(cc, cd); MultiCurrencyAmount test = mc1.minus(mc2); assertMCA(test, cb, cd.negated(), CurrencyAmount.of(Currency.AUD, 114)); }