/// <summary>Gets a interest rate with respect to a specific compounding convention. /// </summary> /// <param name="interestRate">The interest rate.</param> /// <param name="sourceCompounding">The compounding convention of the input <paramref name="interestRate"/>.</param> /// <param name="destinationCompounding">The compounding convention to convert to.</param> /// <param name="interestPeriodLength">The length of the interest period.</param> /// <returns>The interest rate in its <paramref name="destinationCompounding"/> compounding convention.</returns> /// <remarks>Internally first the normalized interest will be computed with respect to <paramref name="sourceCompounding"/>. Afterwards /// the interest rate will be computed with respect to <paramref name="destinationCompounding"/>. Therefore it may cause some overhead. In /// time critical situations one may use a type safed overload of this method instead.</remarks> public static double GetConvertedInterestRate(double interestRate, IInterestRateCompounding sourceCompounding, IInterestRateCompounding destinationCompounding, double interestPeriodLength) { if (sourceCompounding == null) { throw new ArgumentNullException("sourceCompounding"); } double normalizedInterest = sourceCompounding.GetInterestAmount(interestRate, interestPeriodLength); if (destinationCompounding == null) { throw new ArgumentNullException("destinationCompounding"); } return(destinationCompounding.GetImpliedInterestRate(normalizedInterest, interestPeriodLength)); }
public void GetNormalizedInterest_destinationInterestRate_sourceNormalizedInterest(double interestRate, IInterestRateCompounding interestRateCompounding, double interestPeriodLength, double expectedNormalizedInterest) { double actualInterestAmount = interestRateCompounding.GetInterestAmount(interestRate, interestPeriodLength); Assert.That(actualInterestAmount, Is.EqualTo(expectedNormalizedInterest).Within(1E-8)); }