public double Npv(NpvObjectModel model, double discountRate)
        {
            var cashFlows = model.GetCashFlows();
            var npv       = cashFlows.Select((c, n) => c / Math.Pow(1 + (discountRate / 100), n)).Sum();

            return(Math.Round(npv, 2));
        }
        public async Task <NpvResultModel> NpvCollectionAsync(NpvObjectModel model)
        {
            var result = new NpvResultModel();
            await Task.Run(() =>
            {
                var cashFlows = model.CashFlows.Split(',').Select(Double.Parse).ToList();
                cashFlows.Insert(0, -model.IntialInvestment);

                var discountRate = model.LowerBoundDiscountRate;
                while (discountRate <= model.UpperBoundDiscountRate)
                {
                    result.Labels.Add($"{discountRate}%");
                    result.Values.Add(Npv(model, discountRate));

                    discountRate = Math.Round(discountRate + model.DiscountRateIncrement, 2);
                }
                ;
            });

            return(result);
        }
예제 #3
0
        // POST api/values
        public async Task <IHttpActionResult> Post([FromBody] NpvObjectModel model)
        {
            var result = await new ComputeHelper().NpvCollectionAsync(model);

            return(Ok(result));
        }