public void test_of() { CashSwaptionSettlement test = CashSwaptionSettlement.of(date(2015, 6, 30), CashSwaptionSettlementMethod.CASH_PRICE); assertEquals(test.getMethod(), CashSwaptionSettlementMethod.CASH_PRICE); assertEquals(test.getSettlementDate(), date(2015, 6, 30)); assertEquals(test.getSettlementType(), SettlementType.CASH); }
/** * Obtains an instance from the settlement date and method. * * @param settlementDate the settlement date * @param method the settlement method * @return the settlement */ public static CashSwaptionSettlement of(LocalDate settlementDate, CashSwaptionSettlementMethod method) { return new CashSwaptionSettlement(settlementDate, method); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -295948169: // settlementDate return ((CashSwaptionSettlement) bean).getSettlementDate(); case -1077554975: // method return ((CashSwaptionSettlement) bean).getMethod(); } return super.propertyGet(bean, propertyName, quiet); }
/** * Calculates the numeraire, used to multiply the results. * * @param swaption the swap * @param fixedLeg the fixed leg * @param forward the forward rate * @param ratesProvider the rates provider * @return the numeraire */ protected double calculateNumeraire( ResolvedSwaption swaption, ResolvedSwapLeg fixedLeg, double forward, RatesProvider ratesProvider) { double annuityCash = swapPricer.getLegPricer().annuityCash(fixedLeg, forward); CashSwaptionSettlement cashSettlement = (CashSwaptionSettlement) swaption.getSwaptionSettlement(); double discountSettle = ratesProvider.discountFactor(fixedLeg.getCurrency(), cashSettlement.getSettlementDate()); return Math.abs(annuityCash * discountSettle); }
private SwaptionSettlement parseSettlement(XmlElement swaptionEl, FpmlDocument document) { Optional<String> optionalCashSettlement = swaptionEl.findAttribute("cashSettlement"); if (optionalCashSettlement.isPresent()) { XmlElement cashSettlementEl = swaptionEl.getChild("cashSettlement"); CashSwaptionSettlementMethod method = parseCashSettlementMethod(cashSettlementEl); LocalDate settlementDate = document.parseAdjustedRelativeDateOffset(cashSettlementEl).getUnadjusted(); return CashSwaptionSettlement.of(settlementDate, method); } else { // treat physical as the default to match FpML examples return PhysicalSwaptionSettlement.DEFAULT; } }
/** * Validates that the swaption is single currency cash par-yield. * * @param swaption the swaption */ protected void validateSwaption(ResolvedSwaption swaption) { ArgChecker.isFalse(swaption.getUnderlying().isCrossCurrency(), "Underlying swap must be single currency"); ArgChecker.isTrue(swaption.getSwaptionSettlement().getSettlementType().equals(SettlementType.CASH), "Swaption must be cash settlement"); CashSwaptionSettlement cashSettle = (CashSwaptionSettlement) swaption.getSwaptionSettlement(); ArgChecker.isTrue(cashSettle.getMethod().equals(CashSwaptionSettlementMethod.PAR_YIELD), "Cash settlement method must be par yield"); }
public void test_presentValueDelta_atMaturity() { double forward = PRICER_SWAP.parRate(RSWAP_REC, RATE_PROVIDER_AT_MATURITY); ResolvedSwapLeg fixedLeg = SWAPTION_REC_LONG.getUnderlying().getLegs(SwapLegType.FIXED).get(0); double annuityCash = PRICER_SWAP.getLegPricer().annuityCash(fixedLeg, forward); CashSwaptionSettlement cashSettlement = (CashSwaptionSettlement) SWAPTION_REC_LONG.getSwaptionSettlement(); double discountSettle = RATE_PROVIDER_AT_MATURITY.discountFactor(fixedLeg.getCurrency(), cashSettlement.getSettlementDate()); double pvbpCash = Math.abs(annuityCash * discountSettle); CurrencyAmount deltaRec = PRICER.presentValueDelta(SWAPTION_REC_LONG, RATE_PROVIDER_AT_MATURITY, VOLS_AT_MATURITY); assertEquals(deltaRec.getAmount(), RATE > forward ? -pvbpCash : 0, TOLERANCE_DELTA); CurrencyAmount deltaPay = PRICER.presentValueDelta(SWAPTION_PAY_SHORT, RATE_PROVIDER_AT_MATURITY, VOLS_AT_MATURITY); assertEquals(deltaPay.getAmount(), RATE > forward ? 0 : pvbpCash, TOLERANCE_DELTA); }
public void test_serialization() { CashSwaptionSettlement test = CashSwaptionSettlement.of(date(2015, 6, 30), CashSwaptionSettlementMethod.CASH_PRICE); assertSerialization(test); }
public void test_presentValueDelta_parity() { double forward = PRICER_SWAP.parRate(RSWAP_REC, RATE_PROVIDER); ResolvedSwapLeg fixedLeg = SWAPTION_REC_LONG.getUnderlying().getLegs(SwapLegType.FIXED).get(0); double annuityCash = PRICER_SWAP.getLegPricer().annuityCash(fixedLeg, forward); CashSwaptionSettlement cashSettlement = (CashSwaptionSettlement) SWAPTION_REC_LONG.getSwaptionSettlement(); double discountSettle = RATE_PROVIDER.discountFactor(fixedLeg.getCurrency(), cashSettlement.getSettlementDate()); double pvbpCash = Math.abs(annuityCash * discountSettle); CurrencyAmount deltaRec = PRICER.presentValueDelta(SWAPTION_REC_LONG, RATE_PROVIDER, VOLS); CurrencyAmount deltaPay = PRICER.presentValueDelta(SWAPTION_PAY_SHORT, RATE_PROVIDER, VOLS); assertEquals(deltaRec.getAmount() + deltaPay.getAmount(), -pvbpCash, TOLERANCE_DELTA); }
public void coverage() { CashSwaptionSettlement test = CashSwaptionSettlement.of(date(2015, 6, 30), CashSwaptionSettlementMethod.CASH_PRICE); coverImmutableBean(test); CashSwaptionSettlement test2 = CashSwaptionSettlement.of(date(2015, 7, 30), CashSwaptionSettlementMethod.PAR_YIELD); coverBeanEquals(test, test2); coverEnum(CashSwaptionSettlementMethod.class); coverEnum(SettlementType.class); }
@Override public CashSwaptionSettlement build() { return new CashSwaptionSettlement( settlementDate, method); }
double annuityCash = annuityDerivative.getValue(); double annuityCashDr = annuityDerivative.getDerivative(0); LocalDate settlementDate = ((CashSwaptionSettlement) swaption.getSwaptionSettlement()).getSettlementDate(); double discountSettle = ratesProvider.discountFactor(fixedLeg.getCurrency(), settlementDate); double strike = calculateStrike(fixedLeg);
double annuityCash = annuityDerivative.getValue(); double annuityCashDr = annuityDerivative.getDerivative(0); LocalDate settlementDate = ((CashSwaptionSettlement) swaption.getSwaptionSettlement()).getSettlementDate(); double discountSettle = ratesProvider.discountFactor(fixedLeg.getCurrency(), settlementDate); double strike = calculateStrike(fixedLeg);