Пример #1
0
        /// <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));
        }
Пример #2
0
        public void GetConvertedInterestRate_DestinationInterestRate_SourceInterestRate(double interestRate, IInterestRateCompounding sourceInterestRateCompounding, IInterestRateCompounding destinationInterestRateCompounding, double interestPeriodLength, double expectedInterestRate)
        {
            double actualInterestRate = Compounding.GetConvertedInterestRate(interestRate, sourceInterestRateCompounding, destinationInterestRateCompounding, interestPeriodLength);

            Assert.That(actualInterestRate, Is.EqualTo(expectedInterestRate).Within(1E-8));
        }
        public void TryGetImpliedInterestRate_destinationNormalizedInterest_sourceInterestRate(double normalizedInterest, IInterestRateCompounding interestRateCompounding, double interestPeriodLength, double expectedInterestRate)
        {
            double actualInterestRate = interestRateCompounding.GetImpliedInterestRate(normalizedInterest, interestPeriodLength);

            Assert.That(actualInterestRate, Is.EqualTo(expectedInterestRate).Within(1E-8));
        }
        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));
        }