Esempio n. 1
0
        public void Calculate(ReportGrouping grouping, double discountRatePerYear)
        {
            // The underlying data is always monthly
            var discountRate = grouping == ReportGrouping.Yearly ? discountRatePerYear : Financial.ConvertDiscountRateYearToMonth(discountRatePerYear);

            if (CalculateNpv)
            {
                Npv = (decimal)Financials.Npv.Calculate(_cashFlows, discountRate);
            }
            if (CalculateIrr)
            {
                var irr = Financials.Irr.Calculate(_cashFlows, discountRate);
                Irr = double.IsNaN(irr) ? 0m : (decimal)irr;
            }

            // If we ask for yearly, convert the resulting IRR
            if (grouping == ReportGrouping.Monthly)
            {
                Irr = Financial.ConvertDiscountRateMonthToYear(Irr);
            }
        }