/// <summary> /// Смята резултатите на финансовия калкулатор /// </summary> /// <param name="p"></param> /// <returns></returns> public CreditCalcResults Calculate(CreditCalcParams p) { IsParamsValid(p); CreditCalcResults res = null; if (p.IsAnnuityInstallments) { res = CalculateAnnuity(p); } else { res = CalculateDescending(p); } APRCalculator aprCalc = new APRCalculator(p.Amount); foreach (var m in res.MonthlyInstallments) { if (m.RowNumber == 0) { aprCalc.AddInstalment(m.Fees, 0); } else { aprCalc.AddInstalment(m.TotalInstallment, 365.25M / 12M * m.RowNumber); } res.TotalFees += m.Fees; res.TotalRates += m.RateInstallment; res.TotalInstallments += m.Installment; } res.AnnualPercentageRate = aprCalc.Calculate(); res.TotalInstallmentsWithTotalFeesAndRates = res.TotalInstallments + res.TotalFees; return(res); }
public LeasingCalcResults Calculate(LeasingCalcParams p) { IsParamsValid(p); LeasingCalcResults res = new LeasingCalcResults(); decimal loanAmount = (decimal)p.Price - (decimal)p.InitialInstallment; APRCalculator aprCalc = new APRCalculator(loanAmount); decimal initialFee = GetFeeAmount(p.Price.Value, p.InitialManagementFee, p.TreatInitialManagementFeeAsPercent); aprCalc.AddInstalment(initialFee, 0); for (int i = 1; i <= p.Period; i++) { aprCalc.AddInstalment(p.MonthlyInstallment.Value, 365.25M / 12M * i); } res.AnnualPercentRate = Math.Round(aprCalc.Calculate(), 2); res.TotalFees = Math.Round(initialFee, 2); res.TotalPaidWithFees = Math.Round(p.MonthlyInstallment.Value * p.Period.Value + p.InitialInstallment.Value + res.TotalFees, 2); return(res); }