Ejemplo n.º 1
0
        public IEnumerable <NetPresentValuePerRate> CalculateNetPresentValueDynamicRate(
            double initialInvestment,
            double lowerBoundDiscountRate,
            double upperBoundDiscountRate,
            double discountRateIncrement,
            IEnumerable <PeriodAmount> cashFlows)
        {
            FinancialValidator.ValidateRate(lowerBoundDiscountRate);
            FinancialValidator.ValidateRate(upperBoundDiscountRate);
            FinancialValidator.ValidateRateIncrement(upperBoundDiscountRate, discountRateIncrement);
            cashFlows.ToList().ForEach(cf => FinancialValidator.ValidateExponent(cf.Period));

            var netPresentValues = new List <NetPresentValuePerRate>();

            for (double rate = lowerBoundDiscountRate; rate <= upperBoundDiscountRate; rate += discountRateIncrement)
            {
                var value = CalculateNetPresentValue(initialInvestment, rate, cashFlows);

                netPresentValues.Add(new NetPresentValuePerRate()
                {
                    Amount = value,
                    Rate   = rate
                });
            }

            return(netPresentValues);
        }
Ejemplo n.º 2
0
        public void ValidateRate_Throws_ArgumentException()
        {
            // Arrange
            double invalidRate = -1D;

            // Act
            Action act = () => FinancialValidator.ValidateRate(invalidRate);

            // Assert
            Assert.Throws <ArgumentException>(act);
        }
Ejemplo n.º 3
0
        public void ValidateExponent_Throws_ArgumentException()
        {
            // Arrange
            double invalidExponent = -2D;

            // Act
            Action act = () => FinancialValidator.ValidateExponent(invalidExponent);

            // Assert
            Assert.Throws <ArgumentException>(act);
        }
Ejemplo n.º 4
0
        public void ValidateRateIncrement_Throws_ArgumentException()
        {
            // Arrange
            double upperBoundRate       = 15D;
            double invalidRateIncrement = 16D;

            // Act
            Action act = () => FinancialValidator.ValidateRateIncrement(upperBoundRate, invalidRateIncrement);

            // Assert
            Assert.Throws <ArgumentException>(act);
        }