예제 #1
0
        public void CalculateSetOfNPV_Given_All_Parameters_Is_Valid(
            double initialCost
            , double upperLimit
            , double lowerLimit
            , double increment)
        {
            var request = new CalculateSetOfNPVRequest
            {
                CashFlow = new List <double>
                {
                    1000
                    , 1500
                    , 2000
                    , 2500
                    , 3000
                },
                UpperBoundDiscountRate   = upperLimit
                , LowerBoundDiscountRate = lowerLimit
                , Increment   = increment
                , InitialCost = initialCost
            };
            var cashFlowSummary = string.Join(", ", request.CashFlow.ToArray());
            var npvEngine       = new NPVEngine.NPVEngine();
            var expectedOutput  = new List <NPVSet>();

            while (lowerLimit <= upperLimit)
            {
                expectedOutput.Add(new NPVSet
                {
                    CashFlowSummary = cashFlowSummary
                    , InitialCost   = initialCost * -1
                    , DiscountRate  = lowerLimit
                    , NPV           = npvEngine.CalculateIndividualNPV(new CalculateIndividualNPVRequest
                    {
                        CashFlows = request.CashFlow
                        ,
                        InitialValue = request.InitialCost
                        ,
                        Interest = lowerLimit / 100
                    })
                });
                lowerLimit += increment;
            }

            var actualOutput = npvEngine.CalculateSetOfNPV(request);

            for (var i = 0; i < expectedOutput.Count; i++)
            {
                Assert.AreEqual(expectedOutput[i].CashFlowSummary, actualOutput[i].CashFlowSummary);
                Assert.AreEqual(expectedOutput[i].DiscountRate, actualOutput[i].DiscountRate);
                Assert.AreEqual(Math.Round(expectedOutput[i].NPV, 2), actualOutput[i].NPV);
            }
        }
예제 #2
0
        public void CalculateIndividualNPV_Shall_Satisfy_Expected(double interest, double initialValue, double expectedNPV)
        {
            var npvEngine = new NPVEngine.NPVEngine();
            var cashFlows = new List <double> {
                1000, 2000, 3000, 4000, 5000
            };
            var npv = npvEngine.CalculateIndividualNPV(
                new CalculateIndividualNPVRequest
            {
                CashFlows      = cashFlows
                , Interest     = interest
                , InitialValue = initialValue
            }
                );

            Assert.AreEqual(expectedNPV, Math.Round(npv, 2));
        }