/** * Obtains an instance from the amount and date. * * @param paymentAmount the amount of the notional exchange * @param paymentDate the date that the payment is made * @return the notional exchange */ public static NotionalExchange of(CurrencyAmount paymentAmount, LocalDate paymentDate) { return new NotionalExchange(Payment.of(paymentAmount, paymentDate)); }
/** * Calculates the current of the FX barrier option trade. * * @param trade the option trade * @param valuationDate the valuation date * @return the current cash amount */ public CurrencyAmount currentCash(ResolvedFxSingleBarrierOptionTrade trade, LocalDate valuationDate) { Payment premium = trade.getPremium(); if (premium.getDate().equals(valuationDate)) { return CurrencyAmount.of(premium.getCurrency(), premium.getAmount()); } return CurrencyAmount.of(premium.getCurrency(), 0d); }
/** * Computes the forecast value of the payment. * <p> * The present value is zero if the payment date is before the valuation date. * * @param payment the payment * @param provider the provider * @return the forecast value */ public CurrencyAmount forecastValue(Payment payment, BaseProvider provider) { if (provider.getValuationDate().isAfter(payment.getDate())) { return CurrencyAmount.zero(payment.getCurrency()); } return payment.getValue(); }
PaypalResponse paypalResponse = new PaypalResponse(message); if (paypalResponse.isSuccess()) { Payment payment = new Payment(); payment.userId = user.id; payment.totalAmount = totalAmount; payment.token = paypalResponse.getToken(); payment.correlationID = paypalResponse.getCorrelationID(); payment.save();
/** * Gets the currency amount in which the amount is paid. * <p> * This returns the currency amount whose amount is negative or zero. * * @return the pay currency amount */ public CurrencyAmount getPayCurrencyAmount() { if (baseCurrencyPayment.getAmount() <= 0d) { return baseCurrencyPayment.getValue(); } return counterCurrencyPayment.getValue(); }
public void test_of_Payment() { NotionalExchange test = NotionalExchange.of(Payment.of(GBP_1000, DATE_2014_06_30)); assertEquals(test.getPayment(), Payment.of(GBP_1000, DATE_2014_06_30)); assertEquals(test.getPaymentDate(), DATE_2014_06_30); assertEquals(test.getPaymentAmount(), GBP_1000); assertEquals(test.getCurrency(), GBP); }
public void test_currentCash_onPayment() { MultiCurrencyAmount computed = PRICER.currentCash(FWD, PAYMENT_DATE); assertEquals(computed, MultiCurrencyAmount.of( FWD.getBaseCurrencyPayment().getValue(), FWD.getCounterCurrencyPayment().getValue())); } }
public void price_from_yield_discount() { ResolvedBill bill = sut(); double yield = 0.01; LocalDate settlementDate = LocalDate.of(2018, 8, 17); double af = bill.getDayCount().relativeYearFraction(settlementDate, bill.getNotional().getDate()); double priceExpected = 1.0d - yield * af; double priceComputed = bill.priceFromYield(yield, settlementDate); assertEquals(priceExpected, priceComputed, TOLERANCE_PRICE); }
public void test_upfrontPayment() { Payment payment = TRADE_PRICER.upfrontPayment(TRADE); assertEquals(payment.getCurrency(), EUR); assertEquals(payment.getAmount(), -NOTIONAL * QUANTITY * DIRTY_PRICE, TOL); assertEquals(payment.getDate(), SETTLEMENT); }
public void test_of() { ResolvedBulletPayment test = ResolvedBulletPayment.of(PAYMENT1); assertEquals(test.getPayment(), PAYMENT1); assertEquals(test.getCurrency(), PAYMENT1.getCurrency()); }
public void test_adjustDate() { Payment test = Payment.ofReceive(GBP_P1000, DATE_2015_06_29); Payment expected = Payment.of(GBP_P1000, DATE_2015_06_29.plusDays(1)); assertEquals(test.adjustDate(TemporalAdjusters.ofDateAdjuster(d -> d.plusDays(1))), expected); }
public void test_negated() { Payment test = Payment.ofReceive(GBP_P1000, DATE_2015_06_30); assertEquals(test.negated(), Payment.of(GBP_M1000, DATE_2015_06_30)); }
public void test_explainPresentValue_provider_ended() { ExplainMap explain = PRICER.explainPresentValue(PAYMENT_PAST, PROVIDER); Currency currency = PAYMENT_PAST.getCurrency(); assertEquals(explain.get(ExplainKey.ENTRY_TYPE).get(), "Payment"); assertEquals(explain.get(ExplainKey.PAYMENT_DATE).get(), PAYMENT_PAST.getDate()); assertEquals(explain.get(ExplainKey.PAYMENT_CURRENCY).get(), currency); assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().getCurrency(), currency); assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().getAmount(), 0, TOL); assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().getCurrency(), currency); assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().getAmount(), 0, TOL); }
/** * Computes the forecast value of the payment. * <p> * The present value is zero if the payment date is before the valuation date. * * @param payment the payment * @param provider the provider * @return the forecast value */ public double forecastValueAmount(Payment payment, BaseProvider provider) { if (provider.getValuationDate().isAfter(payment.getDate())) { return 0d; } return payment.getAmount(); }
/** * Calculates the current cash. * * @param payment the payment * @param provider the provider * @return the current cash */ public CurrencyAmount currentCash(Payment payment, BaseProvider provider) { if (payment.getDate().isEqual(provider.getValuationDate())) { return payment.getValue(); } return CurrencyAmount.zero(payment.getCurrency()); }
public void test_builder_quantitySettlement() { assertThrows(() -> ResolvedBillTrade.builder() .info(TradeInfo.of(date(2015, 3, 25))) .product(ResolvedBillTest.sut()) .quantity(123) .settlement(Payment.of(Currency.USD, 120, date(2015, 3, 27))) .build()); }
/** * Calculates the current cash. * * @param fx the product * @param valuationDate the valuation date * @return the current cash */ public MultiCurrencyAmount currentCash(ResolvedFxSingle fx, LocalDate valuationDate) { if (valuationDate.isEqual(fx.getPaymentDate())) { return MultiCurrencyAmount.of(fx.getBaseCurrencyPayment().getValue(), fx.getCounterCurrencyPayment().getValue()); } return MultiCurrencyAmount.empty(); }
@ImmutableValidator private void validate() { if (baseCurrencyPayment.getCurrency().equals(counterCurrencyPayment.getCurrency())) { throw new IllegalArgumentException("Payments must have different currencies"); } if ((baseCurrencyPayment.getAmount() != 0d || counterCurrencyPayment.getAmount() != 0d) && Math.signum(baseCurrencyPayment.getAmount()) != -Math.signum(counterCurrencyPayment.getAmount())) { throw new IllegalArgumentException("Payments must have different signs"); } ArgChecker.inOrderOrEqual(baseCurrencyPayment.getDate(), counterCurrencyPayment.getDate(), "baseCurrencyPayment.date", "counterCurrencyPayment.date"); }