//------------------------------------------------------------------------- private CurrencyAmount presentValueSettlement(ResolvedCapitalIndexedBondTrade trade, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider) { if (!trade.Settlement.Present) { // position has no settlement, thus it has no value return(CurrencyAmount.zero(trade.Product.Currency)); } BondPaymentPeriod settlePeriod = trade.Settlement.get().Payment; ResolvedCapitalIndexedBond product = trade.Product; CurrencyAmount netAmount = this.netAmount(trade, ratesProvider); RepoCurveDiscountFactors repoDf = DiscountingCapitalIndexedBondProductPricer.repoCurveDf(product, discountingProvider); return(netAmount.multipliedBy(repoDf.discountFactor(settlePeriod.PaymentDate))); }
// the sensitivity of the net amount of the settlement private PointSensitivityBuilder netAmountSensitivity(ResolvedCapitalIndexedBondSettlement settlement, RatesProvider ratesProvider) { BondPaymentPeriod settlePeriod = settlement.Payment; if (settlePeriod is KnownAmountBondPaymentPeriod) { return(PointSensitivityBuilder.none()); } else if (settlePeriod is CapitalIndexedBondPaymentPeriod) { CapitalIndexedBondPaymentPeriod casted = (CapitalIndexedBondPaymentPeriod)settlePeriod; return(productPricer.PeriodPricer.forecastValueSensitivity(casted, ratesProvider)); } throw new System.NotSupportedException("unsupported settlement type"); }
/// <summary> /// Calculates the current cash of the bond trade. /// </summary> /// <param name="trade"> the trade </param> /// <param name="ratesProvider"> the rates provider, used to determine price index values </param> /// <returns> the current cash </returns> public virtual CurrencyAmount currentCash(ResolvedCapitalIndexedBondTrade trade, RatesProvider ratesProvider) { LocalDate valuationDate = ratesProvider.ValuationDate; LocalDate settlementDate = this.settlementDate(trade, valuationDate); CurrencyAmount cashProduct = productPricer.currentCash(trade.Product, ratesProvider, settlementDate); if (!trade.Settlement.Present) { return(cashProduct); } BondPaymentPeriod settlePeriod = trade.Settlement.get().Payment; double cashSettle = settlePeriod.PaymentDate.isEqual(valuationDate) ? netAmount(trade, ratesProvider).Amount : 0d; return(cashProduct.plus(cashSettle)); }
// the sensitivity of the present value of the settlement private PointSensitivityBuilder presentValueSensitivitySettlement(ResolvedCapitalIndexedBondTrade trade, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider) { if (!trade.Settlement.Present) { // position has no settlement, thus it has no sensitivity return(PointSensitivityBuilder.none()); } ResolvedCapitalIndexedBondSettlement settlement = trade.Settlement.get(); BondPaymentPeriod settlePeriod = settlement.Payment; ResolvedCapitalIndexedBond product = trade.Product; RepoCurveDiscountFactors repoDf = DiscountingCapitalIndexedBondProductPricer.repoCurveDf(product, discountingProvider); double df = repoDf.discountFactor(settlePeriod.PaymentDate); double netAmount = this.netAmount(trade, ratesProvider).Amount; PointSensitivityBuilder dfSensi = repoDf.zeroRatePointSensitivity(settlePeriod.PaymentDate).multipliedBy(netAmount); PointSensitivityBuilder naSensi = netAmountSensitivity(settlement, ratesProvider).multipliedBy(df); return(dfSensi.combinedWith(naSensi)); }
//------------------------------------------------------------------------- /// <summary> /// Calculates the net amount of the settlement of the bond trade. /// <para> /// Since the sign of the settlement notional is opposite to that of the product, negative amount will be returned /// for positive quantity of trade. /// /// </para> /// </summary> /// <param name="trade"> the trade </param> /// <param name="ratesProvider"> the rates provider, used to determine price index values </param> /// <returns> the net amount </returns> public virtual CurrencyAmount netAmount(ResolvedCapitalIndexedBondTrade trade, RatesProvider ratesProvider) { if (!trade.Settlement.Present) { // position has no settlement, thus it has no value return(CurrencyAmount.zero(trade.Product.Currency)); } BondPaymentPeriod settlePeriod = trade.Settlement.get().Payment; if (settlePeriod is KnownAmountBondPaymentPeriod) { Payment payment = ((KnownAmountBondPaymentPeriod)settlePeriod).Payment; return(payment.Value); } else if (settlePeriod is CapitalIndexedBondPaymentPeriod) { CapitalIndexedBondPaymentPeriod casted = (CapitalIndexedBondPaymentPeriod)settlePeriod; double netAmount = productPricer.PeriodPricer.forecastValue(casted, ratesProvider); return(CurrencyAmount.of(casted.Currency, netAmount)); } throw new System.NotSupportedException("unsupported settlement type"); }