/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ protected Builder(ResolvedBill beanToCopy) { this.securityId = beanToCopy.getSecurityId(); this.notional = beanToCopy.getNotional(); this.dayCount = beanToCopy.getDayCount(); this.yieldConvention = beanToCopy.getYieldConvention(); this.legalEntityId = beanToCopy.getLegalEntityId(); this.settlementDateOffset = beanToCopy.getSettlementDateOffset(); }
/** * Calculates the yield for settlement at a given settlement date using curves. * * @param bill the bill * @param provider the discounting provider * @param settlementDate the settlement date * @return the yield */ public double yieldFromCurves(ResolvedBill bill, LegalEntityDiscountingProvider provider, LocalDate settlementDate) { double price = priceFromCurves(bill, provider, settlementDate); return bill.yieldFromPrice(price, settlementDate); }
static RepoCurveDiscountFactors repoCurveDf(ResolvedBill bill, LegalEntityDiscountingProvider provider) { return provider.repoCurveDiscountFactors(bill.getSecurityId(), bill.getLegalEntityId(), bill.getCurrency()); }
static IssuerCurveDiscountFactors issuerCurveDf(ResolvedBill bill, LegalEntityDiscountingProvider provider) { return provider.issuerCurveDiscountFactors(bill.getLegalEntityId(), bill.getCurrency()); }
public void yield_from_price_discount() { ResolvedBill bill = sut(); double price = 0.99; LocalDate settlementDate = LocalDate.of(2018, 8, 17); double af = bill.getDayCount().relativeYearFraction(settlementDate, bill.getNotional().getDate()); double yieldExpected = (1.0d - price) / af; double yieldComputed = bill.yieldFromPrice(price, settlementDate); assertEquals(yieldExpected, yieldComputed, TOLERANCE_PRICE); }
/** * Calculates the present value of the bill product. * <p> * The present value of the product is the value on the valuation date. * The result is expressed using the payment currency of the bill. * <p> * Coupon payments of the product are considered based on the valuation date. * * @param bill the product * @param provider the discounting provider * @return the present value of the bill product */ public CurrencyAmount presentValue(ResolvedBill bill, LegalEntityDiscountingProvider provider) { if (provider.getValuationDate().isAfter(bill.getNotional().getDate())) { return CurrencyAmount.of(bill.getCurrency(), 0.0d); } IssuerCurveDiscountFactors issuerDf = issuerCurveDf(bill, provider); double dfMaturity = issuerDf.discountFactor(bill.getNotional().getDate()); return bill.getNotional().getValue().multipliedBy(dfMaturity); }
public void price_from_yield_discount() { ResolvedBill bill = sut(); double yield = 0.01; LocalDate settlementDate = LocalDate.of(2018, 8, 17); double af = bill.getDayCount().relativeYearFraction(settlementDate, bill.getNotional().getDate()); double priceExpected = 1.0d - yield * af; double priceComputed = bill.priceFromYield(yield, settlementDate); assertEquals(priceExpected, priceComputed, TOLERANCE_PRICE); }
/** * Calculates the present value sensitivity of the bill product. * <p> * The present value sensitivity of the product is the sensitivity of the present value to * the underlying curves. * * @param bill the product * @param provider the discounting provider * @return the present value curve sensitivity of the product */ public PointSensitivities presentValueSensitivity(ResolvedBill bill, LegalEntityDiscountingProvider provider) { if (provider.getValuationDate().isAfter(bill.getNotional().getDate())) { return PointSensitivities.empty(); } IssuerCurveDiscountFactors issuerDf = issuerCurveDf(bill, provider); double dfEndBar = bill.getNotional().getAmount(); PointSensitivityBuilder sensMaturity = issuerDf.zeroRatePointSensitivity(bill.getNotional().getDate()) .multipliedBy(dfEndBar); return sensMaturity.build(); }
@Override public ResolvedBill build() { return new ResolvedBill(this); }
public void yield_from_price_intatmat() { ResolvedBill bill = BillTest.US_BILL .toBuilder().yieldConvention(BillYieldConvention.INTEREST_AT_MATURITY).build().resolve(REF_DATA); double price = 0.99; LocalDate settlementDate = LocalDate.of(2018, 8, 17); double af = bill.getDayCount().relativeYearFraction(settlementDate, bill.getNotional().getDate()); double yieldExpected = (1.0d / price - 1.0d) / af; double yieldComputed = bill.yieldFromPrice(price, settlementDate); assertEquals(yieldExpected, yieldComputed, TOLERANCE_PRICE); }
/** * Calculates the present value of a bill product with z-spread. * <p> * The z-spread is a parallel shift applied to continuously compounded rates or * periodic compounded rates of the issuer discounting curve. * * @param bill the product * @param provider the discounting provider * @param zSpread the z-spread * @param compoundedRateType the compounded rate type * @param periodsPerYear the number of periods per year * @return the present value of the bill product */ public CurrencyAmount presentValueWithZSpread( ResolvedBill bill, LegalEntityDiscountingProvider provider, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { if (provider.getValuationDate().isAfter(bill.getNotional().getDate())) { return CurrencyAmount.of(bill.getCurrency(), 0.0d); } IssuerCurveDiscountFactors issuerDf = issuerCurveDf(bill, provider); double dfMaturity = issuerDf.getDiscountFactors() .discountFactorWithSpread(bill.getNotional().getDate(), zSpread, compoundedRateType, periodsPerYear); return bill.getNotional().getValue().multipliedBy(dfMaturity); }
public void price_from_yield_intatmat() { ResolvedBill bill = BillTest.US_BILL .toBuilder().yieldConvention(BillYieldConvention.INTEREST_AT_MATURITY).build().resolve(REF_DATA); double yield = 0.01; LocalDate settlementDate = LocalDate.of(2018, 8, 17); double af = bill.getDayCount().relativeYearFraction(settlementDate, bill.getNotional().getDate()); double priceExpected = 1.0d / (1 + yield * af); double priceComputed = bill.priceFromYield(yield, settlementDate); assertEquals(priceExpected, priceComputed, TOLERANCE_PRICE); }
/** * Calculates the price for settlement at a given settlement date using curves. * * @param bill the bill * @param provider the discounting provider * @param settlementDate the settlement date * @return the price */ public double priceFromCurves(ResolvedBill bill, LegalEntityDiscountingProvider provider, LocalDate settlementDate) { ArgChecker.inOrderNotEqual(settlementDate, bill.getNotional().getDate(), "settlementDate", "endDate"); ArgChecker.inOrderOrEqual(provider.getValuationDate(), settlementDate, "valuationDate", "settlementDate"); IssuerCurveDiscountFactors issuerDf = issuerCurveDf(bill, provider); double dfMaturity = issuerDf.discountFactor(bill.getNotional().getDate()); RepoCurveDiscountFactors repoDf = repoCurveDf(bill, provider); double dfRepoSettle = repoDf.discountFactor(settlementDate); return dfMaturity / dfRepoSettle; }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 1574023291: // securityId return ((ResolvedBill) bean).getSecurityId(); case 1585636160: // notional return ((ResolvedBill) bean).getNotional(); case 1905311443: // dayCount return ((ResolvedBill) bean).getDayCount(); case -1895216418: // yieldConvention return ((ResolvedBill) bean).getYieldConvention(); case 866287159: // legalEntityId return ((ResolvedBill) bean).getLegalEntityId(); case 135924714: // settlementDateOffset return ((ResolvedBill) bean).getSettlementDateOffset(); } return super.propertyGet(bean, propertyName, quiet); }
/** * Calculates the current cash of a bill trade. * * @param trade the trade * @param valuationDate the valuation date * @return the current cash amount */ public CurrencyAmount currentCash(ResolvedBillTrade trade, LocalDate valuationDate) { if (trade.getProduct().getNotional().getDate().equals(valuationDate)) { return trade.getProduct().getNotional().getValue().multipliedBy(trade.getQuantity()); } if (trade.getSettlement().isPresent() && trade.getSettlement().get().getDate().equals(valuationDate)) { return trade.getSettlement().get().getValue(); } return CurrencyAmount.zero(trade.getProduct().getCurrency()); }
int periodsPerYear) { if (provider.getValuationDate().isAfter(bill.getNotional().getDate())) { return PointSensitivities.empty(); double dfEndBar = bill.getNotional().getAmount(); ZeroRateSensitivity zeroSensMaturity = issuerDf.getDiscountFactors() .zeroRatePointSensitivityWithSpread(bill.getNotional().getDate(), zSpread, compoundedRateType, periodsPerYear); IssuerCurveZeroRateSensitivity dscSensMaturity = IssuerCurveZeroRateSensitivity.of(zeroSensMaturity, issuerDf.getLegalEntityGroup())
/** * Calculates the yield for settlement at a given settlement date using curves with z-spread. * <p> * The z-spread is a parallel shift applied to continuously compounded rates or * periodic compounded rates of the issuer discounting curve. * <p> * The z-spread is applied only on the legal entity curve, not on the repo curve. * * @param bill the bill * @param provider the discounting provider * @param settlementDate the settlement date * @param zSpread the z-spread * @param compoundedRateType the compounded rate type * @param periodsPerYear the number of periods per year * @return the yield */ public double yieldFromCurvesWithZSpread( ResolvedBill bill, LegalEntityDiscountingProvider provider, LocalDate settlementDate, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { double price = priceFromCurvesWithZSpread(bill, provider, settlementDate, zSpread, compoundedRateType, periodsPerYear); return bill.yieldFromPrice(price, settlementDate); }
public void test_resolve() { ResolvedBill resolved = US_BILL.resolve(REF_DATA); assertEquals(resolved.getDayCount(), DAY_COUNT); assertEquals(resolved.getLegalEntityId(), LEGAL_ENTITY); assertEquals(resolved.getNotional(), NOTIONAL.resolve(REF_DATA)); assertEquals(resolved.getSecurityId(), SECURITY_ID); assertEquals(resolved.getSettlementDateOffset(), SETTLE); assertEquals(resolved.getYieldConvention(), YIELD_CONVENTION); }
/** * 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; }
int periodsPerYear) { ArgChecker.inOrderNotEqual(settlementDate, bill.getNotional().getDate(), "settlementDate", "endDate"); ArgChecker.inOrderOrEqual(provider.getValuationDate(), settlementDate, "valuationDate", "settlementDate"); IssuerCurveDiscountFactors issuerDf = issuerCurveDf(bill, provider); double dfMaturity = issuerDf.getDiscountFactors() .discountFactorWithSpread(bill.getNotional().getDate(), zSpread, compoundedRateType, periodsPerYear); RepoCurveDiscountFactors repoDf = repoCurveDf(bill, provider); double dfRepoSettle = repoDf.discountFactor(settlementDate);