private CurrencyAmount presentValueFromProductPresentValue(ResolvedCapitalIndexedBondTrade trade, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider, CurrencyAmount productPresentValue) { CurrencyAmount pvProduct = productPresentValue.multipliedBy(trade.Quantity); CurrencyAmount pvPayment = presentValueSettlement(trade, ratesProvider, discountingProvider); return(pvProduct.plus(pvPayment)); }
private CurrencyAmount presentValueFromProductPresentValue(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider provider, CurrencyAmount productPresentValue) { CurrencyAmount pvProduct = productPresentValue.multipliedBy(trade.Quantity); CurrencyAmount pvPayment = presentValuePayment(trade, provider); return(pvProduct.plus(pvPayment)); }
//------------------------------------------------------------------------- public virtual void coverage() { KnownAmountRateComputation test = KnownAmountRateComputation.of(GBP_P1000); coverImmutableBean(test); KnownAmountRateComputation test2 = KnownAmountRateComputation.of(GBP_P1000.plus(100)); coverBeanEquals(test, test2); }
/// <summary> /// Calculates the present value of the swaption trade. /// <para> /// The result is expressed using the currency of the swapion. /// /// </para> /// </summary> /// <param name="trade"> the swaption trade </param> /// <param name="ratesProvider"> the rates provider </param> /// <param name="hwProvider"> the Hull-White model parameter trade </param> /// <returns> the present value </returns> public virtual CurrencyAmount presentValue(ResolvedSwaptionTrade trade, RatesProvider ratesProvider, HullWhiteOneFactorPiecewiseConstantParametersProvider hwProvider) { ResolvedSwaption product = trade.Product; CurrencyAmount pvProduct = PRICER_PRODUCT.presentValue(product, ratesProvider, hwProvider); Payment premium = trade.Premium; CurrencyAmount pvPremium = PRICER_PREMIUM.presentValue(premium, ratesProvider); return(pvProduct.plus(pvPremium)); }
public virtual void test_presentValue() { MultiCurrencyAmount computed1 = PRICER.presentValue(CAP_ONE_LEG, RATES, VOLS); MultiCurrencyAmount computed2 = PRICER.presentValue(CAP_TWO_LEGS, RATES, VOLS); CurrencyAmount cap = PRICER_CAP_LEG.presentValue(CAP_LEG, RATES, VOLS); CurrencyAmount pay = PRICER_PAY_LEG.presentValue(PAY_LEG, RATES); assertEquals(computed1, MultiCurrencyAmount.of(cap)); assertEquals(computed2, MultiCurrencyAmount.of(cap.plus(pay))); }
//------------------------------------------------------------------------- /// <summary> /// Calculates the present value of the swaption trade. /// <para> /// The result is expressed using the currency of the swaption. /// /// </para> /// </summary> /// <param name="trade"> the swaption trade </param> /// <param name="ratesProvider"> the rates provider </param> /// <param name="swaptionVolatilities"> the volatilities </param> /// <returns> the present value </returns> public virtual CurrencyAmount presentValue(ResolvedSwaptionTrade trade, RatesProvider ratesProvider, SabrSwaptionVolatilities swaptionVolatilities) { // product ResolvedSwaption product = trade.Product; CurrencyAmount pvProduct = isCash(product) ? cashParYieldPricer.presentValue(product, ratesProvider, swaptionVolatilities) : physicalPricer.presentValue(product, ratesProvider, swaptionVolatilities); // premium Payment premium = trade.Premium; CurrencyAmount pvPremium = paymentPricer.presentValue(premium, ratesProvider); // total return(pvProduct.plus(pvPremium)); }
//------------------------------------------------------------------------- /// <summary> /// Calculates the present value of the trade. /// <para> /// The present value of the product is based on the valuation date. /// </para> /// <para> /// This method can calculate the clean or dirty present value, see <seealso cref="PriceType"/>. /// If calculating the clean value, the accrued interest is calculated based on the step-in date. /// /// </para> /// </summary> /// <param name="trade"> the trade </param> /// <param name="ratesProvider"> the rates provider </param> /// <param name="priceType"> the price type </param> /// <param name="refData"> the reference data </param> /// <returns> the price </returns> public virtual CurrencyAmount presentValue(ResolvedCdsTrade trade, CreditRatesProvider ratesProvider, PriceType priceType, ReferenceData refData) { CurrencyAmount pvProduct = productPricer.presentValue(trade.Product, ratesProvider, ratesProvider.ValuationDate, priceType, refData); if (!trade.UpfrontFee.Present) { return(pvProduct); } Payment upfront = trade.UpfrontFee.get(); CurrencyAmount pvUpfront = upfrontPricer.presentValue(upfront, ratesProvider.discountFactors(upfront.Currency).toDiscountFactors()); return(pvProduct.plus(pvUpfront)); }
/// <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)); }
/// <summary> /// Calculates the current cash of the fixed coupon bond trade. /// </summary> /// <param name="trade"> the trade </param> /// <param name="valuationDate"> the valuation date </param> /// <returns> the current cash amount </returns> public virtual CurrencyAmount currentCash(ResolvedFixedCouponBondTrade trade, LocalDate valuationDate) { Payment upfrontPayment = this.upfrontPayment(trade); Currency currency = upfrontPayment.Currency; // assumes single currency is involved in trade CurrencyAmount currentCash = CurrencyAmount.zero(currency); if (upfrontPayment.Date.Equals(valuationDate)) { currentCash = currentCash.plus(upfrontPayment.Value); } if (trade.Settlement.Present) { LocalDate settlementDate = trade.Settlement.get().SettlementDate; ResolvedFixedCouponBond product = trade.Product; if (!settlementDate.isAfter(valuationDate)) { double cashCoupon = product.hasExCouponPeriod() ? 0d : currentCashCouponPayment(product, valuationDate); Payment payment = product.NominalPayment; double cashNominal = payment.Date.isEqual(valuationDate) ? payment.Amount : 0d; currentCash = currentCash.plus(CurrencyAmount.of(currency, (cashCoupon + cashNominal) * trade.Quantity)); } } return(currentCash); }
/// <summary> /// Calculates the present value of a bill trade with z-spread. /// <para> /// 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. /// </para> /// <para> /// The z-spread is a parallel shift applied to continuously compounded rates or periodic compounded rates of /// the issuer discounting curve. The z-spread is applied only on the legal entity curve, not on the repo curve used /// for the settlement amount. /// /// </para> /// </summary> /// <param name="trade"> the trade </param> /// <param name="provider"> the discounting provider </param> /// <param name="zSpread"> the z-spread </param> /// <param name="compoundedRateType"> the compounded rate type </param> /// <param name="periodsPerYear"> the number of periods per year </param> /// <returns> the present value </returns> public virtual CurrencyAmount presentValueWithZSpread(ResolvedBillTrade trade, LegalEntityDiscountingProvider provider, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { if (provider.ValuationDate.isAfter(trade.Product.Notional.Date)) { return(CurrencyAmount.of(trade.Product.Currency, 0.0d)); } CurrencyAmount pvProduct = productPricer.presentValueWithZSpread(trade.Product, provider, zSpread, compoundedRateType, periodsPerYear).multipliedBy(trade.Quantity); if (trade.Settlement.Present) { RepoCurveDiscountFactors repoDf = DiscountingBillProductPricer.repoCurveDf(trade.Product, provider); CurrencyAmount pvSettle = paymentPricer.presentValue(trade.Settlement.get(), repoDf.DiscountFactors); return(pvProduct.plus(pvSettle)); } return(pvProduct); }
public virtual void test_presentValueWithZSpread_periodic_noExcoupon() { CurrencyAmount computed = PRICER.presentValueWithZSpread(PRODUCT_NO_EXCOUPON, PROVIDER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); CurrencyAmount expected = PRICER_NOMINAL.presentValueWithSpread(PRODUCT.NominalPayment, DSC_FACTORS_ISSUER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); int size = PRODUCT.PeriodicPayments.size(); double pvcCupon = 0d; for (int i = 2; i < size; ++i) { FixedCouponBondPaymentPeriod payment = PRODUCT.PeriodicPayments.get(i); pvcCupon += PRICER_COUPON.presentValueWithSpread(payment, IssuerCurveDiscountFactors.of(DSC_FACTORS_ISSUER, GROUP_ISSUER), Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); } expected = expected.plus(pvcCupon); assertEquals(computed.Currency, EUR); assertEquals(computed.Amount, expected.Amount, NOTIONAL * TOL); }
/// <summary> /// Calculates the present value of the settlement of the bond trade from the clean price with z-spread. /// <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> /// <para> /// The z-spread is a parallel shift applied to continuously compounded rates or periodic /// compounded rates of the discounting curve. /// /// </para> /// </summary> /// <param name="trade"> the trade </param> /// <param name="ratesProvider"> the rates provider, used to determine price index values </param> /// <param name="discountingProvider"> the discount factors provider </param> /// <param name="refData"> the reference data used to calculate the settlement date </param> /// <param name="zSpread"> the z-spread </param> /// <param name="compoundedRateType"> the compounded rate type </param> /// <param name="periodsPerYear"> the number of periods per year </param> /// <param name="cleanRealPrice"> the clean real price </param> /// <returns> the present value of the settlement </returns> public virtual CurrencyAmount presentValueFromCleanPriceWithZSpread(ResolvedCapitalIndexedBondTrade trade, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider, ReferenceData refData, double cleanRealPrice, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { validate(ratesProvider, discountingProvider); LocalDate valuationDate = ratesProvider.ValuationDate; ResolvedCapitalIndexedBond bond = trade.Product; LocalDate standardSettlementDate = bond.calculateSettlementDateFromValuation(valuationDate, refData); LocalDate tradeSettlementDate = settlementDate(trade, valuationDate); RepoCurveDiscountFactors repoDf = DiscountingCapitalIndexedBondProductPricer.repoCurveDf(bond, discountingProvider); double df = repoDf.discountFactor(standardSettlementDate); CurrencyAmount pvStandard = forecastValueStandardFromCleanPrice(bond, ratesProvider, standardSettlementDate, cleanRealPrice).multipliedBy(df); if (standardSettlementDate.isEqual(tradeSettlementDate)) { return(presentValueFromProductPresentValue(trade, ratesProvider, discountingProvider, pvStandard)); } // check coupon payment between two settlement dates IssuerCurveDiscountFactors issuerDf = DiscountingCapitalIndexedBondProductPricer.issuerCurveDf(bond, discountingProvider); double pvDiff = 0d; if (standardSettlementDate.isAfter(tradeSettlementDate)) { pvDiff = -productPricer.presentValueCouponWithZSpread(bond, ratesProvider, issuerDf, tradeSettlementDate, standardSettlementDate, zSpread, compoundedRateType, periodsPerYear); } else { pvDiff = productPricer.presentValueCouponWithZSpread(bond, ratesProvider, issuerDf, standardSettlementDate, tradeSettlementDate, zSpread, compoundedRateType, periodsPerYear); } return(presentValueFromProductPresentValue(trade, ratesProvider, discountingProvider, pvStandard.plus(pvDiff))); }