public void ComputeNpvCommand_ShouldComputeNpv()
        {
            var oneRateLevelOnly = new List <double> {
                0.12
            };

            discountRateLimiter.GetRateLevels(Arg.Any <double>(), Arg.Any <double>(), Arg.Any <double>())
            .Returns(oneRateLevelOnly);
            var npvParameter = new NpvParameter {
                InitialInvestment = -35000
            };
            var sut = new NpvCalculatorViewModel(discountRateLimiter)
            {
                NpvParameter = npvParameter,
            };

            sut.CashFlows.Clear();
            sut.CashFlows.Add(new CashFlow {
                Cash = 10000, Index = 1
            });
            sut.CashFlows.Add(new CashFlow {
                Cash = 27000, Index = 2
            });
            sut.CashFlows.Add(new CashFlow {
                Cash = 19000, Index = 3
            });

            sut.ComputeNpvCommand.Execute(null);

            sut.NetPresentValues.Count.ShouldBe(1);
            Math.Round(sut.NetPresentValues.First().Value, 2).ShouldBe(8976.63);
            //ref: https://www.investopedia.com/ask/answers/032615/what-formula-calculating-net-present-value-npv.asp
        }
Exemplo n.º 2
0
        private void ComputeNpvExecute(object param)
        {
            NetPresentValues.Clear();
            var rateLevels = npvCalculator.GetRateLevels(NpvParameter.LowerBoundDiscountRate,
                                                         NpvParameter.UpperBoundDiscountRate,
                                                         NpvParameter.DiscountRateIncrement);

            for (var i = 0; i < rateLevels.Count; i++)
            {
                NetPresentValues.Add(new NetPresentValue {
                    Index = i + 1, DiscountRateLevel = rateLevels[i]
                });
            }

            for (var i = 0; i < NetPresentValues.Count; i++)
            {
                var discountRateLevel = NetPresentValues[i].DiscountRateLevel;
                var j = 0;
                var totalPresentValue = CashFlows.ToList().Sum(c =>
                {
                    j++;
                    var presentValue = CalculatePresentValue(c.Cash, discountRateLevel, j);
                    return(presentValue);
                });

                NetPresentValues[i].Value = totalPresentValue + NpvParameter.InitialInvestment;
            }

            HasItems = true;
        }