@Test(dataProvider = "name") public void test_toString(CapitalIndexedBondYieldConvention convention, String name) { assertEquals(convention.toString(), name); }
/** * Computes the clean price from the conventional real yield. * <p> * The resulting clean price is real price or nominal price depending on the yield convention. * <p> * The input yield and output are expressed in fraction. * <p> * Strata uses <i>decimal prices</i> for bonds. For example, a price of 99.32% is represented in Strata by 0.9932. * * @param bond the product * @param ratesProvider the rates provider, used to determine price index values * @param settlementDate the settlement date * @param yield the yield * @return the clean price of the product */ public double cleanPriceFromRealYield( ResolvedCapitalIndexedBond bond, RatesProvider ratesProvider, LocalDate settlementDate, double yield) { double dirtyPrice = dirtyPriceFromRealYield(bond, ratesProvider, settlementDate, yield); if (bond.getYieldConvention().equals(CapitalIndexedBondYieldConvention.GB_IL_FLOAT)) { return cleanNominalPriceFromDirtyNominalPrice(bond, ratesProvider, settlementDate, dirtyPrice); } return cleanRealPriceFromDirtyRealPrice(bond, settlementDate, dirtyPrice); }
double couponPerYear = bond.getFrequency().eventsPerYear(); CapitalIndexedBondYieldConvention yieldConvention = bond.getYieldConvention(); if (yieldConvention.equals(CapitalIndexedBondYieldConvention.US_IL_REAL)) { double pvAtFirstCoupon; double cpnRate = bond.getPeriodicPayments().get(0).getRealCoupon(); double v = 1d / (1d + yield / couponPerYear); double rs = ratioPeriodToNextCoupon(period, settlementDate); if (yieldConvention.equals(CapitalIndexedBondYieldConvention.GB_IL_FLOAT)) { RateComputation obs = period.getRateComputation(); LocalDateDoubleTimeSeries ts = ratesProvider.priceIndexValues(bond.getRateCalculation().getIndex()).getFixings(); if (yieldConvention.equals(CapitalIndexedBondYieldConvention.GB_IL_BOND)) { double indexRatio = indexRatio(bond, ratesProvider, settlementDate); double firstCashFlow = realRate * indexRatio * firstYearFraction * couponPerYear; if (yieldConvention.equals(CapitalIndexedBondYieldConvention.JP_IL_SIMPLE)) { LocalDate maturityDate = bond.getEndDate(); double maturity = bond.yearFraction(settlementDate, maturityDate); return dirtyRealPriceFromCleanRealPrice(bond, settlementDate, cleanPrice); if (yieldConvention.equals(CapitalIndexedBondYieldConvention.JP_IL_COMPOUND)) { double pvAtFirstCoupon = 0d; for (int loopcpn = 0; loopcpn < nbCoupon; loopcpn++) { "The convention " + bond.getYieldConvention().toString() + " is not supported.");
@Test(dataProvider = "name") public void test_of_lookup(CapitalIndexedBondYieldConvention convention, String name) { assertEquals(CapitalIndexedBondYieldConvention.of(name), convention); }
@Override public Double apply(Double z) { double dirtyPrice = dirtyNominalPriceFromCurvesWithZSpread( bond, ratesProvider, discountingProvider, settlementDate, z, compoundedRateType, periodsPerYear); if (bond.getYieldConvention().equals(CapitalIndexedBondYieldConvention.GB_IL_FLOAT)) { return cleanNominalPriceFromDirtyNominalPrice(bond, ratesProvider, settlementDate, dirtyPrice) - cleanPrice; } double dirtyRealPrice = realPriceFromNominalPrice(bond, ratesProvider, settlementDate, dirtyPrice); return cleanRealPriceFromDirtyRealPrice(bond, settlementDate, dirtyRealPrice) - cleanPrice; } };
@Test(dataProvider = "name") public void test_of_lookupLowerCase(CapitalIndexedBondYieldConvention convention, String name) { assertEquals(CapitalIndexedBondYieldConvention.of(name.toLowerCase(Locale.ENGLISH)), convention); }
CurrencyAmount forecastValueStandardFromCleanPrice( ResolvedCapitalIndexedBond product, RatesProvider ratesProvider, LocalDate standardSettlementDate, double realCleanPrice) { double notional = product.getNotional(); double netAmountReal = realCleanPrice * notional + product.accruedInterest(standardSettlementDate); double indexRatio = product.getYieldConvention().equals(CapitalIndexedBondYieldConvention.GB_IL_FLOAT) ? 1d : productPricer.indexRatio(product, ratesProvider, standardSettlementDate); return CurrencyAmount.of(product.getCurrency(), indexRatio * netAmountReal); }
@Test(dataProvider = "name") public void test_of_lookupUpperCase(CapitalIndexedBondYieldConvention convention, String name) { assertEquals(CapitalIndexedBondYieldConvention.of(name.toUpperCase(Locale.ENGLISH)), convention); }
PointSensitivityBuilder forecastValueSensitivityStandardFromCleanPrice( ResolvedCapitalIndexedBond product, RatesProvider ratesProvider, LocalDate standardSettlementDate, double realCleanPrice) { if (product.getYieldConvention().equals(CapitalIndexedBondYieldConvention.GB_IL_FLOAT)) { return PointSensitivityBuilder.none(); } double notional = product.getNotional(); double netAmountReal = realCleanPrice * notional + product.accruedInterest(standardSettlementDate); PointSensitivityBuilder indexRatioSensi = productPricer.indexRatioSensitivity(product, ratesProvider, standardSettlementDate); return indexRatioSensi.multipliedBy(netAmountReal); }
public void test_of_lookup_notFound() { assertThrows(() -> CapitalIndexedBondYieldConvention.of("Rubbish"), IllegalArgumentException.class); }
/** * Calculates the accrued interest of the bond with the specified date. * * @param referenceDate the reference date * @return the accrued interest of the product */ public double accruedInterest(LocalDate referenceDate) { if (getUnadjustedStartDate().isAfter(referenceDate)) { return 0d; } double notional = getNotional(); CapitalIndexedBondPaymentPeriod period = findPeriod(referenceDate) .orElseThrow(() -> new IllegalArgumentException("Date outside range of bond")); LocalDate previousAccrualDate = period.getUnadjustedStartDate(); double realCoupon = period.getRealCoupon(); double couponPerYear = getFrequency().eventsPerYear(); double rate = realCoupon * couponPerYear; double accruedInterest = yieldConvention.equals(CapitalIndexedBondYieldConvention.JP_IL_COMPOUND) || yieldConvention.equals(CapitalIndexedBondYieldConvention.JP_IL_SIMPLE) ? yearFraction(previousAccrualDate, referenceDate, DayCounts.ACT_365F) * rate * notional : yearFraction(previousAccrualDate, referenceDate) * rate * notional; double result = 0d; if (hasExCouponPeriod() && !referenceDate.isBefore(period.getDetachmentDate())) { result = accruedInterest - notional * rate * yearFraction(previousAccrualDate, period.getUnadjustedEndDate()); } else { result = accruedInterest; } return result; }
public void test_of_lookup_null() { assertThrows(() -> CapitalIndexedBondYieldConvention.of(null), IllegalArgumentException.class); }
/** * Computes the conventional real yield from the curves. * <p> * The yield is in the bill yield convention. * * @param bond the product * @param ratesProvider the rates provider, used to determine price index values * @param discountingProvider the discount factors provider * @param refData the reference data used to calculate the settlement date * @return the yield of the product */ public double realYieldFromCurves( ResolvedCapitalIndexedBond bond, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider, ReferenceData refData) { validate(ratesProvider, discountingProvider); LocalDate settlementDate = bond.calculateSettlementDateFromValuation(ratesProvider.getValuationDate(), refData); double dirtyPrice; if (bond.getYieldConvention().equals(CapitalIndexedBondYieldConvention.GB_IL_FLOAT)) { dirtyPrice = dirtyNominalPriceFromCurves(bond, ratesProvider, discountingProvider, settlementDate); } else { double dirtyNominalPrice = dirtyNominalPriceFromCurves(bond, ratesProvider, discountingProvider, settlementDate); dirtyPrice = realPriceFromNominalPrice(bond, ratesProvider, settlementDate, dirtyNominalPrice); } return realYieldFromDirtyPrice(bond, ratesProvider, settlementDate, dirtyPrice); }
if (product.getYieldConvention().equals(CapitalIndexedBondYieldConvention.GB_IL_FLOAT)) { settlePeriod = KnownAmountBondPaymentPeriod.of( Payment.of(product.getCurrency(),