/** * 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); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 111972721: // value return ((AdjustablePayment) bean).getValue(); case 3076014: // date return ((AdjustablePayment) bean).getDate(); } return super.propertyGet(bean, propertyName, quiet); }
@Override public ResolvedFxVanillaOptionTrade resolve(ReferenceData refData) { return ResolvedFxVanillaOptionTrade.builder() .info(info) .product(product.resolve(refData)) .premium(premium.resolve(refData)) .build(); }
@Override public PortfolioItemSummary summarize() { // Long Pay USD 1mm @ GBP/USD 1.32 Premium USD 100k : 21Jan18 StringBuilder buf = new StringBuilder(96); CurrencyAmount base = product.getUnderlying().getBaseCurrencyAmount(); CurrencyAmount counter = product.getUnderlying().getCounterCurrencyAmount(); buf.append(product.getLongShort()); buf.append(' '); buf.append(SummarizerUtils.fx(base, counter)); buf.append(" Premium "); buf.append(SummarizerUtils.amount(premium.getValue().mapAmount(v -> Math.abs(v)))); buf.append(" : "); buf.append(SummarizerUtils.date(product.getExpiryDate())); CurrencyPair currencyPair = product.getCurrencyPair(); return SummarizerUtils.summary( this, ProductType.FX_VANILLA_OPTION, buf.toString(), currencyPair.getBase(), currencyPair.getCounter()); }
/** * Computes the price from the yield at a given settlement date. * * @param yield the yield * @param settlementDate the settlement date * @return the price */ public double priceFromYield(double yield, LocalDate settlementDate) { double accrualFactor = dayCount.relativeYearFraction(settlementDate, notional.getDate().getUnadjusted()); return yieldConvention.priceFromYield(yield, accrualFactor); }
@ImmutableValidator private void validate() { ArgChecker.isTrue(settlementDateOffset.getDays() >= 0, "The settlement date offset must be non-negative"); ArgChecker.isTrue(notional.getAmount() > 0, "Notional must be strictly positive"); }
public void test_resolve() { ResolvedBill resolved = US_BILL.resolve(REF_DATA); assertEquals(resolved.getDayCount(), DAY_COUNT); assertEquals(resolved.getLegalEntityId(), LEGAL_ENTITY); assertEquals(resolved.getNotional(), NOTIONAL.resolve(REF_DATA)); assertEquals(resolved.getSecurityId(), SECURITY_ID); assertEquals(resolved.getSettlementDateOffset(), SETTLE); assertEquals(resolved.getYieldConvention(), YIELD_CONVENTION); }
@Override public PortfolioItemSummary summarize() { // Long Barrier Pay USD 1mm Premium USD 100k @ GBP/USD 1.32 : 21Jan18 StringBuilder buf = new StringBuilder(96); CurrencyAmount base = product.getUnderlyingOption().getUnderlying().getBaseCurrencyAmount(); CurrencyAmount counter = product.getUnderlyingOption().getUnderlying().getCounterCurrencyAmount(); buf.append(product.getUnderlyingOption().getLongShort()); buf.append(" Barrier "); buf.append(SummarizerUtils.fx(base, counter)); buf.append(" Premium "); buf.append(SummarizerUtils.amount(premium.getValue().mapAmount(v -> Math.abs(v)))); buf.append(" : "); buf.append(SummarizerUtils.date(product.getUnderlyingOption().getExpiryDate())); CurrencyPair currencyPair = product.getCurrencyPair(); return SummarizerUtils.summary( this, ProductType.FX_SINGLE_BARRIER_OPTION, buf.toString(), currencyPair.getBase(), currencyPair.getCounter()); }
/** * Computes the yield from the price at a given settlement date. * * @param price the price * @param settlementDate the settlement date * @return the yield */ public double yieldFromPrice(double price, LocalDate settlementDate) { double accrualFactor = dayCount.relativeYearFraction(settlementDate, notional.getDate().getUnadjusted()); return yieldConvention.yieldFromPrice(price, accrualFactor); }
@ImmutableValidator private void validate() { ArgChecker.isTrue(settlementDateOffset.getDays() >= 0, "The settlement date offset must be non-negative"); ArgChecker.isTrue(notional.getAmount() > 0, "Notional must be strictly positive"); }
/** * Obtains an instance of a Swaption trade with a fixed payment. * * @param info the trade info * @param product the product * @param premium the premium * @return the trade */ public static SwaptionTrade of(TradeInfo info, Swaption product, Payment premium) { return new SwaptionTrade(info, product, AdjustablePayment.of(premium)); }
@Override public ResolvedIborCapFloorTrade resolve(ReferenceData refData) { return ResolvedIborCapFloorTrade.builder() .info(info) .product(product.resolve(refData)) .premium(premium != null ? premium.resolve(refData) : null) .build(); }
@Override public ResolvedBillTrade resolve(ReferenceData refData) { ResolvedBill resolvedProduct = product.resolve(refData); CurrencyAmount settleAmount = product.getNotional().getValue().multipliedBy(-price * quantity); LocalDate settlementDate = calculateSettlementDate(refData); Payment settlement = Payment.of(settleAmount, settlementDate); return ResolvedBillTrade.builder() .info(info) .product(resolvedProduct) .quantity(quantity) .settlement(settlement).build(); }
public void test_ofYield() { BillTrade test = sut_yield(); assertEquals(test.getProduct(), PRODUCT); assertEquals(test.getInfo(), TRADE_INFO); assertEquals(test.getQuantity(), QUANTITY); double price = 1.0d - YIELD * PRODUCT.getDayCount().relativeYearFraction(SETTLEMENT_DATE, PRODUCT.getNotional().getDate().getUnadjusted()); assertEquals(test.getPrice(), price, TOLERANCE_PRICE); assertEquals(test.withInfo(TRADE_INFO).getInfo(), TRADE_INFO); assertEquals(test.withQuantity(129).getQuantity(), 129d, 0d); assertEquals(test.withPrice(129).getPrice(), 129d, 0d); }
public void test_presentValue_zspread() { CurrencyAmount pvComputed = PRICER.presentValueWithZSpread(BILL, PROVIDER, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0); double pvExpected = DSC_FACTORS_ISSUER.discountFactor(MATURITY_DATE) * NOTIONAL.getAmount() * Math.exp(-Z_SPREAD * DSC_FACTORS_ISSUER.relativeYearFraction(MATURITY_DATE)); assertEquals(pvComputed.getCurrency(), EUR); assertEquals(pvComputed.getAmount(), pvExpected, TOLERANCE_PV); }
/** * Obtains an instance based on a {@code Payment}. * * @param payment the fixed payment * @return the adjustable payment instance */ public static AdjustablePayment of(Payment payment) { return of(payment.getValue(), payment.getDate()); }
@Override public ResolvedCmsTrade resolve(ReferenceData refData) { return ResolvedCmsTrade.builder() .info(info) .product(product.resolve(refData)) .premium(premium != null ? premium.resolve(refData) : null) .build(); }