Ejemplo n.º 1
0
        public void Calculate_CashFlowIs150000AndDiscountRateIsFrom1Point2To1Point4Percent_ReturnsNegative76182Point26()
        {
            var expected = -76182.26;
            var npv      = new NetPresentValue
            {
                CashFlows = new List <CashFlow>
                {
                    new CashFlow {
                        CashFlowValue = 150000
                    },
                    new CashFlow {
                        CashFlowValue = 50000
                    },
                    new CashFlow {
                        CashFlowValue = 25000
                    }
                },
                DiscountRateIncrement  = .1,
                LowerBoundDiscountRate = 1.2,
                UpperBoundDiscountRate = 1.4
            };

            var netPresentValues = this.target.Calculate(npv);

            Assert.AreEqual(expected, netPresentValues.First().NetPresentValue);
        }
Ejemplo n.º 2
0
        public void DeleteNPV(int id)
        {
            var npv = new NetPresentValue {
                Id = id
            };

            this.context.Delete(npv);
        }
Ejemplo n.º 3
0
        public IEnumerable <NetPresentValueResult> Calculate(NetPresentValue npv)
        {
            var netPresentValues       = new Dictionary <string, double>();
            var lowerBoundDiscountRate = double.Parse((npv.LowerBoundDiscountRate / 100).ToString("0.####"));
            var upperBoundDiscountRate = double.Parse((npv.UpperBoundDiscountRate / 100).ToString("0.####"));
            var discountRateIncrement  = double.Parse((npv.DiscountRateIncrement / 100).ToString("0.####"));

            foreach (var rate in this.CalculateDiscountRateRange(lowerBoundDiscountRate, upperBoundDiscountRate, discountRateIncrement))
            {
                var netPresentValue = this.CalculateNetPresentValue(npv.CashFlows.Select(c => c.CashFlowValue), rate);
                var percentage      = rate.ToString("#0.##%");
                yield return(new NetPresentValueResult
                {
                    DiscountRate = percentage,
                    NetPresentValue = netPresentValue,
                    Color = netPresentValue < 0 ? "#ff0000" : "#42A5F5"
                });
            }
        }
Ejemplo n.º 4
0
 public async Task InsertNPVAsync(NetPresentValue netPresentValue)
 {
     await this.context.InsertAsync(netPresentValue);
 }