public void test_of() { RepoCurveDiscountFactors test = RepoCurveDiscountFactors.of(DSC_FACTORS, GROUP); assertEquals(test.getRepoGroup(), GROUP); assertEquals(test.getCurrency(), GBP); assertEquals(test.getValuationDate(), DATE); assertEquals(test.discountFactor(DATE_AFTER), DSC_FACTORS.discountFactor(DATE_AFTER)); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -91613053: // discountFactors return ((RepoCurveDiscountFactors) bean).getDiscountFactors(); case -393084371: // repoGroup return ((RepoCurveDiscountFactors) bean).getRepoGroup(); } return super.propertyGet(bean, propertyName, quiet); }
public void test_parameterSensitivity() { RepoCurveDiscountFactors base = RepoCurveDiscountFactors.of(DSC_FACTORS, GROUP); RepoCurveZeroRateSensitivity sensi = base.zeroRatePointSensitivity(DATE_AFTER, USD); CurrencyParameterSensitivities computed = base.parameterSensitivity(sensi); CurrencyParameterSensitivities expected = DSC_FACTORS.parameterSensitivity(DSC_FACTORS.zeroRatePointSensitivity(DATE_AFTER, USD)); assertEquals(computed, expected); }
/** * Calculates the zero rate point sensitivity at the specified date. * <p> * This returns a sensitivity instance referring to the zero rate sensitivity of the curve * used to determine the discount factor. * The sensitivity typically has the value {@code (-discountFactor * relativeYearFraction)}. * The sensitivity refers to the result of {@link #discountFactor(LocalDate)}. * * @param date the date to discount to * @return the point sensitivity of the zero rate * @throws RuntimeException if the result cannot be calculated */ public RepoCurveZeroRateSensitivity zeroRatePointSensitivity(LocalDate date) { return zeroRatePointSensitivity(date, getCurrency()); }
PointSensitivityBuilder dirtyPriceSensitivity( ResolvedFixedCouponBond bond, LegalEntityDiscountingProvider provider, LocalDate referenceDate) { RepoCurveDiscountFactors repoDf = repoCurveDf(bond, provider); double df = repoDf.discountFactor(referenceDate); CurrencyAmount pv = presentValue(bond, provider); double notional = bond.getNotional(); PointSensitivityBuilder pvSensi = presentValueSensitivity(bond, provider).multipliedBy(1d / df / notional); RepoCurveZeroRateSensitivity dfSensi = repoDf.zeroRatePointSensitivity(referenceDate) .multipliedBy(-pv.getAmount() / df / df / notional); return pvSensi.combinedWith(dfSensi); }
double dirtyNominalPriceFromCurves( ResolvedCapitalIndexedBond bond, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider, LocalDate settlementDate) { CurrencyAmount pv = presentValue(bond, ratesProvider, discountingProvider, settlementDate); RepoCurveDiscountFactors repoDf = repoCurveDf(bond, discountingProvider); double df = repoDf.discountFactor(settlementDate); double notional = bond.getNotional(); return pv.getAmount() / (df * notional); }
private CurrencyAmount presentValuePayment(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider provider) { RepoCurveDiscountFactors repoDf = DiscountingFixedCouponBondProductPricer.repoCurveDf(trade.getProduct(), provider); Payment upfrontPayment = upfrontPayment(trade); return paymentPricer.presentValue(upfrontPayment, repoDf.getDiscountFactors()); }
public void test_zeroRatePointSensitivity_USD() { RepoCurveDiscountFactors base = RepoCurveDiscountFactors.of(DSC_FACTORS, GROUP); RepoCurveZeroRateSensitivity expected = RepoCurveZeroRateSensitivity.of(DSC_FACTORS.zeroRatePointSensitivity(DATE_AFTER, USD), GROUP); RepoCurveZeroRateSensitivity computed = base.zeroRatePointSensitivity(DATE_AFTER, USD); assertEquals(computed, expected); }
private RepoCurveDiscountFactors repoCurveDiscountFactors(RepoGroup repoGroup, Currency currency) { DiscountFactors discountFactors = repoCurves.get(Pair.of(repoGroup, currency)); if (discountFactors == null) { throw new IllegalArgumentException("Unable to find repo curve: " + repoGroup + ", " + currency); } return RepoCurveDiscountFactors.of(discountFactors, repoGroup); }
@Override public CurrencyParameterSensitivities parameterSensitivity(PointSensitivities pointSensitivities) { CurrencyParameterSensitivities sens = CurrencyParameterSensitivities.empty(); for (PointSensitivity point : pointSensitivities.getSensitivities()) { if (point instanceof RepoCurveZeroRateSensitivity) { RepoCurveZeroRateSensitivity pt = (RepoCurveZeroRateSensitivity) point; RepoCurveDiscountFactors factors = repoCurveDiscountFactors(pt.getRepoGroup(), pt.getCurveCurrency()); sens = sens.combinedWith(factors.parameterSensitivity(pt)); } else if (point instanceof IssuerCurveZeroRateSensitivity) { IssuerCurveZeroRateSensitivity pt = (IssuerCurveZeroRateSensitivity) point; IssuerCurveDiscountFactors factors = issuerCurveDiscountFactors(pt.getLegalEntityGroup(), pt.getCurveCurrency()); sens = sens.combinedWith(factors.parameterSensitivity(pt)); } } return sens; }
public void test_curveParameterSensitivity() { ImmutableLegalEntityDiscountingProvider test = ImmutableLegalEntityDiscountingProvider.builder() .issuerCurves(ImmutableMap.of(Pair.of(GROUP_ISSUER, GBP), DSC_FACTORS_ISSUER)) .issuerCurveGroups(ImmutableMap.of(ID_ISSUER, GROUP_ISSUER)) .repoCurves(ImmutableMap.of(Pair.of(GROUP_REPO_ISSUER, GBP), DSC_FACTORS_REPO)) .repoCurveGroups(ImmutableMap.of(ID_ISSUER, GROUP_REPO_ISSUER)) .valuationDate(DATE) .build(); LocalDate refDate = date(2018, 11, 24); IssuerCurveZeroRateSensitivity sensi1 = test.issuerCurveDiscountFactors(ID_ISSUER, GBP) .zeroRatePointSensitivity(refDate, GBP); RepoCurveZeroRateSensitivity sensi2 = test.repoCurveDiscountFactors(ID_SECURITY, ID_ISSUER, GBP) .zeroRatePointSensitivity(refDate, GBP); PointSensitivities sensi = PointSensitivities.of(sensi1, sensi2); CurrencyParameterSensitivities computed = test.parameterSensitivity(sensi); CurrencyParameterSensitivities expected = DSC_FACTORS_ISSUER.parameterSensitivity(sensi1.createZeroRateSensitivity()).combinedWith( DSC_FACTORS_REPO.parameterSensitivity(sensi2.createZeroRateSensitivity())); assertTrue(computed.equalWithTolerance(expected, 1.0e-12)); }
/** * Obtains an instance based on discount factors and group. * * @param discountFactors the discount factors * @param group the group * @return the repo curve discount factors */ public static RepoCurveDiscountFactors of(DiscountFactors discountFactors, RepoGroup group) { return new RepoCurveDiscountFactors(discountFactors, group); }
PointSensitivityBuilder dirtyNominalPriceSensitivity( ResolvedCapitalIndexedBond bond, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider, LocalDate settlementDate) { double notional = bond.getNotional(); CurrencyAmount pv = presentValue(bond, ratesProvider, discountingProvider, settlementDate); RepoCurveDiscountFactors repoDf = repoCurveDf(bond, discountingProvider); double df = repoDf.discountFactor(settlementDate); PointSensitivityBuilder pvSensi = presentValueSensitivity( bond, ratesProvider, discountingProvider, settlementDate).multipliedBy(1d / (df * notional)); RepoCurveZeroRateSensitivity dfSensi = repoDf.zeroRatePointSensitivity(settlementDate).multipliedBy(-pv.getAmount() / (df * df * notional)); return pvSensi.combinedWith(dfSensi); }
double dirtyNominalPriceFromCurvesWithZSpread( ResolvedCapitalIndexedBond bond, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider, LocalDate settlementDate, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { CurrencyAmount pv = presentValueWithZSpread( bond, ratesProvider, discountingProvider, settlementDate, zSpread, compoundedRateType, periodsPerYear); RepoCurveDiscountFactors repoDf = repoCurveDf(bond, discountingProvider); double df = repoDf.discountFactor(settlementDate); double notional = bond.getNotional(); return pv.getAmount() / (df * notional); }
/** * Calculates the present value of a bill trade. * <p> * If the settlement details are provided, the present value is the sum of the underlying product's present value * multiplied by the quantity and the present value of the settlement payment if still due at the valuation date. * If not it is the underlying product's present value multiplied by the quantity. * * @param trade the trade * @param provider the discounting provider * @return the present value */ public CurrencyAmount presentValue(ResolvedBillTrade trade, LegalEntityDiscountingProvider provider) { if (provider.getValuationDate().isAfter(trade.getProduct().getNotional().getDate())) { return CurrencyAmount.of(trade.getProduct().getCurrency(), 0.0d); } CurrencyAmount pvProduct = productPricer.presentValue(trade.getProduct(), provider) .multipliedBy(trade.getQuantity()); if (trade.getSettlement().isPresent()) { RepoCurveDiscountFactors repoDf = DiscountingBillProductPricer.repoCurveDf(trade.getProduct(), provider); CurrencyAmount pvSettle = paymentPricer.presentValue(trade.getSettlement().get(), repoDf.getDiscountFactors()); return pvProduct.plus(pvSettle); } return pvProduct; }
public void test_zeroRatePointSensitivity() { RepoCurveDiscountFactors base = RepoCurveDiscountFactors.of(DSC_FACTORS, GROUP); RepoCurveZeroRateSensitivity expected = RepoCurveZeroRateSensitivity.of(DSC_FACTORS.zeroRatePointSensitivity(DATE_AFTER), GROUP); RepoCurveZeroRateSensitivity computed = base.zeroRatePointSensitivity(DATE_AFTER); assertEquals(computed, expected); }
@Override public RepoCurveDiscountFactors build() { return new RepoCurveDiscountFactors( discountFactors, repoGroup); }
private PointSensitivityBuilder presentValueSensitivitySettlement( ResolvedCapitalIndexedBondTrade trade, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider) { if (!trade.getSettlement().isPresent()) { // position has no settlement, thus it has no sensitivity return PointSensitivityBuilder.none(); } ResolvedCapitalIndexedBondSettlement settlement = trade.getSettlement().get(); BondPaymentPeriod settlePeriod = settlement.getPayment(); ResolvedCapitalIndexedBond product = trade.getProduct(); RepoCurveDiscountFactors repoDf = DiscountingCapitalIndexedBondProductPricer.repoCurveDf(product, discountingProvider); double df = repoDf.discountFactor(settlePeriod.getPaymentDate()); double netAmount = netAmount(trade, ratesProvider).getAmount(); PointSensitivityBuilder dfSensi = repoDf.zeroRatePointSensitivity(settlePeriod.getPaymentDate()).multipliedBy(netAmount); PointSensitivityBuilder naSensi = netAmountSensitivity(settlement, ratesProvider).multipliedBy(df); return dfSensi.combinedWith(naSensi); }
/** * Calculates the dirty price of the fixed coupon bond under the specified settlement date. * <p> * The fixed coupon bond is represented as {@link Security} where standard ID of the bond is stored. * * @param bond the product * @param provider the discounting provider * @param settlementDate the settlement date * @return the dirty price of the fixed coupon bond security */ public double dirtyPriceFromCurves( ResolvedFixedCouponBond bond, LegalEntityDiscountingProvider provider, LocalDate settlementDate) { CurrencyAmount pv = presentValue(bond, provider, settlementDate); RepoCurveDiscountFactors repoDf = repoCurveDf(bond, provider); double df = repoDf.discountFactor(settlementDate); double notional = bond.getNotional(); return pv.getAmount() / df / notional; }