/// <summary> /// Computes the present value of the payment with z-spread by discounting. /// <para> /// The present value is zero if the payment date is before the valuation date. /// </para> /// <para> /// The specified discount factors should be for the payment currency, however this is not validated. /// </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="payment"> the payment </param> /// <param name="discountFactors"> the discount factors to price against </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 presentValueWithSpread(Payment payment, DiscountFactors discountFactors, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { if (discountFactors.ValuationDate.isAfter(payment.Date)) { return(CurrencyAmount.zero(payment.Currency)); } double df = discountFactors.discountFactorWithSpread(payment.Date, zSpread, compoundedRateType, periodsPerYear); return(payment.Value.multipliedBy(df)); }
/// <summary> /// Compute the present value curve sensitivity of the payment with z-spread. /// <para> /// The present value sensitivity of the payment is the sensitivity of the /// present value to the discount factor curve. /// There is no sensitivity if the payment date is before the valuation date. /// </para> /// <para> /// The specified discount factors should be for the payment currency, however this is not validated. /// </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="payment"> the payment </param> /// <param name="discountFactors"> the discount factors to price against </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 point sensitivity of the present value </returns> public virtual PointSensitivityBuilder presentValueSensitivityWithSpread(Payment payment, DiscountFactors discountFactors, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { if (discountFactors.ValuationDate.isAfter(payment.Date)) { return(PointSensitivityBuilder.none()); } ZeroRateSensitivity sensi = discountFactors.zeroRatePointSensitivityWithSpread(payment.Date, zSpread, compoundedRateType, periodsPerYear); return(sensi.multipliedBy(payment.Amount)); }
public override ZeroRateSensitivity zeroRatePointSensitivityWithSpread(double yearFraction, Currency sensitivityCurrency, double zSpread, CompoundedRateType compoundedRateType, int periodPerYear) { if (Math.Abs(yearFraction) < EFFECTIVE_ZERO) { return(ZeroRateSensitivity.of(currency, yearFraction, sensitivityCurrency, 0)); } if (compoundedRateType.Equals(CompoundedRateType.CONTINUOUS)) { double discountFactor = discountFactorWithSpread(yearFraction, zSpread, compoundedRateType, periodPerYear); return(ZeroRateSensitivity.of(currency, yearFraction, sensitivityCurrency, -discountFactor * yearFraction)); } double df = discountFactor(yearFraction); double df2 = Math.Pow(df, -1.0 / (yearFraction * periodPerYear)); double df3 = df2 + zSpread / periodPerYear; double ddfSdz = -yearFraction *Math.Pow(df3, -yearFraction *periodPerYear - 1) * df2; return(ZeroRateSensitivity.of(currency, yearFraction, sensitivityCurrency, ddfSdz)); }
public virtual void test_of_lookup_null() { assertThrows(() => CompoundedRateType.of(null), typeof(System.ArgumentException)); }
public virtual void test_of_lookup_notFound() { assertThrows(() => CompoundedRateType.of("Rubbish"), typeof(System.ArgumentException)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(dataProvider = "name") public void test_of_lookup(CompoundedRateType convention, String name) public virtual void test_of_lookup(CompoundedRateType convention, string name) { assertEquals(CompoundedRateType.of(name), convention); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(dataProvider = "name") public void test_toString(CompoundedRateType convention, String name) public virtual void test_toString(CompoundedRateType convention, string name) { assertEquals(convention.ToString(), name); }