@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 3493088: // rate return ((FixedRateComputation) bean).getRate(); } return super.propertyGet(bean, propertyName, quiet); }
/** * Creates the {@code RateComputation} for the stub. * * @param defaultRate the default fixed rate * @return the rate computation */ RateComputation createRateComputation(double defaultRate) { if (isFixedRate()) { return FixedRateComputation.of(fixedRate); } else if (isKnownAmount()) { return KnownAmountRateComputation.of(knownAmount); } else { return FixedRateComputation.of(defaultRate); } }
@Override public FixedRateComputation build() { return new FixedRateComputation( rate); }
public void test_collectIndices() { FixedRateComputation test = FixedRateComputation.of(0.05); ImmutableSet.Builder<Index> builder = ImmutableSet.builder(); test.collectIndices(builder); assertEquals(builder.build(), ImmutableSet.of()); }
public void test_rate_FixedRateComputation() { FixedRateComputation ro = FixedRateComputation.of(0.0123d); DispatchingRateComputationFn test = DispatchingRateComputationFn.DEFAULT; assertEquals(test.rate(ro, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV), 0.0123d, 0d); }
/** * Calculates the strike. * * @param fixedLeg the fixed leg * @return the strike */ protected double calculateStrike(ResolvedSwapLeg fixedLeg) { SwapPaymentPeriod paymentPeriod = fixedLeg.getPaymentPeriods().get(0); ArgChecker.isTrue(paymentPeriod instanceof RatePaymentPeriod, "Payment period must be RatePaymentPeriod"); RatePaymentPeriod ratePaymentPeriod = (RatePaymentPeriod) paymentPeriod; // compounding is caught when par rate is computed RateComputation rateComputation = ratePaymentPeriod.getAccrualPeriods().get(0).getRateComputation(); ArgChecker.isTrue(rateComputation instanceof FixedRateComputation, "Swap leg must be fixed leg"); return ((FixedRateComputation) rateComputation).getRate(); }
/** * Creates an instance. * * @param rate the fixed rate * @return the fixed rate computation */ public static FixedRateComputation of(double rate) { return new FixedRateComputation(rate); }
public void test_serialization() { FixedRateComputation test = FixedRateComputation.of(0.05); assertSerialization(test); }
return Triple.of(false, 0, 0.0d); // Should be fixed period if ((i > 0) && (((FixedRateComputation) accrualPeriods.get(i).getRateComputation()).getRate() != fixedRate)) { return Triple.of(false, 0, 0.0d); // All fixed rates should be the same fixedRate = ((FixedRateComputation) accrualPeriods.get(i).getRateComputation()).getRate(); if (accrualPeriods.get(i).getSpread() != 0) { return Triple.of(false, 0, 0.0d); // Should have no spread
public void coverage() { FixedRateComputation test = FixedRateComputation.of(0.05); coverImmutableBean(test); }
/** * Computes cash flow equivalent and sensitivity of fixed leg. * <p> * The return type is a map of {@code NotionalExchange} and {@code PointSensitivityBuilder}. * * @param fixedLeg the fixed leg * @param ratesProvider the rates provider * @return the cash flow equivalent and sensitivity */ public static ImmutableMap<Payment, PointSensitivityBuilder> cashFlowEquivalentAndSensitivityFixedLeg( ResolvedSwapLeg fixedLeg, RatesProvider ratesProvider) { ArgChecker.isTrue(fixedLeg.getType().equals(SwapLegType.FIXED), "Leg type should be FIXED"); ArgChecker.isTrue(fixedLeg.getPaymentEvents().isEmpty(), "PaymentEvent should be empty"); Map<Payment, PointSensitivityBuilder> res = new HashMap<Payment, PointSensitivityBuilder>(); for (SwapPaymentPeriod paymentPeriod : fixedLeg.getPaymentPeriods()) { ArgChecker.isTrue(paymentPeriod instanceof RatePaymentPeriod, "rate payment should be RatePaymentPeriod"); RatePaymentPeriod ratePaymentPeriod = (RatePaymentPeriod) paymentPeriod; ArgChecker.isTrue(ratePaymentPeriod.getAccrualPeriods().size() == 1, "rate payment should not be compounding"); RateAccrualPeriod rateAccrualPeriod = ratePaymentPeriod.getAccrualPeriods().get(0); double factor = rateAccrualPeriod.getYearFraction() * ((FixedRateComputation) rateAccrualPeriod.getRateComputation()).getRate(); CurrencyAmount notional = ratePaymentPeriod.getNotionalAmount().multipliedBy(factor); LocalDate paymentDate = ratePaymentPeriod.getPaymentDate(); Payment pay = Payment.of(notional, paymentDate); res.put(pay, PointSensitivityBuilder.none()); } return ImmutableMap.copyOf(res); }
public void test_createRateComputation_NONE() { FixedRateStubCalculation test = FixedRateStubCalculation.NONE; assertEquals(test.createRateComputation(3d), FixedRateComputation.of(3d)); }
private void assertFixedPaymentPeriod( ResolvedSwapLeg expandedPayLeg, int index, String paymentDateStr, String startDateStr, String endDateStr, double notional, double rate) { RatePaymentPeriod pp = (RatePaymentPeriod) expandedPayLeg.getPaymentPeriods().get(index); assertEquals(pp.getPaymentDate().toString(), paymentDateStr); assertEquals(Math.abs(pp.getNotional()), notional); assertEquals(pp.getAccrualPeriods().size(), 1); RateAccrualPeriod ap = pp.getAccrualPeriods().get(0); assertEquals(ap.getStartDate().toString(), startDateStr); assertEquals(ap.getEndDate().toString(), endDateStr); if (ap.getRateComputation() instanceof FixedRateComputation) { assertEquals(((FixedRateComputation) ap.getRateComputation()).getRate(), rate); } else { fail(); } }
public void test_createRateComputation_fixedRate() { FixedRateStubCalculation test = FixedRateStubCalculation.ofFixedRate(0.025d); assertEquals(test.createRateComputation(3d), FixedRateComputation.of(0.025d)); }
return ((FixedRateComputation) computation).getRate(); } else if (computation instanceof FixedOvernightCompoundedAnnualRateComputation) {
public void test_createRateComputation_fixedRate() { IborRateStubCalculation test = IborRateStubCalculation.ofFixedRate(0.025d); assertEquals(test.createRateComputation(DATE, GBP_LIBOR_3M, REF_DATA), FixedRateComputation.of(0.025d)); }
RateAccrualPeriod rateAccrualPeriod = ratePaymentPeriod.getAccrualPeriods().get(0); double factor = rateAccrualPeriod.getYearFraction() * ((FixedRateComputation) rateAccrualPeriod.getRateComputation()).getRate(); CurrencyAmount notional = ratePaymentPeriod.getNotionalAmount().multipliedBy(factor); LocalDate paymentDate = ratePaymentPeriod.getPaymentDate();
double rate = ((FixedRateComputation) computation).getRate(); builder.put(ExplainKey.FIXED_RATE, rate); builder.put(ExplainKey.COMBINED_RATE, rate);