示例#1
0
 public Loan(LoanSpecification specification, decimal installment, decimal administrationFee, LoanIndicators indicators)
 {
     Specification     = specification;
     Installment       = installment;
     AdministrationFee = administrationFee;
     Indicators        = indicators;
 }
示例#2
0
        private decimal CalculateEffectiveApr(LoanSpecification specification, decimal apr)
        {
            var periodicApr  = 1 + apr / (specification.NumberOfCompoundPeriodsSimplify * 100);
            var effectiveApr = (decimal)Math.Pow((double)periodicApr, specification.NumberOfCompoundPeriodsSimplify) - 1;

            return(effectiveApr * 100);
        }
        private decimal CalculateAdministrationFee(LoanSpecification loanSpecification)
        {
            var percentageAmount = loanSpecification.OriginalPrincipal / 100 * _bankInterestProvider.AdministrationFeePercentage;

            return(percentageAmount < _bankInterestProvider.AdministrationFeeMaximumAmount
                ? percentageAmount
                : _bankInterestProvider.AdministrationFeeMaximumAmount);
        }
        public Loan CreateLoan(LoanSpecification loanSpecification)
        {
            var administrationFee = CalculateAdministrationFee(loanSpecification);
            var installment       = _installmentCalculator.CalculateInstallment(loanSpecification);
            var indicators        = _loanIndicatorsGenerator.GenerateLoanIndicators(loanSpecification, administrationFee);

            return(new Loan(loanSpecification, installment, administrationFee, indicators));
        }
示例#5
0
        private decimal CalculateEffectiveAnnualRate(LoanSpecification loanSpecification)
        {
            var interestRate        = loanSpecification.AnnualInterestRate / 100;
            var periodicRate        = (double)interestRate / loanSpecification.NumberOfCompoundPeriodsSimplify;
            var effectiveAnnualRate = (decimal)(Math.Pow(1 + periodicRate, loanSpecification.NumberOfCompoundPeriodsSimplify) - 1) * 100;

            return(effectiveAnnualRate);
        }
示例#6
0
        public decimal CalculateInstallment(LoanSpecification loanSpecification)
        {
            var interestRate = loanSpecification.AnnualInterestRate / 100;
            var periodicRate = (double)interestRate / loanSpecification.NumberOfCompoundPeriodsSimplify;
            var qPowN        = Math.Pow(1 + periodicRate, loanSpecification.DurationInMonths);
            var installment  = (decimal)((double)loanSpecification.OriginalPrincipal * qPowN * (periodicRate / (qPowN - 1)));

            return(installment);
        }
示例#7
0
        public LoanIndicators GenerateLoanIndicators(LoanSpecification loanSpecification, decimal administrationFee)
        {
            var ear  = CalculateEffectiveAnnualRate(loanSpecification);
            var apr  = CalculateApr(loanSpecification, administrationFee);
            var eapr = CalculateEffectiveApr(loanSpecification, apr);

            //effective continuous compound interest
            //var continuousEffectiveAnnualRate = Math.Pow(Math.E,
            //    ((double) (annualInterestRate / 100) * months / 12));

            return(new LoanIndicators
            {
                EffectiveAnnualRate = ear,
                AnnualPercentageRate = apr,
                EffectiveAnnualPercentageRate = eapr
            });
        }
示例#8
0
        private decimal CalculateApr(LoanSpecification loanSpecification, decimal administrationFee)
        {
            var approximation       = loanSpecification.AnnualInterestRate;
            var difference          = 1m;
            var amountToAdd         = 0.0001m;
            var originalInstallment = _installmentCalculator.CalculateInstallment(loanSpecification);
            var borrowedAmount      = loanSpecification.OriginalPrincipal - administrationFee;

            while (difference != 0)
            {
                var newOrigin = _installmentCalculator.CalculateInstallment(new LoanSpecification
                {
                    OriginalPrincipal  = borrowedAmount,
                    DurationInMonths   = loanSpecification.DurationInMonths,
                    CompoundFrequency  = loanSpecification.CompoundFrequency,
                    AnnualInterestRate = approximation
                });

                difference = originalInstallment - newOrigin;

                if (difference is <= ErrorMargin and >= -ErrorMargin)
                {
                    break;
                }

                if (difference > 0)
                {
                    amountToAdd   *= 2;
                    approximation += amountToAdd;
                }

                else
                {
                    amountToAdd   /= 2;
                    approximation -= amountToAdd;
                }
            }

            return(approximation);
        }
        public LoanProposalDto ProposeLoan(ProposeLoanDto dto)
        {
            if (dto.Principal <= 0 || dto.Principal > _loanInputRequirements.CustomerMaximumPrincipal)
            {
                throw new LoanException("principal amount is incorrect");
            }

            if (dto.Months <= 0 || dto.Months > _loanInputRequirements.MaximumLoanPeriodInMonths)
            {
                throw new LoanException("loan period is incorrect");
            }

            var loanSpecification = new LoanSpecification
            {
                OriginalPrincipal  = dto.Principal,
                DurationInMonths   = dto.Months,
                CompoundFrequency  = CompoundFrequency.Monthly,
                AnnualInterestRate = _bankInterestProvider.AnnualInterestRate
            };

            var loan = _loanFactory.CreateLoan(loanSpecification);

            return(_loanMapper.Map(loan));
        }