Esempio n. 1
0
        public LoanResponseDetailsDto CalculateLoan(LoanRequestDetailsDto loanRequestDetails)
        {
            var response = new LoanResponseDetailsDto();

            response.MonthlyPayment    = _loanService.CalculateMonthlyPayment(loanRequestDetails);
            response.AdministrationFee = _loanService.CalculateAdministrationFee(loanRequestDetails);
            response.TotalInterestPaid = _loanService.CalculateTotalInterestPaid(
                response.MonthlyPayment,
                loanRequestDetails.LoanDuration,
                loanRequestDetails.LoanAmount);
            response.APR = _loanService.CalculateAPR(loanRequestDetails);

            return(response);
        }
Esempio n. 2
0
        public double CalculateAPR(LoanRequestDetailsDto loanRequest)
        {
            var totalAccruedAmount = loanRequest.LoanAmount * (1 + loanRequest.LoanDuration * loanRequest.InterestRate / 100);
            var interestAccrued    = totalAccruedAmount - loanRequest.LoanAmount;
            var administrationFee  = CalculateAdministrationFee(loanRequest);

            double apr = 0;

            if (loanRequest.LoanAmount != 0 || loanRequest.LoanDuration != 0)
            {
                apr = 100 * ((administrationFee + interestAccrued) / loanRequest.LoanAmount) / loanRequest.LoanDuration;
            }

            return(apr);
        }
Esempio n. 3
0
        public void CalculateAPR_CalculatesCorrectValue()
        {
            var service     = GetService();
            var loanRequest = new LoanRequestDetailsDto()
            {
                LoanAmount           = 2000,
                LoanDuration         = 2,
                AdministrationAmount = 200,
                AdministrationFixed  = 100,
                InterestRate         = 5
            };
            var result = service.CalculateAPR(loanRequest);

            Assert.AreEqual(10, Math.Round(result, 2));
        }
Esempio n. 4
0
        public void CalculateMonthlyPayment_CalculatesCorrectValue()
        {
            var service     = GetService();
            var loanRequest = new LoanRequestDetailsDto()
            {
                LoanAmount           = 500000,
                LoanDuration         = 10,
                AdministrationAmount = 10000,
                AdministrationFixed  = 1,
                InterestRate         = 5
            };
            var result = service.CalculateMonthlyPayment(loanRequest);

            Assert.AreEqual(5303.28, Math.Round(result, 2));
        }
Esempio n. 5
0
        public double CalculateMonthlyPayment(LoanRequestDetailsDto loanRequest)
        {
            var months = loanRequest.LoanDuration * 12;
            var rate   = (loanRequest.InterestRate / 100) / 12;

            var discountFactor = months;

            if (rate != 0)
            {
                var discountFactorNumerator   = Math.Pow(1 + rate, months) - 1;
                var discountFactorDenominator = rate * Math.Pow(1 + rate, months);

                discountFactor = discountFactorNumerator / discountFactorDenominator;
            }

            return(discountFactor == 0
                ? 0
                : loanRequest.LoanAmount / discountFactor);
        }
Esempio n. 6
0
 public double CalculateAdministrationFee(LoanRequestDetailsDto loanRequest)
 {
     return(Math.Min(
                loanRequest.LoanAmount * loanRequest.AdministrationFixed / 100,
                loanRequest.AdministrationAmount));
 }