public void test_cleanRealPrice_dirtyRealPrice() { double dirtyRealPrice = 1.055; LocalDate refDate = LocalDate.of(2014, 6, 10); double cleanRealPrice = PRICER.cleanRealPriceFromDirtyRealPrice(PRODUCT, refDate, dirtyRealPrice); double expected = dirtyRealPrice - PRODUCT.accruedInterest(refDate) / NOTIONAL; assertEquals(cleanRealPrice, expected, TOL); assertEquals(PRICER.dirtyRealPriceFromCleanRealPrice(PRODUCT, refDate, cleanRealPrice), dirtyRealPrice, TOL); }
/** * 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); }
public void test_priceFromRealYield_jpw() { LocalDate standardSettle = PRODUCT_JPW.getSettlementDateOffset().adjust(VAL_DATE, REF_DATA); double computed = PRICER.cleanPriceFromRealYield(PRODUCT_JPW, RATES_PROVS_JP, standardSettle, YIELD_JPW); assertEquals(computed, 1.10, 1.e-2); double dirtyPrice = PRICER.dirtyPriceFromRealYield(PRODUCT_JPW, RATES_PROVS_JP, standardSettle, YIELD_JPW); double cleanPrice = PRICER.cleanRealPriceFromDirtyRealPrice(PRODUCT_JPW, standardSettle, dirtyPrice); assertEquals(computed, cleanPrice); double yieldRe = PRICER.realYieldFromDirtyPrice(PRODUCT_JPW, RATES_PROVS_JP, standardSettle, dirtyPrice); assertEquals(yieldRe, YIELD_JPW, TOL); }
@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; } };
public void test_priceFromRealYield_ukCorp() { LocalDate standardSettle = PRODUCT_CORP.getSettlementDateOffset().adjust(VAL_DATE_GB, REF_DATA); double computed = PRICER.cleanPriceFromRealYield(PRODUCT_CORP, RATES_PROVS_GB, standardSettle, YIELD_CORP); assertEquals(computed, 1.39, 1.e-2); double computedOnePeriod = PRICER.cleanPriceFromRealYield( PRODUCT_CORP, RATES_PROVS_GB, LocalDate.of(2039, 12, 1), -0.02842); assertEquals(computedOnePeriod, 1.01, 1.e-2); double dirtyPrice = PRICER.dirtyPriceFromRealYield(PRODUCT_CORP, RATES_PROVS_GB, standardSettle, YIELD_CORP); double cleanPrice = PRICER.cleanRealPriceFromDirtyRealPrice(PRODUCT_CORP, standardSettle, dirtyPrice); assertEquals(computed, cleanPrice); double yieldRe = PRICER.realYieldFromDirtyPrice(PRODUCT_CORP, RATES_PROVS_GB, standardSettle, dirtyPrice); assertEquals(yieldRe, YIELD_CORP, TOL); }
public void test_priceFromRealYield_jpi() { LocalDate standardSettle = PRODUCT_JPI.getSettlementDateOffset().adjust(VAL_DATE, REF_DATA); double computed = PRICER.cleanPriceFromRealYield(PRODUCT_JPI, RATES_PROVS_JP, standardSettle, YIELD_JPI); assertEquals(computed, 1.04, 1.e-2); double dirtyPrice = PRICER.dirtyPriceFromRealYield(PRODUCT_JPI, RATES_PROVS_JP, standardSettle, YIELD_JPI); double cleanPrice = PRICER.cleanRealPriceFromDirtyRealPrice(PRODUCT_JPI, standardSettle, dirtyPrice); assertEquals(computed, cleanPrice); double yieldRe = PRICER.realYieldFromDirtyPrice(PRODUCT_JPI, RATES_PROVS_JP, standardSettle, dirtyPrice); assertEquals(yieldRe, YIELD_JPI, TOL); }
public void test_priceFromRealYield_us() { LocalDate standardSettle = PRODUCT_US.getSettlementDateOffset().adjust(VAL_DATE, REF_DATA); double computed = PRICER.cleanPriceFromRealYield(PRODUCT_US, RATES_PROVS_US, standardSettle, YIELD_US); assertEquals(computed, 1.06, 1.e-2); double computedSmall = PRICER.cleanPriceFromRealYield(PRODUCT_US, RATES_PROVS_US, standardSettle, 0.0); assertEquals(computedSmall, 1.05, 1.e-2); double dirtyPrice = PRICER.dirtyPriceFromRealYield(PRODUCT_US, RATES_PROVS_US, standardSettle, YIELD_US); double cleanPrice = PRICER.cleanRealPriceFromDirtyRealPrice(PRODUCT_US, standardSettle, dirtyPrice); assertEquals(computed, cleanPrice); double yieldRe = PRICER.realYieldFromDirtyPrice(PRODUCT_US, RATES_PROVS_US, standardSettle, dirtyPrice); assertEquals(yieldRe, YIELD_US, TOL); }