public void zSpreadFromCurvesAndCleanPrice_jpi() { LocalDate standardSettle = PRODUCT_JPI.getSettlementDateOffset().adjust(VAL_DATE, REF_DATA); double dirtyNominalPrice = PRICER.dirtyNominalPriceFromCurvesWithZSpread( PRODUCT_JPI, RATES_PROVS_JP, ISSUER_PROVS_JP, REF_DATA, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); double cleanRealPrice = PRICER.realPriceFromNominalPrice(PRODUCT_JPI, RATES_PROVS_JP, standardSettle, PRICER.cleanNominalPriceFromDirtyNominalPrice(PRODUCT_JPI, RATES_PROVS_JP, standardSettle, dirtyNominalPrice)); double computed = PRICER.zSpreadFromCurvesAndCleanPrice( PRODUCT_JPI, RATES_PROVS_JP, ISSUER_PROVS_JP, REF_DATA, cleanRealPrice, PERIODIC, PERIOD_PER_YEAR); assertEquals(computed, Z_SPREAD, TOL); }
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); }
public void test_realYieldFromCurves_us() { LocalDate standardSettle = PRODUCT_US.getSettlementDateOffset().adjust(VAL_DATE, REF_DATA); double computed = PRICER.realYieldFromCurves(PRODUCT_US, RATES_PROVS_US, ISSUER_PROVS_US, REF_DATA); double dirtyNominalPrice = PRICER.dirtyNominalPriceFromCurves( PRODUCT_US, RATES_PROVS_US, ISSUER_PROVS_US, REF_DATA); double dirtyRealPrice = PRICER.realPriceFromNominalPrice(PRODUCT_US, RATES_PROVS_US, standardSettle, dirtyNominalPrice); double expected = PRICER.realYieldFromDirtyPrice(PRODUCT_US, RATES_PROVS_US, standardSettle, dirtyRealPrice); assertEquals(computed, expected, 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; } };
/** * 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); }
/** * Calculates the dirty price of the bond security. * <p> * The bond is represented as {@link Security} where standard ID of the bond is stored. * <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 discountingProvider the discount factors provider * @param refData the reference data used to calculate the settlement date * @return the dirty price of the bond security */ public double dirtyNominalPriceFromCurves( ResolvedCapitalIndexedBond bond, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider, ReferenceData refData) { validate(ratesProvider, discountingProvider); LocalDate settlementDate = bond.calculateSettlementDateFromValuation(ratesProvider.getValuationDate(), refData); return dirtyNominalPriceFromCurves(bond, ratesProvider, discountingProvider, settlementDate); }
new DiscountingCapitalIndexedBondProductPricer(DiscountingCapitalIndexedBondPaymentPeriodPricer.DEFAULT); int periodsPerYear) { validate(ratesProvider, discountingProvider); LocalDate settlementDate = bond.calculateSettlementDateFromValuation(ratesProvider.getValuationDate(), refData); return dirtyNominalPriceFromCurvesWithZSpread( bond, ratesProvider, discountingProvider, settlementDate, zSpread, compoundedRateType, periodsPerYear); int periodsPerYear) { validate(ratesProvider, discountingProvider); LocalDate settlementDate = bond.calculateSettlementDateFromValuation(ratesProvider.getValuationDate(), refData); return dirtyNominalPriceSensitivityWithZSpread( bond, ratesProvider, CurrencyAmount pv = presentValueWithZSpread( bond, ratesProvider, discountingProvider, settlementDate, zSpread, compoundedRateType, periodsPerYear); RepoCurveDiscountFactors repoDf = repoCurveDf(bond, discountingProvider); double df = repoDf.discountFactor(settlementDate); PointSensitivityBuilder pvSensi = presentValueSensitivityWithZSpread(bond, ratesProvider, discountingProvider, settlementDate, zSpread, compoundedRateType, periodsPerYear).multipliedBy(1d / (df * notional)); RepoCurveZeroRateSensitivity dfSensi =
public void test_priceFromRealYield_ukGov() { LocalDate standardSettle = PRODUCT_GOV.getSettlementDateOffset().adjust(VAL_DATE_GB, REF_DATA); double computed = PRICER.cleanPriceFromRealYield(PRODUCT_GOV, RATES_PROVS_GB, standardSettle, YIELD_GOV); assertEquals(computed, 3.60, 1.e-2); double computedOnePeriod = PRICER.cleanPriceFromRealYield(PRODUCT_GOV_OP, RATES_PROVS_GB, PRODUCT_GOV_OP .getSettlementDateOffset().adjust(VAL_DATE_GB, REF_DATA), YIELD_GOV_OP); assertEquals(computedOnePeriod, 3.21, 4.e-2); double dirtyPrice = PRICER.dirtyPriceFromRealYield(PRODUCT_GOV, RATES_PROVS_GB, standardSettle, YIELD_GOV); double cleanPrice = PRICER.cleanNominalPriceFromDirtyNominalPrice( PRODUCT_GOV, RATES_PROVS_GB, standardSettle, dirtyPrice); assertEquals(computed, cleanPrice); double yieldRe = PRICER.realYieldFromDirtyPrice(PRODUCT_GOV, RATES_PROVS_GB, standardSettle, dirtyPrice); assertEquals(yieldRe, YIELD_GOV, TOL); }
public void test_modifiedDuration_convexity_us() { double eps = 1.0e-5; LocalDate standardSettle = PRODUCT_US.getSettlementDateOffset().adjust(VAL_DATE, REF_DATA); double mdComputed = PRICER.modifiedDurationFromRealYieldFiniteDifference(PRODUCT_US, RATES_PROVS_US, standardSettle, YIELD_US); double cvComputed = PRICER.convexityFromRealYieldFiniteDifference(PRODUCT_US, RATES_PROVS_US, standardSettle, YIELD_US); double price = PRICER.cleanPriceFromRealYield(PRODUCT_US, RATES_PROVS_US, standardSettle, YIELD_US); double up = PRICER.cleanPriceFromRealYield(PRODUCT_US, RATES_PROVS_US, standardSettle, YIELD_US + eps); double dw = PRICER.cleanPriceFromRealYield(PRODUCT_US, RATES_PROVS_US, standardSettle, YIELD_US - eps); assertEquals(mdComputed, 0.5 * (dw - up) / eps / price, eps); assertEquals(cvComputed, (up + dw - 2d * price) / price / eps / eps, eps); }
/** * 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); }
public void zSpreadFromCurvesAndCleanPrice_ukGov() { LocalDate standardSettle = PRODUCT_GOV.getSettlementDateOffset().adjust(VAL_DATE_GB, REF_DATA); double dirtyNominalPrice = PRICER.dirtyNominalPriceFromCurvesWithZSpread( PRODUCT_GOV, RATES_PROVS_GB, ISSUER_PROVS_GB, REF_DATA, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); double cleanNominalPrice = PRICER.cleanNominalPriceFromDirtyNominalPrice(PRODUCT_GOV, RATES_PROVS_GB, standardSettle, dirtyNominalPrice); double computed = PRICER.zSpreadFromCurvesAndCleanPrice( PRODUCT_GOV, RATES_PROVS_GB, ISSUER_PROVS_GB, REF_DATA, cleanNominalPrice, PERIODIC, PERIOD_PER_YEAR); assertEquals(computed, Z_SPREAD, TOL); }
public void test_realYieldFromCurves_ukGov() { LocalDate standardSettle = PRODUCT_GOV.getSettlementDateOffset().adjust(VAL_DATE_GB, REF_DATA); double computed = PRICER.realYieldFromCurves(PRODUCT_GOV, RATES_PROVS_GB, ISSUER_PROVS_GB, REF_DATA); double dirtyNominalPrice = PRICER.dirtyNominalPriceFromCurves( PRODUCT_GOV, RATES_PROVS_GB, ISSUER_PROVS_GB, REF_DATA); double expected = PRICER.realYieldFromDirtyPrice(PRODUCT_GOV, RATES_PROVS_GB, standardSettle, dirtyNominalPrice); assertEquals(computed, expected, TOL); }
public void test_dirtyNominalPriceFromCurvesWithZSpread() { double computed = PRICER.dirtyNominalPriceFromCurvesWithZSpread( PRODUCT, RATES_PROVIDER, ISSUER_RATES_PROVIDER, REF_DATA, Z_SPREAD, CONTINUOUS, 0); LocalDate settlement = SETTLE_OFFSET.adjust(VALUATION, REF_DATA); double df = ISSUER_RATES_PROVIDER.repoCurveDiscountFactors(SECURITY_ID, LEGAL_ENTITY, USD).discountFactor(settlement); double expected = PRICER.presentValueWithZSpread(PRODUCT, RATES_PROVIDER, ISSUER_RATES_PROVIDER, settlement, Z_SPREAD, CONTINUOUS, 0).getAmount() / NOTIONAL / df; assertEquals(computed, expected, TOL); }
public void test_dirtyNominalPriceFromCurves() { double computed = PRICER.dirtyNominalPriceFromCurves( PRODUCT, RATES_PROVIDER, ISSUER_RATES_PROVIDER, REF_DATA); LocalDate settlement = SETTLE_OFFSET.adjust(VALUATION, REF_DATA); double df = ISSUER_RATES_PROVIDER.repoCurveDiscountFactors(SECURITY_ID, LEGAL_ENTITY, USD).discountFactor(settlement); double expected = PRICER.presentValue(PRODUCT, RATES_PROVIDER, ISSUER_RATES_PROVIDER, settlement).getAmount() / NOTIONAL / df; assertEquals(computed, expected, TOL); }
public void test_currentCash_exCoupon() { CurrencyAmount computed = PRICER.currentCash(PRODUCT_EX_COUPON, RATES_PROVIDER, VALUATION); assertEquals(computed.getAmount(), 0d); }
pvAtFirstCoupon = cpnRate * nbCoupon + 1d; return pvAtFirstCoupon / (1d + factorToNextCoupon(bond, settlementDate) * yield / couponPerYear); double firstYearFraction = bond.yearFraction(period.getUnadjustedStartDate(), period.getUnadjustedEndDate()); double v = 1d / (1d + yield / couponPerYear); double rs = ratioPeriodToNextCoupon(period, settlementDate); if (yieldConvention.equals(CapitalIndexedBondYieldConvention.GB_IL_FLOAT)) { RateComputation obs = period.getRateComputation(); double indexRatio = indexRatio(bond, ratesProvider, settlementDate); double firstCashFlow = realRate * indexRatio * firstYearFraction * couponPerYear; if (nbCoupon == 1) { double maturity = bond.yearFraction(settlementDate, maturityDate); double cleanPrice = (1d + realRate * couponPerYear * maturity) / (1d + yield * maturity); return dirtyRealPriceFromCleanRealPrice(bond, settlementDate, cleanPrice); double factorToNext = factorToNextCoupon(bond, settlementDate); return pvAtFirstCoupon * Math.pow(v, factorToNext);
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); }
/** * Calculates the dirty price sensitivity of the bond security. * <p> * The dirty price sensitivity of the security is the sensitivity of the dirty price value to * the underlying curves. * * @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 dirty price curve sensitivity of the security */ public PointSensitivityBuilder dirtyNominalPriceSensitivity( ResolvedCapitalIndexedBond bond, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider, ReferenceData refData) { validate(ratesProvider, discountingProvider); LocalDate settlementDate = bond.calculateSettlementDateFromValuation(ratesProvider.getValuationDate(), refData); return dirtyNominalPriceSensitivity(bond, ratesProvider, discountingProvider, settlementDate); }
public void test_cleanNominalPrice_dirtyNominalPrice() { double dirtyNominalPrice = 1.055; LocalDate refDate = LocalDate.of(2014, 6, 10); double cleanNominalPrice = PRICER.cleanNominalPriceFromDirtyNominalPrice(PRODUCT, RATES_PROVIDER, refDate, dirtyNominalPrice); RateComputation obs = RATE_CALC.createRateComputation(VALUATION); double refRate = RateComputationFn.standard().rate(obs, null, null, RATES_PROVIDER); double expected = dirtyNominalPrice - PRODUCT.accruedInterest(refDate) * (refRate + 1d) / NOTIONAL; assertEquals(cleanNominalPrice, expected, TOL); assertEquals(PRICER.dirtyNominalPriceFromCleanNominalPrice(PRODUCT, RATES_PROVIDER, refDate, cleanNominalPrice), dirtyNominalPrice, TOL); }
public void test_dirtyPriceNominalPriceFromCurvesSensitivity() { PointSensitivities point = PRICER.dirtyNominalPriceSensitivity( PRODUCT, RATES_PROVIDER, ISSUER_RATES_PROVIDER, REF_DATA).build(); CurrencyParameterSensitivities computed1 = RATES_PROVIDER.parameterSensitivity(point); CurrencyParameterSensitivities computed2 = ISSUER_RATES_PROVIDER.parameterSensitivity(point); CurrencyParameterSensitivities expected = fdPriceSensitivity(PRODUCT, RATES_PROVIDER, ISSUER_RATES_PROVIDER); assertTrue(expected.equalWithTolerance(computed1.combinedWith(computed2), EPS * NOTIONAL)); }