public Loan SimulateTranche(Loan loan, ITrancheConfiguration trancheConfiguration) { var copyOfLoan = loan.Copy(); var scheduleConfiguration = _configurationFactory .Init() .WithLoan(copyOfLoan) .Finish() .GetConfiguration(); var schedule = Mapper.Map<IEnumerable<Installment>, IEnumerable<IInstallment>>(copyOfLoan.InstallmentList); var scheduleBuilder = new ScheduleBuilder(); var trancheBuilder = new TrancheBuilder(); var trancheAssembler = new TrancheAssembler(); var copyOfTrancheConfiguration = (ITrancheConfiguration) trancheConfiguration.Clone(); copyOfTrancheConfiguration.InterestRate *= (decimal) scheduleConfiguration.PeriodPolicy.GetNumberOfPeriodsInYear( copyOfTrancheConfiguration.StartDate, scheduleConfiguration.YearPolicy); schedule = trancheAssembler.AssembleTranche( schedule, scheduleConfiguration, copyOfTrancheConfiguration, scheduleBuilder, trancheBuilder); var newSchedule = Mapper.Map<IEnumerable<IInstallment>, List<Installment>>(schedule); foreach (var installment in newSchedule) { var oldInstallment = copyOfLoan.InstallmentList.Find(i => i.Number == installment.Number); if (oldInstallment == null) break; installment.Comment = oldInstallment.Comment; installment.PaidFees = oldInstallment.PaidFees; installment.PaidCommissions = oldInstallment.PaidCommissions; installment.FeesUnpaid = oldInstallment.FeesUnpaid; installment.CommissionsUnpaid = oldInstallment.CommissionsUnpaid; installment.IsPending = oldInstallment.IsPending; //installment.PaidDate = oldInstallment.PaidDate; } copyOfLoan.InstallmentList = newSchedule; copyOfLoan.NbOfInstallments = newSchedule.Count(); copyOfLoan.Amount += trancheConfiguration.Amount; return copyOfLoan; }
public Loan SimulateTranche(Loan loan, ITrancheConfiguration trancheConfiguration) { var copyOfLoan = loan.Copy(); var scheduleConfiguration = _configurationFactory .Init() .WithLoan(copyOfLoan) .Finish() .GetConfiguration(); var schedule = copyOfLoan.InstallmentList; var scheduleBuilder = new ScheduleBuilder(); var trancheBuilder = new TrancheBuilder(); var trancheAssembler = new TrancheAssembler(); var copyOfTrancheConfiguration = (ITrancheConfiguration)trancheConfiguration.Clone(); var newSchedule = new List<Installment>(); if (loan.Product.ScriptName == null) newSchedule = trancheAssembler.AssembleTranche( schedule, scheduleConfiguration, copyOfTrancheConfiguration, scheduleBuilder, trancheBuilder).ToList(); else newSchedule = AssembleTranche(copyOfLoan, scheduleConfiguration, trancheConfiguration); foreach (var installment in newSchedule) { var oldInstallment = copyOfLoan.InstallmentList.Find(i => i.Number == installment.Number); if (oldInstallment == null) break; installment.Comment = oldInstallment.Comment; installment.PaidFees = oldInstallment.PaidFees; installment.PaidCommissions = oldInstallment.PaidCommissions; installment.FeesUnpaid = oldInstallment.FeesUnpaid; installment.CommissionsUnpaid = oldInstallment.CommissionsUnpaid; installment.IsPending = oldInstallment.IsPending; //installment.PaidDate = oldInstallment.PaidDate; } copyOfLoan.InstallmentList = newSchedule; copyOfLoan.NbOfInstallments = newSchedule.Count(); copyOfLoan.Amount += trancheConfiguration.Amount; return copyOfLoan; }