public void ComputeNpvCommand_ShouldComputeMultipleNpv() { var multipleRateLevels = new List <double> { 0.12, 0.15 }; discountRateLimiter.GetRateLevels(Arg.Any <double>(), Arg.Any <double>(), Arg.Any <double>()) .Returns(multipleRateLevels); 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(2); Math.Round(sut.NetPresentValues.First().Value, 2).ShouldBe(8976.63); Math.Round(sut.NetPresentValues.Last().Value, 2).ShouldBe(6604.34); }
public NpvCalculatorViewModel(IDiscountRateLimiter npvCalculator) { this.npvCalculator = npvCalculator; ComputeNpvCommand = new DelegateCommand <object>(ComputeNpvExecute, ComputeNpvCanExecute); SetCashFlowsCommand = new DelegateCommand <object>(SetCashFlowsExecute); NpvParameter = new NpvParameter { InitialInvestment = -100000, LowerBoundDiscountRate = 0.0365, UpperBoundDiscountRate = 0.037, DiscountRateIncrement = 0.0001, ProjectLife = 3 }; CashFlows.AddRange(new[] { new CashFlow { Index = 0, Cash = 10000 }, new CashFlow { Index = 1, Cash = 10000 }, new CashFlow { Index = 2, Cash = 10000 } }); }
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 }
private bool ComputeNpvCanExecute(object param) { var canExecute = NpvParameter.IsValid() && CashFlows.Any(); return(canExecute); }