Example #1
0
        private IEnumerable<Installment> BuildTranche(IEnumerable<Installment> schedule,Loan loan, IScheduleConfiguration scheduleConfiguration, ITrancheConfiguration trancheConfiguration)
        {
            var copyOfLoan = loan.Copy();
            loan.Amount = trancheConfiguration.Amount;
            loan.NbOfInstallments = trancheConfiguration.NumberOfInstallments;
            loan.GracePeriod = trancheConfiguration.GracePeriod;
            loan.InterestRate = trancheConfiguration.InterestRate/100;
            loan.StartDate = trancheConfiguration.StartDate;
            loan.FirstInstallmentDate = trancheConfiguration.PreferredFirstInstallmentDate;

            var rhs = SimulateScheduleCreation(loan);

            loan.Amount = schedule.Sum(i => i.CapitalRepayment.Value - i.PaidCapital.Value);
            if (!trancheConfiguration.ApplyNewInterestRateToOlb)
            {
                loan.InterestRate = copyOfLoan.InterestRate;
            }

            var lhs = SimulateScheduleCreation(loan);

            var result = new List<Installment>();

            // Merge the two schedules
            var max = Math.Max(lhs.Count, rhs.Count);
            for (var i = 0; i < max; i++)
            {
                var lhi = i >= lhs.Count ? null : lhs[i];
                var rhi = i >= rhs.Count ? null : rhs[i];

                Installment installment;

                if (lhi == null)
                {
                    installment = rhi;
                }
                else if (rhi == null)
                {
                    installment = lhi;
                }
                else
                {
                    installment = new Installment
                    {
                        Number = lhi.Number,
                        StartDate = lhi.StartDate,
                        ExpectedDate = lhi.ExpectedDate,
                        //RepaymentDate = lhi.RepaymentDate,
                        CapitalRepayment = lhi.CapitalRepayment + rhi.CapitalRepayment,
                        InterestsRepayment = lhi.InterestsRepayment + rhi.InterestsRepayment,
                        OLB = lhi.OLB + rhi.OLB,
                    };
                }
                result.Add(installment);
            }

            result[0].InterestsRepayment += GetExtraInterest(schedule, scheduleConfiguration, trancheConfiguration);
            return result;
        }
Example #2
0
        public List<Installment> SimulateScriptSchedule(Loan loan)
        {
            string dir = TechnicalSettings.ScriptPath;
            if (string.IsNullOrEmpty(dir)) dir = AppDomain.CurrentDomain.BaseDirectory;
            dir = Path.Combine(dir, "Scripts\\Schedule\\");
            var file = Path.Combine(dir, loan.ScriptName);
            if (!File.Exists(file))
                throw new Exception("Couldn't load the file " + loan.ScriptName);
            var script = RunScript(file);
            var configuration = new Dictionary<string, object>();
            var nonWorkingDate = NonWorkingDateSingleton.GetInstance(string.Empty);
            configuration.Add("Holidays", nonWorkingDate);

            var loanData = new Dictionary<string, object>();
            loanData["Amount"] = loan.Amount.Value;
            loanData["InterestRate"] = loan.InterestRate;
            loanData["NumberOfInstallments"] = loan.NbOfInstallments;
            loanData["GracePeriod"] = loan.GracePeriod;
            loanData["ChargeInterestDuringGracePeriod"] = loan.Product.ChargeInterestWithinGracePeriod;
            loanData["DisbursementDate"] = loan.StartDate;
            loanData["FirstInstallmentDate"] = loan.FirstInstallmentDate;

            var items = (List<Dictionary<string, object>>) script.Main(loanData, configuration);
            var installments = new List<Installment>();

            foreach (var item in items)
            {
                var installment = new Installment();
                installment.Number = (int) item["Number"];
                installment.CapitalRepayment = (decimal) item["Principal"];
                installment.OLB = (decimal) item["OLB"];
                installment.InterestsRepayment = (decimal) item["Interest"];
                installment.StartDate = (DateTime) item["StartDate"];
                installment.ExpectedDate = (DateTime) item["ExpectedDate"];
                installments.Add(installment);
            }

            return installments;
        }