@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 97440432: // first return ((Triple<?, ?, ?>) bean).getFirst(); case -906279820: // second return ((Triple<?, ?, ?>) bean).getSecond(); case 110331239: // third return ((Triple<?, ?, ?>) bean).getThird(); } return super.propertyGet(bean, propertyName, quiet); }
@Override public Triple<A, B, C> build() { return new Triple<>( first, second, third); }
@Test(expectedExceptions = ClassCastException.class) public void test_compareTo_notComparable() { Runnable notComparable = () -> {}; Triple<Integer, Runnable, String> test1 = Triple.of(1, notComparable, "A"); Triple<Integer, Runnable, String> test2 = Triple.of(2, notComparable, "B"); test1.compareTo(test2); }
Triple<CreditDiscountFactors, LegalEntitySurvivalProbabilities, Double> rates = reduceDiscountFactors(cds, ratesProvider); double protectionFull = underlyingPricer.protectionFull( cds, rates.getFirst(), rates.getSecond(), referenceDate, effectiveStartDate); double rpv01 = underlyingPricer.riskyAnnuity( cds, rates.getFirst(), rates.getSecond(), referenceDate, stepinDate, effectiveStartDate, PriceType.CLEAN); double lgd = 1d - recoveryRate; double numTotal = cdsIndex.getLegalEntityIds().size();
/** * Calculates the expected loss of the CDS index product. * <p> * The expected loss is the (undiscounted) expected default settlement value paid by the protection seller. * The resulting value is always positive. * * @param cdsIndex the product * @param ratesProvider the rates provider * @return the expected loss */ public CurrencyAmount expectedLoss( ResolvedCdsIndex cdsIndex, CreditRatesProvider ratesProvider) { if (isExpired(cdsIndex, ratesProvider)) { return CurrencyAmount.of(cdsIndex.getCurrency(), 0d); } ResolvedCds cds = cdsIndex.toSingleNameCds(); double recoveryRate = underlyingPricer.recoveryRate(cds, ratesProvider); Triple<CreditDiscountFactors, LegalEntitySurvivalProbabilities, Double> rates = reduceDiscountFactors(cds, ratesProvider); double survivalProbability = rates.getSecond().survivalProbability(cds.getProtectionEndDate()); double el = (1d - recoveryRate) * (1d - survivalProbability) * rates.getThird(); return CurrencyAmount.of(cds.getCurrency(), Math.abs(cds.getNotional()) * el); }
@Test(dataProvider = "factoryNull", expectedExceptions = IllegalArgumentException.class) public void test_of_null(Object first, Object second, Object third) { Triple.of(first, second, third); }
ArgChecker.isTrue(fixedCompounded.getFirst(), "Swap should have a fixed leg and for one payment it should be based on compunding witout spread."); double notional = payment.getNotional(); double df = provider.discountFactor(ccyFixedLeg, payment.getPaymentDate()); return Math.pow(-(otherLegsConvertedPv + fixedLegEventsPv) / (notional * df) + 1.0d, 1.0 / fixedCompounded.getSecond()) - 1.0d;
private Triple<Boolean, Integer, Double> checkFixedCompounded(ResolvedSwapLeg leg) { if (leg.getPaymentEvents().size() != 0) { return Triple.of(false, 0, 0.0d); // No event return Triple.of(false, 0, 0.0d); // Should be compounded for (int i = 0; i < nbAccrualPeriods; i++) { if (!(accrualPeriods.get(i).getRateComputation() instanceof FixedRateComputation)) { return Triple.of(false, 0, 0.0d); // Should be fixed period return Triple.of(false, 0, 0.0d); // All fixed rates should be the same return Triple.of(false, 0, 0.0d); // Should have no spread return Triple.of(false, 0, 0.0d); // Should have a gearing of 1. return Triple.of(false, 0, 0.0d); // Should have a year fraction of 1. return Triple.of(true, nbAccrualPeriods, fixedRate);
public void test_compareTo() { Triple<String, String, String> abc = Triple.of("A", "B", "C"); Triple<String, String, String> adc = Triple.of("A", "D", "C"); Triple<String, String, String> bac = Triple.of("B", "A", "C"); Triple<String, String, String> bad = Triple.of("B", "A", "D"); assertTrue(abc.compareTo(abc) == 0); assertTrue(abc.compareTo(adc) < 0); assertTrue(abc.compareTo(bac) < 0); assertTrue(adc.compareTo(abc) > 0); assertTrue(adc.compareTo(adc) == 0); assertTrue(adc.compareTo(bac) < 0); assertTrue(bac.compareTo(abc) > 0); assertTrue(bac.compareTo(adc) > 0); assertTrue(bac.compareTo(bac) == 0); assertTrue(bad.compareTo(abc) > 0); assertTrue(bad.compareTo(adc) > 0); assertTrue(bad.compareTo(bac) > 0); assertTrue(bad.compareTo(bad) == 0); }
public void test_equals() { Triple<Integer, String, String> a = Triple.of(1, "Hello", "Triple"); Triple<Integer, String, String> a2 = Triple.of(1, "Hello", "Triple"); Triple<Integer, String, String> b = Triple.of(1, "Goodbye", "Triple"); Triple<Integer, String, String> c = Triple.of(2, "Hello", "Triple"); Triple<Integer, String, String> d = Triple.of(2, "Goodbye", "Triple"); Triple<Integer, String, String> e = Triple.of(2, "Goodbye", "Other"); assertEquals(a.equals(a), true); assertEquals(a.equals(b), false); assertEquals(a.equals(c), false); assertEquals(a.equals(d), false); assertEquals(a.equals(e), false); assertEquals(a.equals(a2), true); assertEquals(b.equals(a), false); assertEquals(b.equals(b), true); assertEquals(b.equals(c), false); assertEquals(b.equals(d), false); assertEquals(b.equals(e), false); assertEquals(c.equals(a), false); assertEquals(c.equals(b), false); assertEquals(c.equals(c), true); assertEquals(c.equals(d), false); assertEquals(c.equals(e), false); assertEquals(d.equals(a), false); assertEquals(d.equals(b), false); assertEquals(d.equals(c), false);
cds, rates.getFirst(), rates.getSecond(), referenceDate, effectiveStartDate, recoveryRate); protectionLegSensi = protectionLegSensi.multipliedBy(signedNotional * rates.getThird()); PointSensitivityBuilder riskyAnnuitySensi = underlyingPricer.riskyAnnuitySensitivity( cds, rates.getFirst(), rates.getSecond(), referenceDate, stepinDate, effectiveStartDate); riskyAnnuitySensi = riskyAnnuitySensi.multipliedBy(-cds.getFixedRate() * signedNotional * rates.getThird());
if (fixedCompounded.getFirst()) { double df = provider.discountFactor(ccyReferenceLeg, referenceLeg.getPaymentPeriods().get(0).getPaymentDate()); PointSensitivityBuilder dfDr = provider.discountFactors(ccyReferenceLeg) convertedPvDr.combinedWith(referenceConvertedPvDr.multipliedBy(-1)).multipliedBy(-1.0d / (df * notional)) .combinedWith(dfDr.multipliedBy((convertedPv - referenceConvertedPv) / (df * df * notional))) .multipliedBy(1.0d / fixedCompounded.getSecond() * Math.pow(-(convertedPv - referenceConvertedPv) / (df * notional) + 1.0d, 1.0d / fixedCompounded.getSecond() - 1.0d)); return dParSpreadDr;
public void coverage() { Triple<String, String, String> test = Triple.of("A", "B", "C"); TestHelper.coverImmutableBean(test); }
/** * Obtains a triple inferring the types. * * @param <A> the first element type * @param <B> the second element type * @param <C> the third element type * @param first the first element * @param second the second element * @param third the third element * @return a triple formed from the three parameters */ public static <A, B, C> Triple<A, B, C> of(A first, B second, C third) { return new Triple<A, B, C>(first, second, third); }