Exemplo n.º 1
0
        public async Task <int> ManageNPVCalculation(CalculateNPVApiRequest request)
        {
            var calculateNPVRequest = new CalculateNPVRequest
            {
                InitialInvestment      = request.InitialInvestment.Value,
                LowerBoundDiscountRate = request.LowerBoundDiscountRate.Value / 100,
                UpperBoundDiscountRate = request.UpperBoundDiscountRate.Value / 100,
                DiscountRateIncrement  = request.DiscountRateIncrement.Value / 100
            };
            var requestId = await DB.InsertAsync(calculateNPVRequest);

            var cashFlows = await ManageCashFlows(request, requestId);

            await ManageNPVResults(calculateNPVRequest, cashFlows, requestId);

            return(requestId);
        }
Exemplo n.º 2
0
        private async Task ManageNPVResults(CalculateNPVRequest calculateNPVRequest, List <CashFlow> cashFlows, int requestId)
        {
            var currentDiscountRate = calculateNPVRequest.LowerBoundDiscountRate;

            while ((decimal)calculateNPVRequest.UpperBoundDiscountRate >= (decimal)currentDiscountRate)
            {
                var computedNPV        = ComputeNPV(calculateNPVRequest.InitialInvestment, currentDiscountRate, cashFlows);
                var calculateNPVResult = new CalculateNPVResult
                {
                    RequestId       = requestId,
                    DiscountRate    = currentDiscountRate,
                    NetPresentValue = computedNPV
                };
                await DB.InsertAsync(calculateNPVResult);

                if ((decimal)calculateNPVRequest.UpperBoundDiscountRate == (decimal)currentDiscountRate)
                {
                    break;
                }

                currentDiscountRate = currentDiscountRate + calculateNPVRequest.DiscountRateIncrement;
            }
        }